Browse Source

fix: quick add input got removed sometimes with syncing service

Peng Xiao 3 years ago
parent
commit
ebfcba284e
2 changed files with 18 additions and 2 deletions
  1. 14 1
      tldraw/demo/src/App.jsx
  2. 4 1
      tldraw/packages/core/src/lib/TLHistory.ts

+ 14 - 1
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 (
     <div className={`h-screen w-screen`}>
       <ThemeSwitcher theme={theme} setTheme={setTheme} />
@@ -157,7 +170,7 @@ export default function App() {
           saveAsset: fileToBase64,
           makeAssetUrl: a => a,
         }}
-        model={documentModel}
+        model={model}
         onPersist={onPersist}
       />
     </div>

+ 4 - 1
tldraw/packages/core/src/lib/TLHistory.ts

@@ -122,7 +122,10 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
             }
           }
           // Any shapes remaining in the shapes map need to be removed
-          if (shapesMap.size > 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