[lexical][Breaking Change] Bug Fix: Change $copyNode to use afterCloneFrom #7609
+126
−9
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.
Breaking Changes
If you have code that assumes that
newNode.afterCloneFrom(prevNode)
will not be called as a result of$copyNode(prevNode)
, and would no longer work if it was, then it will need some refactoring. This is a very unlikely scenario.Description
$copyNode
is used when creating a shallow copy (not including children) of a node with a new key. It currently only really works as expected if the node doesn't use NodeState and has a clone method that directly sets all expected properties.Discovered this issue while working through a #7258 refactor of ListNode. After replacing the clone boilerplate with afterCloneFrom the list type and tag would no longer be copied.
Test plan
New unit tests
Before
$copyNode
would not copy all properties of a nodeAfter
$copyNode
will copy all properties of a node, including NodeState (but without creating an aliasing issue), but not including the LexicalNode and ElementNode NodeKey pointers and size cache (__prev
,__next
,__parent
,__first
,__last
,__size
)