Skip to content

[lexical-playground] Bug Fix: keep the Excalidraw drawing and its size across a node clone - #8984

Merged
etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/excalidraw-afterclonefrom
Aug 9, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/excalidraw-afterclonefrom

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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)

…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)
```
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 9, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 9, 2026
Merged via the queue into meta:main with commit 610cfd9 Aug 9, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants