Skip to content

LinkFeature always saves relationTo as first collection when creating a doc #14728

@6TELOIV

Description

@6TELOIV

Describe the Bug

When using the built in lexical LinkFeature with more than one enabledCollection, creating an internal link to a doc created through the link UI always saves the relationTo as the first collection in the enabledCollections array. At best, it prevents saving with a validation error. At worst, this causes the user to save an incorrect link unknowingly.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/main/templates/website

Reproduction Steps

The bug is present in the website template, so we'll use that.

  1. Create or edit an existing doc in the Pages collection.
  2. In a rich text field (ex: hero.richText) add a link.
  3. Change the link to "internal link" and create a new doc in any collection but the first (in this case, Posts).
    Image
  4. Fill the required fields and save and close then new doc.
  5. Notice the link is now pointing to a (potentially invalid) doc from the first collection (in this case, Pages)
    Image
  6. Save and close the link, and try to save the page where you made the link. If the doc ID is invalid, you will see this error:
    Image

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

db: postgres, area: docs, plugin: richtext-lexical

Environment Info

Payload: 3.63.0
Node.js: 22.X (deployed on vercel)
Next.js: 15.4.7

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions