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

Error: Method expand is not available in mode "tree" #45

Closed
jason51553262 opened this issue Jan 19, 2022 · 2 comments
Closed

Error: Method expand is not available in mode "tree" #45

jason51553262 opened this issue Jan 19, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@jason51553262
Copy link

When calling expand() from onChangeMode callback and where mode === 'tree' I get the following error:

Error: Method expand is not available in mode "tree"
    at lE.eval (https://i4vo7.csb.app/node_modules/svelte-jsoneditor/dist/jsoneditor.js:33:182026)
    at expand (https://i4vo7.csb.app/src/JSONEditor.tsx:36:22)
    at handleOnChangeMode (https://i4vo7.csb.app/src/JSONEditor.tsx:58:7)
    at HTMLButtonElement.G (https://i4vo7.csb.app/node_modules/svelte-jsoneditor/dist/jsoneditor.js:33:179849)
    at HTMLButtonElement.eval (https://i4vo7.csb.app/node_modules/svelte-jsoneditor/dist/jsoneditor.js:29:23080)

The expand method works ok when first mounting the component, but not when switching between modes.

See the issue in the following sandbox:
https://codesandbox.io/s/blue-cloud-i4vo7

On first load the nodes are expanded, but when clicking to code and back to tree, that's when the expand method fails.

Am I calling it correctly?

@josdejong josdejong added the bug Something isn't working label Jan 20, 2022
@josdejong
Copy link
Owner

josdejong commented Jan 20, 2022

Thanks for reporting. I did some debugging, and it turns out the onChangeMode callback is called whilst the editor still has to rerender. A workaround is to replace expand() with setTimeout(expand) in your codesandbox.

@josdejong
Copy link
Owner

Fixed now in v0.3.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants