fix(web): prevent infinite render loop on /apps page#35393
Open
lyzno1 wants to merge 1 commit intolanggenius:mainfrom
Open
fix(web): prevent infinite render loop on /apps page#35393lyzno1 wants to merge 1 commit intolanggenius:mainfrom
lyzno1 wants to merge 1 commit intolanggenius:mainfrom
Conversation
Stabilize the `pages` reference derived from the infinite query result so
that the downstream `appIds` memo, `refreshWorkflowOnlineUsers` callback
and the effect that calls it stop re-running on every render.
Before this change, `data?.pages ?? []` produced a fresh empty array on
every render whenever the query had not yet resolved. That fresh
reference cascaded into a new `appIds` array, a new callback identity and
a re-running effect that called `setWorkflowOnlineUsersMap({})` with a
new object literal each time, eventually tripping React's
"Maximum update depth exceeded" guard on `/apps`.
The line itself is four months old; it became reachable only after the
collaboration feature added the `setState`-in-effect chain that depends
transitively on `pages`.
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stabilize the
pagesreference derived from the apps infinite query so the downstreamappIdsmemo,refreshWorkflowOnlineUserscallback, and the effect that consumes it stop re-running on every render. Without this, opening/appson a fresh load can trip React'sMaximum update depth exceededguard.Root cause
web/app/components/apps/list.tsxhad a stale-but-latent line:When
useInfiniteAppListhas not resolved yet,data?.pages ?? []produces a brand-new empty array on every render. That fresh reference cascaded:appIds = useMemo(..., [pages])— recomputes, returns a new array.refreshWorkflowOnlineUsers = useCallback(..., [appIds, ...])— new function identity each render.useEffect(() => void refreshWorkflowOnlineUsers(), [refreshWorkflowOnlineUsers])— re-runs every render.setWorkflowOnlineUsersMap({})with a brand-new{}literal, which React cannot bail out on (Object.is({}, {}) === false).The
pages = data?.pages ?? []line itself has existed since #29004 (2025-12-02) and was harmless because nothing read it reactively. The collaboration feature in #30781 (2026-04-16) introduced thesetState-in-effect chain that depends transitively onpages, which is what made the latent reference instability fatal.Fix
Memoize
pagesso that the empty fallback keeps a stable reference across renders:This breaks the loop by stabilizing the entire downstream chain. No behavior change in the resolved-data path (TanStack Query already returns a stable
data.pagesreference once data is loaded).Test plan
/appson a fresh dev server (pnpm dev) — noMaximum update depth exceededconsole error.enable_collaboration_mode = falsepath still clearsworkflowOnlineUsersMapexactly once.Notes / follow-ups (out of scope)
The
workflowOnlineUsersMapblock (useState+useEffect+setInterval+ manual fetch) is essentially server state being managed as client state. A cleaner long-term fix is to migrate it to auseQuery({ queryKey: ['workflowOnlineUsers', appIds], refetchInterval: 10_000 }), which would eliminate the entire dependency chain that this PR stabilizes. Filed mentally for a follow-up; this PR keeps the surface minimal.Made with Cursor