Skip to content

[Breaking Change][lexical-react] Refactor: LexicalNestedComposer add skipEditableListener prop and deprecate initialNodes prop and implicit namespace setting#7357

Merged
etrepum merged 6 commits intofacebook:mainfrom
etrepum:deprecate-initialNodes
Mar 24, 2025

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Mar 20, 2025

Breaking Changes

LexicalNestedComposer manipulates internal data structures of the LexicalEditor in ways that are unsafe and lead to incorrect behavior.

The initialNodes prop is deprecated and will be removed in v0.32.0. The functionality it had can be achieved by configuring the nodes array of the editor correctly when it is created.

Similarly, the forced inheritance of namespace is incorrect whenever the nodes configuration differs at all from the parent. It is always safer and more correct to explicitly specify a namespace.

Before

<LexicalNestedComposer initialEditor={caption} initialNodes={[/* … */]}>
  {/* … */}
</LexicalNestedComposer>
class ImageNode extends DecoratorNode<JSX.Element> {
  constructor(/* … */) {
      // …
      this.__caption = caption || createEditor();
  }
}

After

<LexicalNestedComposer initialEditor={caption}>
  {/* … */}
</LexicalNestedComposer>
class ImageNode extends DecoratorNode<JSX.Element> {
  constructor(/* … */) {
      // …
      this.__caption = caption || createEditor({
        namespace: 'Playground/ImageNodeCaption',
        nodes: [/* … */],
      });
  }
}

New APIs

There's a new skipEditableListener property of LexicalNestedComposerProps that allows you to manually control the editable state of the nested editor. Previously the editable state of the nested editors was always forced to follow the parent editor's editable state.

Description

initialNodes doesn't work correctly, never really has, and should be deprecated. This deprecates that feature, provides a warning in __DEV__ with planned removal for v0.32.0.

Additionally other misfeatures of LexicalNestedComposer have been cleaned up allowing for more explicit control over the nested editor's configuration (namespace, editable state).

Internally this was implemented by storing the arguments used to create the editor so that it can be determined whether a value was set explicitly or implicitly (e.g. the automatically created namespace). This will also be useful as an internal implementation detail for other features.

Test plan

Unit tests for skipEditableListener and the warnings (with a warnOnlyOnce mock that always warns)

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 20, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2025 10:52pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2025 10:52pm

@facebook-github-bot facebook-github-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 Mar 20, 2025
@etrepum etrepum changed the title [Breaking Change][lexical-react] Breaking Change: Deprecate LexicalNestedComposer initialNodes [Breaking Change][lexical-react] Refactor: Deprecate LexicalNestedComposer initialNodes Mar 20, 2025
@etrepum etrepum changed the title [Breaking Change][lexical-react] Refactor: Deprecate LexicalNestedComposer initialNodes [Breaking Change][lexical-react] Refactor: Deprecate LexicalNestedComposer initialNodes & add skipEditableListener prop Mar 20, 2025
@etrepum etrepum changed the title [Breaking Change][lexical-react] Refactor: Deprecate LexicalNestedComposer initialNodes & add skipEditableListener prop [Breaking Change][lexical-react] Refactor: LexicalNestedComposer add skipEditableListener prop and deprecate initialNodes prop and implicit namespace setting Mar 20, 2025
@etrepum etrepum added this pull request to the merge queue Mar 24, 2025
Merged via the queue into facebook:main with commit d6d9b3c Mar 24, 2025
39 checks passed
GermanJablo added a commit to payloadcms/payload that referenced this pull request Sep 3, 2025
Fixes #13386

Below I write a clarification to copy and paste into the release note,
based on our latest upgrade of Lexical [in
v3.29.0](https://github.com/payloadcms/payload/releases/tag/v3.29.0).

## Important
This release upgrades the lexical dependency from 0.28.0 to 0.34.0.

If you installed lexical manually, update it to 0.34.0. Installing
lexical manually is not recommended, as it may break between updates,
and our re-exported versions should be used. See the [yellow banner
box](https://payloadcms.com/docs/rich-text/custom-features) for details.

If you still encounter richtext-lexical errors, do the following, in
this order:

- Delete node_modules
- Delete your lockfile (e.g. pnpm-lock.json)
- Reinstall your dependencies (e.g. pnpm install)

### Lexical Breaking Changes

The following Lexical releases describe breaking changes. We recommend
reading them if you're using Lexical APIs directly
(`@payloadcms/richtext-lexical/lexical/*`).

- [v.0.33.0](https://github.com/facebook/lexical/releases/tag/v0.33.0)
- [v.0.30.0](https://github.com/facebook/lexical/releases/tag/v0.30.0)
- [v.0.29.0](https://github.com/facebook/lexical/releases/tag/v0.29.0)

___

TODO:
- [x] facebook/lexical#7719
- [x] facebook/lexical#7362
- [x] facebook/lexical#7707
- [x] facebook/lexical#7388
- [x] facebook/lexical#7357
- [x] facebook/lexical#7352
- [x] facebook/lexical#7472
- [x] facebook/lexical#7556
- [x] facebook/lexical#7417
- [x] facebook/lexical#1036
- [x] facebook/lexical#7509
- [x] facebook/lexical#7693
- [x] facebook/lexical#7408
- [x] facebook/lexical#7450
- [x] facebook/lexical#7415
- [x] facebook/lexical#7368
- [x] facebook/lexical#7372
- [x] facebook/lexical#7572
- [x] facebook/lexical#7558
- [x] facebook/lexical#7613
- [x] facebook/lexical#7405
- [x] facebook/lexical#7420
- [x] facebook/lexical#7662

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211202581885926
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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants