Skip to content

Cannot use orderable on collections with both SEO plugin and autosaving drafts #12212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joedawson opened this issue Apr 24, 2025 · 3 comments
Closed
Assignees

Comments

@joedawson
Copy link

Describe the Bug

Hello,

I recently opened an issue that was closed as I could not provide a complete reproduction.

I've been able to replicate the two issues I was having:

  • Not being able to "migrate" your data to use the new orderable feature
  • Seeing a blank create screen after enabling orderable on a collection

To replicate this, you need the following on your collection:

  • orderable: true
  • the @payloadcms/plugin-seo plugin enabled for your collection
  • drafts enabled, using autosave

I've seen my previous issue mentioned in PR #12129 and I did originally have my hunch set on this being my issue - but even without tabs I am getting my mentioned issues.

I believe I have provided a sufficient reproduction now that outlines the issues I was experiencing but only when the specifics mentioned above are being used.

Link to the code that reproduces this issue

https://github.com/joedawson/orderable-issue/

Reproduction Steps

  1. Add 2-3 docs in "Themes" collection
  2. Enable orderable: true in the themes collection
  3. You will not yet be able to reorder, without migrating the data. There is a GET handler via /api/handle to attempt to migrate the data
  4. The first theme will be given an _order value but all subsequent documents will fail:
Updated theme 1 with orderable value
Failed to update theme 6: Error [ValidationError]: The following field is invalid: _order
    at async GET (src/app/(frontend)/api/handle/route.ts:24:8)
  22 |     for (const doc of themes.docs) {
  23 |       try {
> 24 |         await payload.update({
     |        ^
  25 |           collection: 'themes',
  26 |           id: doc.id,
  27 |           data: {} {
  data: [Object],
  isOperational: true,
  isPublic: false,
  status: 400,
  [cause]: [Object]
}
 GET /api/handle 200 in 912ms
  1. Attempt to create a new document in this same collection, you will now see a blank screen with the following errors in console:
key not found: error:valueMustBeUnique
key not found: error:followingFieldsInvalid
[23:48:24] INFO: error:followingFieldsInvalid _order

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

plugin: seo, area: core

Environment Info

Binaries:
  Node: 22.4.1
  npm: 10.8.1
  Yarn: N/A
  pnpm: 9.5.0
Relevant Packages:
  payload: 3.35.1
  next: 15.3.0
  @payloadcms/db-postgres: 3.35.1
  @payloadcms/graphql: 3.35.1
  @payloadcms/next/utilities: 3.35.1
  @payloadcms/plugin-seo: 3.35.1
  @payloadcms/richtext-lexical: 3.35.1
  @payloadcms/translations: 3.35.1
  @payloadcms/ui/shared: 3.35.1
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
@joedawson joedawson added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels Apr 24, 2025
@github-actions github-actions bot removed the validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. label Apr 24, 2025
@GermanJablo GermanJablo self-assigned this Apr 25, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Apr 25, 2025
@DanRibbens
Copy link
Contributor

We found the cause of the issue. We will keep working on this PR to resolve it. #12331

DanRibbens added a commit that referenced this issue May 16, 2025
⚠️ `orderable` fields will no longer be `required` and `unique`, so your
database may prompt you to accept an automatic migration if you're using
[this
feature](https://payloadcms.com/docs/configuration/collections#config-options).
Note that the `orderable` feature is still experimental, so it may still
receive breaking changes without a major upgrade or contain bugs. Use it
with caution.
___

The `orderable` fields will not have `required` and `unique` constraints
at the database schema level, in order to automatically migrate
collections that incorporate this property.

Now, when a user adds the `orderable` property to a collection or join
field, existing documents will have the order field set to undefined.
The first time you try to reorder them, the documents will be
automatically assigned an initial order, and you will be prompted to
refresh the page.

We believe this provides a better development experience than having to
manually migrate data with a script.

Additionally, it fixes a bug that occurred when using `orderable` in
conjunction with groups and tabs fields.

Closes:
- #12129
- #12331
- #12212

---------

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
@GermanJablo
Copy link
Contributor

This should be fixed with #12422. It will be in the next release.
Thanks a lot!

kendelljoseph pushed a commit that referenced this issue May 19, 2025
⚠️ `orderable` fields will no longer be `required` and `unique`, so your
database may prompt you to accept an automatic migration if you're using
[this
feature](https://payloadcms.com/docs/configuration/collections#config-options).
Note that the `orderable` feature is still experimental, so it may still
receive breaking changes without a major upgrade or contain bugs. Use it
with caution.
___

The `orderable` fields will not have `required` and `unique` constraints
at the database schema level, in order to automatically migrate
collections that incorporate this property.

Now, when a user adds the `orderable` property to a collection or join
field, existing documents will have the order field set to undefined.
The first time you try to reorder them, the documents will be
automatically assigned an initial order, and you will be prompted to
refresh the page.

We believe this provides a better development experience than having to
manually migrate data with a script.

Additionally, it fixes a bug that occurred when using `orderable` in
conjunction with groups and tabs fields.

Closes:
- #12129
- #12331
- #12212

---------

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
Copy link
Contributor

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants