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

オープン 初心者向け
#19,954 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@MuhammadAhmad67889 がすでに取り組んでいます。

2026年11月26日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
79/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
next.js, react, typescript
領域
frontend

調査の方向性

packages/ui/src/elements/CloseModalOnRouteChange/index.tsxから始め、v3の実装とv4のガード付きバージョンを比較します。Next 16でcacheComponents: trueとnext devを使うv3アプリで、コレクションの一覧からドキュメントを開いて再現します。ルート変更によって開いているモーダルが閉じ、最大更新深度エラーが発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
46.1k
フォーク
4.5k
平均マージ
2日 15時間
マージ済み PR(30日)
238

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

payloadcms/payload のほかの issue

payloadcms/payload の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。