Skip to content

[lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an internal ephemeral node concept#7904

Merged
etrepum merged 4 commits intofacebook:mainfrom
etrepum:ephemeral-node
Oct 7, 2025
Merged

[lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an internal ephemeral node concept#7904
etrepum merged 4 commits intofacebook:mainfrom
etrepum:ephemeral-node

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Oct 6, 2025

Description

Some of the ugly parts in JSON + HTML export are related to dealing with partially selected TextNode. This tries to clean up some of those rough edges with a new internal concept.

Ephemeral Nodes

An ephemeral node is marked with the node[EPHEMERAL] === true (it is a symbol so is non-enumerable and won't show up with yjs). These instances always return this for getLatest and getWritable and are not allowed to be in an EditorState (which means they can not be a parent or child of some other node). You can create these with $cloneWithPropertiesEphemeral. This is mostly used to create a TextNode in a read-only context where we slice its __text based on the selection.

With this feature we can be more sure that state doesn't leak from these cloned nodes back into the EditorState, and that EditorState doesn't leak out into the accessors and mutators of the ephemeral node (e.g. setTextContent now works on these ephemeral nodes in a read-only editor with no errors or side-effects to the EditorState)

Test plan

New unit tests, all existing e2e + unit tests should pass

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Oct 6, 2025 6:31pm
lexical-playground Ready Ready Preview Comment Oct 6, 2025 6:31pm

@etrepum etrepum changed the title [lexical][lexical-clipboard][lexical-html] Feature: Add an ephemeral node concept and turn ArtificalNode into FragmentNode [lexical][lexical-clipboard][lexical-html] Feature: Add an ephemeral node concept Oct 6, 2025
@etrepum etrepum marked this pull request as ready for review October 6, 2025 18:21
@etrepum etrepum changed the title [lexical][lexical-clipboard][lexical-html] Feature: Add an ephemeral node concept [lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an ephemeral node concept Oct 6, 2025
@etrepum etrepum changed the title [lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an ephemeral node concept [lexical][lexical-clipboard][lexical-html][lexical-selection] Feature: Add an internal ephemeral node concept Oct 6, 2025
@etrepum etrepum added this pull request to the merge queue Oct 7, 2025
Merged via the queue into facebook:main with commit 3535213 Oct 7, 2025
39 checks passed
@etrepum etrepum mentioned this pull request Oct 11, 2025
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.

2 participants