Skip to content

TextStateFeature: Partial selection erases key-values from subsequent TextNodes #13386

Closed

Description

@BoavidaGuerra

Describe the Bug

When applying a new (e.g.) text colour to a partial selection inside a TextNode, TextStateFeature splits the original TextNode into multiple segments (before selection, selection, after selection). However, during this split and patch process, it incorrectly discards the existing key-values (like background colour and text colour) from all resulting TextNodes after the selection.

Expected:

  • The key-values (background and text colours) remain intact on all unselected portions.
  • Only the selected portion receives the new text colour override.

Actual:

  • All text following the selection loses the previously applied key-values.

Link to the code that reproduces this issue

https://github.com/BoavidaGuerra/payload/tree/reproduction/text-state-feature-bug

Reproduction Steps

  1. create a TextNode:
Image
  1. apply a background colour and text colour to the TextNode.:
Image
  1. select a portion of that TextNode and apply a different text colour
Image

The expectation is:

Image

But outcome is:

Image

Which area(s) are affected? (Select all that apply)

plugin: richtext-lexical

Environment Info

Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: N/A
  pnpm: 9.7.1
Relevant Packages:
  payload: 3.50.0
  next: 15.4.4
  @payloadcms/db-postgres: 3.50.0
  @payloadcms/live-preview-react: 3.50.0
  @payloadcms/translations: 3.50.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:43 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8132
  Available memory (MB): 32768
  Available CPU cores: 10

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Aug 6, 2025
  2. removed
    validate-reproduction
    on Aug 6, 2025
  3. added
    plugin: richtext-lexical
    on Aug 6, 2025
  4. removed
    status: needs-triage
    on Aug 6, 2025
  5. GermanJablo commented on Aug 7, 2025

    @GermanJablo
    Contributor

    Thanks. I remember running into that problem. I think it's a bug in Lexical, specifically in the forEachSelectedTextNode function.

  6. added
    dependency-issue
    on Aug 7, 2025
  7. BoavidaGuerra commented on Aug 26, 2025

    @BoavidaGuerra
    Author

    Hi @GermanJablo ,
    Looks like the bug was fixed in Lexical by the following commit: meta/lexical#7641 , which was released in v0.33.0.

    By fixing the TextNode.splitText method (which previously did not copy the NodeState), the behaviour in forEachSelectedTextNode was also corrected.

    If I'm not mistaken, Payload is currently using v0.28.0 of Lexical. Do you guys have any plans to upgrade it?

  8. added a commit that references this issue on Sep 3, 2025
    1a1696d
  9. github-actions commented on Sep 9, 2025

    @github-actions
    Contributor

    🚀 This is included in version v3.55.0

  10. github-actions commented on Sep 17, 2025

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  11. locked as resolved and limited conversation to collaborators on Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dependency-issueplugin: richtext-lexical

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions