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

Prevent running editor effects with a destroyed view during strict mode and suspense #24

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

smoores-dev
Copy link
Contributor

Fixes nytimes/react-prosemirror#101, #8

During Suspense, it's possible for the layout effect cleanup function that calls view.destroy() to be run immediately before the layout group effect that executes useEditorEffect callbacks. This results in calling those callbacks with a destroyed editor (one without a docView), which crashes the editor. This can be simulated in Strict Mode with the sample code from #8.

To fix this, we avoid calling useEditorEffect callbacks if the view that we have access to is destroyed. The next render will produce a new, undestroyed EditorView and trigger another callback call, so this doesn't result in any missed calls!

@smoores-dev smoores-dev merged commit 9496b17 into main Feb 11, 2025
2 checks passed
@smoores-dev smoores-dev deleted the prevent-effect-with-destroyed-view branch February 11, 2025 22:27
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.

Secondary Suspense causing view to be prematurely destroyed
1 participant