[v3] Maximum update depth exceeded opening a document from the list view with cacheComponents: true (dev): backport #18702's CloseModalOnRouteChange guard

Aperta Adatta ai principianti
#19,954 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@MuhammadAhmad67889 ci sta già lavorando.

Dal 26/11/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
next.js, react, typescript
Ambito
frontend

Direzione di ricerca

Inizia da packages/ui/src/elements/CloseModalOnRouteChange/index.tsx e confronta l’implementazione di v3 con la versione protetta di v4. Riproduci il problema in un’app v3 usando Next 16, cacheComponents: true e next dev, aprendo un documento da un elenco di una collection. Il lavoro è completato quando il cambio di route chiude le modali aperte senza attivare l’errore di profondità massima degli aggiornamenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: ui Bug Payload OSS
Describe the Bug

CloseModalOnRouteChange (in @payloadcms/ui, 3.94.2) calls closeAllModals() every time its effect runs. With cacheComponents: true, React can re-run that effect without a route change, because Next keeps left pages mounted inside hidden <Activity> boundaries. Each closeAllModals() dispatch creates a new modal state even when no modal is open. That re-renders every modal consumer and runs the effect again, until React stops it with "Maximum update depth exceeded".

This is already fixed on the v4 line in #18702 ("feat: support cache components", see its "Render loop in dev" section). The fix closes modals only when the pathname actually changed and a modal is open. The current v3 release still has the unconditional call: packages/ui/src/elements/CloseModalOnRouteChange/index.tsx at v3.94.2 calls closeAllModalsEffectEvent() on every run, while v4.0.0-beta.12 has the guarded version. I couldn't find a backport PR. Could the #18702 guard be backported to 3.x?

Causal check: same server, same DB, same browser script, with the @payloadcms/ui client chunk rewritten in flight to drop only that closeAllModals() call.

opens that looped
unmodified 17 / 30
closeAllModals() call removed 0 / 30
Link to the code that reproduces this issue

No standalone repository: this was measured in a private app. The steps below reproduce it on any 3.x app with cacheComponents: true.

Reproduction Steps
  1. Take a Payload 3.x app (seen on 3.93.0; the code is unchanged in 3.94.2) on Next 16.4.x, with cacheComponents: true in next.config.
  2. Run next dev, log in to the admin, open any collection's list view (an upload collection is enough), and click a row to open the document.
  3. The document view throws "Maximum update depth exceeded". It depends on timing and happens on most opens: here 4–8 of every 6–9.

These do not loop:

  • a production build (next build + next start): 0 / 18 opens;
  • a full page load of the document URL: 0 / 12.

The loop happens on every collection, including one with no custom components or custom fields.

Which area(s) are affected?

area: ui

Environment Info
Payload: 3.93.0 (code unchanged in 3.94.2)
Next.js: 16.4.6
React: 19.2.4
next.config: cacheComponents: true
Mode: next dev only

Agent: Claude Code · claude-opus-5-5 · medium

Lingua principale
TypeScript
Stelle
46.1k
Fork
4.5k
Merge medio
2g 15h
PR unite (30g)
238

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di payloadcms/payload

Tutte le issue di payloadcms/payload

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.