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

"Cannot read properties of null (reading 'getInternalPath')" #1498

Open
joshkel opened this issue Feb 16, 2023 · 1 comment
Open

"Cannot read properties of null (reading 'getInternalPath')" #1498

joshkel opened this issue Feb 16, 2023 · 1 comment
Labels

Comments

@joshkel
Copy link
Contributor

joshkel commented Feb 16, 2023

I'm sporadically getting the following error when I change object keys (not values):

TypeError: Cannot read properties of null (reading 'getInternalPath')
S.value
https://76uwry.csb.app/node_modules/jsoneditor/dist/jsoneditor.min.js:33:36942
eval
https://76uwry.csb.app/node_modules/jsoneditor/dist/jsoneditor.min.js:35:2194

See https://codesandbox.io/s/jsoneditor-debounced-error-76uwry for an example: Try changing hello. (This calls setValue extremely fast to demonstrate the problem.)

I believe that the problem is caused by a race condition: Edits are propagated with a 150ms delay (due to the use of debounce), so, if the editor receives a new value, the old value has been removed and no longer has the fields that the event handler expects it to have.

https://github.com/josdejong/jsoneditor/blob/v9.9.2/src/js/Node.js#L1649

I'm not sure if the correct fix is to cancel debounced events when a node is removed (e.g., Lodash's debounce has a cancel function; a similar idea could be added here) or make the events check for, e.g., this.parent == null.

@josdejong
Copy link
Owner

Thanks for reporting! I don't get the error you report, but when I change the interval in your example from 1000 to 10 I can get a similar error 'Uncaught TypeError: this.parent is null'.

I think you're right and this is because of the debounce. So basically, there are two competing changes: the external change, and the change being made by the user, and we could decide to let either of the two changes "win". I think we should go for the simplest solution, which probably is to make it effectively do nothing by checking if this.parent still exists (cancelling the debounce would be fine with me too, but the used debounce function currently does not have a cancel method).

@josdejong josdejong added the bug label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants