Skip to content

Prevent operations on destroyed views#200

Open
ocavue wants to merge 1 commit intoyjs:masterfrom
ocavue:ocavue/view_dispatch
Open

Prevent operations on destroyed views#200
ocavue wants to merge 1 commit intoyjs:masterfrom
ocavue:ocavue/view_dispatch

Conversation

@ocavue
Copy link
Contributor

@ocavue ocavue commented Nov 10, 2025

I encountered the following error during my unit tests:

Uncaught TypeError: Cannot read properties of null (reading 'matchesNode')
    at EditorView.updateStateInner (chunk-VVQZWLTC.js?v=83ef0d59:4795:45)
    at EditorView.updateState (chunk-VVQZWLTC.js?v=83ef0d59:4770:10)
    at EditorView.dispatch (chunk-VVQZWLTC.js?v=83ef0d59:5115:10)
    at y-prosemirror.js?v=ab00c66d:1219:12
    at Map.forEach (<anonymous>)
    at updateMetas (y-prosemirror.js?v=ab00c66d:1212:7)

This error appears in view.dispatch(tr) at lib.js#L33, which is wrapped in a eventloop.timeout / setTimeout.

While I haven't specifically tried to reproduce this error during typical user operations, it may not pose a problem for actual users since it seems to be a timing issue, and automated tests generally run faster than human interactions. Nevertheless, I believe it's a good idea to check view.isDestroyed in asynchronous (i.e., setTimeout) operations to prevent such issues.

In this PR, I added a view.isDestroyed check before view.dispatch(tr) in this place.

Sidenote: In sync-plugin.js, there are also some this.prosemirrorView.dispatch() calls. It could be a good idea to check view.isDestroyed before calling .dispatch(), but I'm not certain if it's necessary. @dmonad Do you think I should add view.isDestroyed check for them too?

@ocavue ocavue marked this pull request as ready for review November 10, 2025 00:45
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

Successfully merging this pull request may close these issues.

1 participant