blocks are injected twice

85 views
Skip to first unread message

ArM

unread,
Feb 28, 2023, 2:18:34 PM2/28/23
to Blockly
During react renders the blocks' xml ends up injecting twice.

````
    const { loaded, project, updateProject } = useProject(); //here is stored the workspace (into data.blocks property)
    const blocklyRef = useRef(null);

    const { xml, workspace } = useBlocklyWorkspace({
        ref: blocklyRef,
        toolboxConfiguration: toolbox,
        initialXml: '',
        workspaceConfiguration: { zoom: { controls: true, wheel: true, startScale: 1, maxScale: 3, minScale: 0.3, scaleSpeed: 1.2 }, theme },
        onWorkspaceChange: (workspace) => {
            if (loaded) {
                console.log(xml);
            }
        }
    });

    useEffect(() => {
        if (loaded) {
            Blockly.serialization.workspaces.load(JSON.parse(project.data.blocks), Blockly.getMainWorkspace());
        }
    }, [loaded]);

    return (
        <div id="blockly" ref={blocklyRef}></div>
    );
````
As you can see from the following image, the xml ends up doubling each blockScreenshot from 2023-02-28 21-11-18.png

Nat Budin

unread,
Feb 28, 2023, 2:19:58 PM2/28/23
to blo...@googlegroups.com
Hi there, I see that you already posted this as a Github issue on https://github.com/nbudin/react-blockly/issues/89.  I’m going to take the discussion over there to avoid having it in two places at once.

Nat

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/b9261f02-b3ac-448e-be2b-5aa9327e0b7en%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages