josdejong/jsoneditor

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

Open

#1,498 创建于 2023年2月16日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)JavaScript (2,034 fork)batch import
bughelp wanted

仓库指标

Star
 (10,781 star)
PR 合并指标
 (平均合并 15小时 36分钟) (30 天内合并 3 个 PR)

描述

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.

贡献者指南