Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly option not working under workspaceConfiguration #83

Closed
sujeithnath opened this issue Jan 23, 2023 · 3 comments
Closed

ReadOnly option not working under workspaceConfiguration #83

sujeithnath opened this issue Jan 23, 2023 · 3 comments

Comments

@sujeithnath
Copy link

Hi there,

As the title mentions, when I add readOnly: true, it give me below error

Uncaught Error: Existing toolbox is null. Can't create new toolbox. at WorkspaceSvg$$module$build$src$core$workspace_svg.updateToolbox (workspace_svg.ts:1869:13) at useBlocklyWorkspace.js:43:23

const {workspace} = useBlocklyWorkspace({ ref: blocklyRef, initialXml: programXml, toolboxConfiguration: { "kind": "flyoutToolbox", "contents": [ { "kind": "block", "type": "controls_if" }, { "kind": "block", "type": "controls_whileUntil" } ] }, workspaceConfiguration: { renderer: 'crc_renderer', readOnly: true, scrollbars: true, trashcan: false, grid: { spacing: 20, length: 3, colour: '#ccc', snap: true, }, media: '/blockly/media/', }, onDispose: (ws) => logger.info('on ws dispose', ws), // @ts-ignore onInject: (ws) => logger.info('injected ws', ws?.undoStack_), onWorkspaceChange: (ws) => logger.info('on ws change', ws), onImportXmlError: (error) => logger.warn('error importing XML', error) })

@nbudin
Copy link
Owner

nbudin commented Jan 23, 2023

Hi @sujeithnath! I'm not totally sure what's happening with readOnly, but one thing I'd recommend trying is to move the toolboxConfiguration value into a const outside your React component. This will prevent useBlocklyWorkspace from trying to update the workspace on every render cycle. Could you try that out and let me know if it solves your issue?

@arontsang
Copy link
Contributor

@nbudin The syncing code is trying to update the UI element workspace with the React prop workspace.

However, there is no UI element workspace, because readonly is set to true.

I've put in a PR for this issue.

@nbudin
Copy link
Owner

nbudin commented Jul 26, 2023

Thanks @arontsang! This PR is merged and I've released v7.3.0 with the fix.

@nbudin nbudin closed this as completed Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants