Orderable collections throw `DuplicateFieldName` for `_order` on the second dev reload with server fast refresh
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- next.js, node.js, typescript
Direzione di ricerca
Start with packages/payload/src/config/orderable/index.ts, especially addOrderableFieldsAndHook, and review the reproducing test described for packages/payload/src/config/sanitize.spec.ts. Run pnpm vitest run --project unit packages/payload/src/config/sanitize.spec.ts and check repeated sanitization of the same orderable collection config. Done means the repeated pass does not add duplicate _order fields or ordering hooks and the third pass does not throw; an open pull request is already linked.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
With Next.js server fast refresh on (the default since #18187) and reorderable collections enabled, the second Payload config reload in dev throws:
DuplicateFieldName: A field with the name '_order' was found multiple times on the same level. Field names must be unique.
From then on every getPayload call waits indefinitely (the reload promise in getPayload never settles after the throw), so every route hangs until the dev server restarts.
Cause: addOrderableFieldsAndHook (packages/payload/src/config/orderable/index.ts) unconditionally calls collection.fields.unshift(orderField) and collection.hooks.beforeChange.push(orderBeforeChangeHook). With server fast refresh, Next only re-evaluates changed modules, so an orderable collection whose module didn't change passes the same, already-sanitized config object into the next sanitizeConfig. The first reload gives it a second _order field and a second hook; the next reload's field sanitization throws.
v3 has the same code but isn't affected by default, as its withPayload still sets turbopackServerFastRefresh: false.
Fix: skip _order when the collection already has it, and replace the previous ordering hook instead of adding another. PR to follow.
Link to the code that reproduces this issue
https://github.com/damnsamn/payload-fork/commit/f1fdb82a51b2ba5fecb4dc2e6a596e317b119574
Reproduction Steps
The linked commit adds a failing test to packages/payload/src/config/sanitize.spec.ts that sanitizes the same orderable collection config twice, as a dev reload does for an unchanged module:
pnpm vitest run --project unit packages/payload/src/config/sanitize.spec.ts
It finds two _order fields after the second pass; a third pass throws DuplicateFieldName.
In an app:
- In a Payload v4 project on Next.js 16.3+, add a collection with
orderable: trueand any second collection. - Run
next dev. - Save a change to the second collection's file, then request any route. This works.
- Save another change, then request any route.
DuplicateFieldNameis logged and every request hangs until restart.
Adding --no-server-fast-refresh to next dev avoids it.
Which area(s) are affected?
area: core
Environment Info
payload: 4.0.0-beta.9
@payloadcms/next: 4.0.0-beta.9
@payloadcms/db-mongodb: 4.0.0-beta.9
next: 16.4.5 (Turbopack)
node: 24.22.3
Code unchanged on main (7a41086).
- Lingua principale
- TypeScript
- Stelle
- 45.8k
- Fork
- 4.4k
- Merge medio
- 3g 4h
- PR unite (30g)
- 210
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
area: ui Bug Payload OSS
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
payloadcms/payload#19839 ·
I maintainer di solito rispondono entro 1 giorno
-
Accessibility: list row and select-all checkboxes still unnamed in 3.x (#17376 fix not in 3.91)ApertaBug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
payloadcms/payload#19837 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19835 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19833 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19832 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
[BUG]: Shared links drop the configured basePath on GitHub PagesForse già presa @anshulchikhale30-p l’ha presa oggi. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add: GTrekkerApertacheck:passed streams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
I maintainer di solito rispondono entro 1 giorno