fix(react): destroy editor instances after two ticks #2121
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
React's StrictMode makes it so that refs (which we use as the main trigger for mounting/unmounting the editor),
are triggered twice. This makes it difficult to know when the editor is actually meant to be unmounted.
If an editor is unmounted during a render of React NodeViews, this can cause errors to occur (since elements which were in the dom at the start of the render are no longer in the dom by the time that the render occurs).
Rationale
This change takes a similar approach to the editor integration in Tiptap, where it delays
unmounting the editor until 2 ticks have passed.This is to allow React the opportunity to re-call
mountwith the same element, or if the ticks pass, to actually unmount the editor instance.In most cases, delaying the removal of the editor instance should be fine, because it is not expected to be available after it has been destroyed.
Changes
Impact
Testing
Screenshots/Video
Checklist
Additional Notes
Fixes #2106