Skip to content

RichText Lexical Field throws 'Uncaught SyntaxError: "undefined" is not valid JSON' when prevValueRef.current is undefined (since v3.58.0) #14372

@jhb-dev

Description

@jhb-dev

Describe the Bug

After #13962 (released in Payload v3.58.0), the RichText Lexical field crashes if prevValueRef.current is undefined. The component calls JSON.parse on an undefined value which results in:

Uncaught SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at Field.tsx:150:22

This is reproducible with an empty RichText field and using the translator plugin to translate a document in payload >= 3.58.0.

Link to the code that reproduces this issue

https://github.com/r1tsuu/payload-enchants/tree/master/packages/translator

Reproduction Steps

  1. Install Payload ≥ 3.58.0 with @payloadcms/richtext-lexical.
  2. Add the Translator plugin by ritsu: https://github.com/r1tsuu/payload-enchants/tree/master/packages/translator
  3. Create a collection with a RichText (Lexical) field.
  4. Create a new document where this RichText field is empty.
  5. Trigger a translation that writes to the empty RichText field.

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

plugin: richtext-lexical

Environment Info

Binaries:
  Node: 24.3.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.12.4
Relevant Packages:
  payload: 3.59.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions