Skip to content

Bug: Polymorphic uploads crash when used in a block within Lexical #14542

@immotus

Description

@immotus

Describe the Bug

Polymorphic uploads within a block used in a Lexical editor cause the editor to crash.

For instance, a simple block like this:

export const TestBlock: Block = {
	slug: "test-block",
	fields: [
    {
      type: "text",
      name: "title",
    },
    {
      type: "upload",
      name: "image",
      relationTo: [ "assets", "media" ],
      required: true,
    }
  ],
};

Embedded within a Lexical editor like this:

  fields: [
    {
      name: "content",
      type: "richText",
      editor: lexicalEditor({
        features: ({ defaultFeatures }) => [
          ...defaultFeatures,
          BlocksFeature({
            blocks: [
              TestBlock,
            ],
          })
        ],
      }),
    },
  ],

Initially, it worked as expected, allowing me to create a new document with these blocks and select images. However, attempting to change the upload within the block after saving the document crashes the entire editor to an unrecoverable state.

Video_2025-11-09_024253.mp4

Link to the code that reproduces this issue

https://github.com/immotus/bug-polymorphic-uploads/

Reproduction Steps

  1. Clone the repo
  2. pnpm i
  3. pnpm dev
  4. Go to localhost:3000
  5. Seed the test database
  6. Upload some images into the Assets collection
  7. Go to the Test collection and create a new document
  8. Add a couple of TestBlocks linking to images in Assets and Media collections
  9. Save the document
  10. Go to the Test collection and open the newly created document again
  11. Try to change images within the blocks to another image from a different collection

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

plugin: richtext-lexical, area: core

Environment Info

Binaries:
  Node: 24.8.0
  npm: N/A
  Yarn: N/A
  pnpm: 10.17.0
Relevant Packages:
  payload: 3.63.0
  next: 15.4.7
  @payloadcms/db-mongodb: 3.63.0
  @payloadcms/graphql: 3.63.0
  @payloadcms/live-preview: 3.63.0
  @payloadcms/live-preview-react: 3.63.0
  @payloadcms/next/utilities: 3.63.0
  @payloadcms/plugin-form-builder: 3.63.0
  @payloadcms/plugin-nested-docs: 3.63.0
  @payloadcms/plugin-redirects: 3.63.0
  @payloadcms/plugin-search: 3.63.0
  @payloadcms/plugin-seo: 3.63.0
  @payloadcms/richtext-lexical: 3.63.0
  @payloadcms/translations: 3.63.0
  @payloadcms/ui/shared: 3.63.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32631
  Available CPU cores: 16

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions