Skip to content

fix(richtext-lexical): coerce integer upload and relationship IDs to number during HTML conversion#17357

Open
anaghroy wants to merge 1 commit into
payloadcms:mainfrom
anaghroy:fix/lexical-upload-integer-id
Open

fix(richtext-lexical): coerce integer upload and relationship IDs to number during HTML conversion#17357
anaghroy wants to merge 1 commit into
payloadcms:mainfrom
anaghroy:fix/lexical-upload-integer-id

Conversation

@anaghroy

@anaghroy anaghroy commented Jul 16, 2026

Copy link
Copy Markdown

What?

We are modifying the Lexical HTML converter ($convertUploadElement and $relationshipElementToNode) so that when it extracts integer IDs from the data-lexical-[type]-id HTML attribute, it correctly casts them into Number types instead of leaving them as strings.

Why?

When a Payload project is configured to use integer IDs for a collection (e.g. media), saving a Rich Text field containing Upload or Relationship nodes can fail validation. Because the Lexical DOM parser natively grabs HTML attributes as strings, it was passing a string (e.g. "2") into $createNode instead of the integer 2. This causes Payload's internal lifecycle hooks to reject the payload entirely with a ValidationError.

How?

Inside conversions.ts and RelationshipNode.tsx, we added a strict type-coercion check:

if (String(Number(id)) === id) {
  id = Number(id)
}

Screenshots

Screenshot 2026-07-16 142351 Screenshot 2026-07-16 142417 Screenshot 2026-07-16 142444 Screenshot 2026-07-16 142507

Closes #17344

@anaghroy
anaghroy requested a review from AlessioGr as a code owner July 16, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in HTML to lexical conversion with image reference.

1 participant