-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Breaking Change][lexical] Bug Fix: Commit updates on editor.setRootElement(null) #7023
[Breaking Change][lexical] Bug Fix: Commit updates on editor.setRootElement(null) #7023
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
/cc @potatowagon |
size-limit report 📦
|
thanks for clarifying the effects of the change |
would this be considered a minor breaking change? given it should work for most cases. edge case would be an implementation that depends on the number of times an update listener is called |
Yes, a very minor breaking change. If it breaks anything, the code was either counting calls or doing something that's probably wrong. |
Description
setRootElement(null)
now triggers the same sort of reconciliation with ahistory-merge
tag thatsetRootElement(element)
triggered.Previously, when
setRootElement(null)
was called with any pending updates, it would put the editor in a situation whereeditor.getEditorState()
would return a writable EditorState. Now the invariant is preserved such thateditor.getEditorState()
always returns a fully reconciled and read-only EditorState, but to match previous semantics such that the current editorState would synchronously get set from the pendingEditorState,setRootElement
now always causes a commit when the root element changes instead of just when it changes to a non-null element.I think there were likely other subtle bugs due to the previous behavior, since setting _editorState directly from _pendingEditorState also won't run transforms, but it would only be possible to notice if you were inspecting this state while still "headless" since a full reconcile would be performed once a new root element is attached.
Closes #7022
Upgrade Information
This change means that a reconciliation will happen on
setRootElement(null)
. Previously, this call would set the pending editor state to the current editor state which means that update listeners, transforms, etc. would not run in this particular scenario. Now they do.This should not have any effect on normal code, but it is a breaking change because it can trigger test failures if you are counting the number of times that an update listener is called, or doing something similar to that.
Test plan
Before
If
setRootElement(null)
was called with any pending updates, it would put the editor in a situation whereeditor.getEditorState()
would return a writable EditorState. Now the invariant is preserved such thateditor.getEditorState()
always returns a fully reconciled and read-only EditorState, but to match previous semantics setRootElement now always causes a commit when the root element changes.The problems due to this invariant being violated surfaced after #6894 was released
After
Unit test coverage for this readOnly scenario.