Repository navigation
[lexical-playground] Bug Fix: keep the Excalidraw drawing and its size across a node clone - #8984
Merged
Merged
Conversation
…e across a node clone
## Description
`ExcalidrawNode` declares `__data`, `__width` and `__height`, and its
constructor gives every argument a default. That means `$config()` synthesizes
the static `clone` as `new ExcalidrawNode()` and relies on `afterCloneFrom` to
carry the node's own properties over — but `ExcalidrawNode` never implemented
`afterCloneFrom`, so the base implementation runs and the three properties are
silently reset to their constructor defaults on every clone.
Every mutation goes through `getWritable()`, which clones, so the writes that
the Excalidraw UI performs destroy each other:
- resizing (`setWidth`/`setHeight`, dispatched by `ImageResizer`) wipes the
drawing back to `'[]'` — the picture disappears;
- saving the drawing (`setData`, dispatched when the modal is closed) resets the
width and height back to `'inherit'`;
- any unrelated write to the node (moving it, `insertAfter`, …) clears all three.
Implement `afterCloneFrom` to copy `__data`, `__width` and `__height`, matching
what every other node in the repo with extra properties does (e.g.
`TableRowNode`, which has the same all-defaults constructor).
## Test plan
New unit test `packages/lexical-playground/__tests__/unit/ExcalidrawNode.test.ts`
covering the three cases above.
### Before
```
$ npx vitest run packages/lexical-playground/__tests__/unit/ExcalidrawNode.test.ts
FAIL |unit| .../ExcalidrawNode.test.ts > ExcalidrawNode > keeps the drawing data when the node is resized
FAIL |unit| .../ExcalidrawNode.test.ts > ExcalidrawNode > keeps the dimensions when the drawing data is saved
FAIL |unit| .../ExcalidrawNode.test.ts > ExcalidrawNode > keeps the drawing data when the node is moved
AssertionError: expected { type: 'excalidraw', ... } to match object { data: '[{"type":"rectangle","id":"a"}]', height: 400, width: 300 }
- Expected
+ Received
{
- "data": "[{\"type\":\"rectangle\",\"id\":\"a\"}]",
- "height": 400,
- "width": 300,
+ "data": "[]",
+ "height": undefined,
+ "width": undefined,
}
Test Files 1 failed (1)
Tests 3 failed (3)
```
### After
```
$ npx vitest run packages/lexical-playground/__tests__/unit/ExcalidrawNode.test.ts
✓ |unit| packages/lexical-playground/__tests__/unit/ExcalidrawNode.test.ts (3 tests) 13ms
Test Files 1 passed (1)
Tests 3 passed (3)
$ npx vitest run packages/lexical-playground
Test Files 18 passed (18)
Tests 274 passed (274)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 00:58
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
etrepum
approved these changes
Aug 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
ExcalidrawNodedeclares__data,__widthand__height, and itsconstructor gives every argument a default. That means
$config()synthesizesthe static
cloneasnew ExcalidrawNode()and relies onafterCloneFromtocarry the node's own properties over — but
ExcalidrawNodenever implementedafterCloneFrom, so the base implementation runs and the three properties aresilently reset to their constructor defaults on every clone.
Every mutation goes through
getWritable(), which clones, so the writes thatthe Excalidraw UI performs destroy each other:
setWidth/setHeight, dispatched byImageResizer) wipes thedrawing back to
'[]'— the picture disappears;setData, dispatched when the modal is closed) resets thewidth and height back to
'inherit';insertAfter, …) clears all three.Implement
afterCloneFromto copy__data,__widthand__height, matchingwhat every other node in the repo with extra properties does (e.g.
TableRowNode, which has the same all-defaults constructor).Test plan
New unit test
packages/lexical-playground/__tests__/unit/ExcalidrawNode.test.tscovering the three cases above.
Before
After