Skip to content

Commit 399cae5

Browse files
authored
Merge pull request #91 from randrei12/main
fix blocks are injected twice
2 parents a5b43a1 + a1fb5bb commit 399cae5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/useBlocklyWorkspace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function importFromXml(
1111
onImportXmlError?: (error: any) => void
1212
) {
1313
try {
14+
if (workspace.getAllBlocks(false).length > 0) return; // we won't load blocks again if they are already loaded
1415
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);
1516
return true;
1617
} catch (e) {
@@ -62,7 +63,7 @@ const useBlocklyWorkspace = ({
6263
}, [onDispose]);
6364

6465
const handleWorkspaceChanged = React.useCallback(
65-
(newWorkspace) => {
66+
(newWorkspace: WorkspaceSvg) => {
6667
if (onWorkspaceChange) {
6768
onWorkspaceChange(newWorkspace);
6869
}

0 commit comments

Comments
 (0)