From ebfcba284e626e8f254036fe71f187dae65c0f0f Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Tue, 23 Aug 2022 11:26:41 +0800 Subject: [PATCH] fix: quick add input got removed sometimes with syncing service --- tldraw/demo/src/App.jsx | 15 ++++++++++++++- tldraw/packages/core/src/lib/TLHistory.ts | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tldraw/demo/src/App.jsx b/tldraw/demo/src/App.jsx index 157602f2a..241efd352 100644 --- a/tldraw/demo/src/App.jsx +++ b/tldraw/demo/src/App.jsx @@ -139,6 +139,19 @@ const searchHandler = q => { export default function App() { const [theme, setTheme] = React.useState('light') + const [model, setModel] = React.useState(documentModel) + + // Mimic external reload event + React.useEffect(() => { + const interval = setInterval(() => { + setModel(onLoad()) + }, 5000) + + return () => { + clearInterval(interval) + } + }, []) + return (
@@ -157,7 +170,7 @@ export default function App() { saveAsset: fileToBase64, makeAssetUrl: a => a, }} - model={documentModel} + model={model} onPersist={onPersist} />
diff --git a/tldraw/packages/core/src/lib/TLHistory.ts b/tldraw/packages/core/src/lib/TLHistory.ts index bc5980579..2f93ac686 100644 --- a/tldraw/packages/core/src/lib/TLHistory.ts +++ b/tldraw/packages/core/src/lib/TLHistory.ts @@ -122,7 +122,10 @@ export class TLHistory 0) page.removeShapes(...shapesMap.values()) + // Do not remove shapes when state is in the middle of a creation + if (shapesMap.size > 0 && !this.app.selectedTool.isIn('creating')) { + page.removeShapes(...shapesMap.values()) + } // Add any new shapes if (shapesToAdd.length > 0) page.addShapes(...shapesToAdd) // Remove the page from the map