josdejong/jsoneditor

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

Open

#1498 opened on Feb 16, 2023

View on GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (10,781 stars) (2,034 forks)batch import
bughelp wanted

Description

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.

Contributor guide