Skip to content

Commit abe8007

Browse files
committed
Fixed blockly sometimes does not recognize changes to the workspace
1 parent 0df8aa8 commit abe8007

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/components/blockly.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ function BlocklyEditor({ tabId, tabName }: BlocklyEditorProps) {
153153
const [isListenerSet, setIsListenerSet] = useState(false);
154154
const [name, setName] = useState<string>(tabName);
155155
const nameRef = useRef(name);
156+
const isLoadingRef = useRef(isLoading);
157+
158+
useEffect(() => {
159+
isLoadingRef.current = isLoading;
160+
}, [isLoading]);
156161

157162
/**
158163
* handleOnInject
@@ -330,10 +335,10 @@ function BlocklyEditor({ tabId, tabName }: BlocklyEditorProps) {
330335
setIsLoading(false);
331336
return;
332337
}
333-
if (isLoading &&
334-
event.type === Blockly.Events.BLOCK_CREATE ||
338+
if (isLoadingRef.current &&
339+
(event.type === Blockly.Events.BLOCK_CREATE ||
335340
event.type === Blockly.Events.BLOCK_DELETE ||
336-
event.type === Blockly.Events.BLOCK_CHANGE
341+
event.type === Blockly.Events.BLOCK_CHANGE)
337342
) { return; }
338343
if (event.type === Blockly.Events.VIEWPORT_CHANGE || event.isUiEvent) { return; }
339344
try {
@@ -368,7 +373,7 @@ function BlocklyEditor({ tabId, tabName }: BlocklyEditorProps) {
368373
ws.removeChangeListener(listener);
369374
}
370375
}
371-
}, [isListenerSet, isLoading, saveEditor, tabId]);
376+
}, [isListenerSet, saveEditor, tabId]);
372377

373378
return (
374379
<BlocklyWorkspace

0 commit comments

Comments
 (0)