Skip to content

fix(Cx): coalesce re-entrant synchronous updates to avoid React max-update-depth#1310

Merged
mstijak merged 2 commits into
masterfrom
fix/cx-sync-update-coalescing
Jul 1, 2026
Merged

fix(Cx): coalesce re-entrant synchronous updates to avoid React max-update-depth#1310
mstijak merged 2 commits into
masterfrom
fix/cx-sync-update-coalescing

Conversation

@mstijak

@mstijak mstijak commented Jul 1, 2026

Copy link
Copy Markdown
Member

Large re-entrant renders — e.g. big reports that write to the store while they render — could re-render the root Cx and detached Restates hundreds of times in one synchronous burst, exceeding React's global nested-update limit ("Maximum update depth exceeded") and crashing or hanging the render.

Cx now coalesces re-entrant synchronous updates and, once a burst grows deep, yields to a microtask so React's counter resets before continuing. Updates that settle in a single render — virtually all of them — behave as before; it only diverges under a deep re-entrant burst. batchUpdatesAndNotify still resolves only once the store reaches a fixpoint, so measure-after-render flows such as page-breaking are unaffected.

On by default. Opt out at startup with disableSyncUpdateCoalescing() (please report any issues so they can be fixed), and tune the burst threshold with enableSyncUpdateCoalescing(limit).

Supersedes the approach in 15996b4.

mstijak added 2 commits June 30, 2026 15:12
…pdate-depth

Large renders that write to the store while rendering (e.g. a several-hundred-page report) could re-render the root Cx and detached Restates hundreds of times in one synchronous burst, exceeding React's global nested-update limit and crashing or hanging the render. Cx now coalesces re-entrant synchronous updates and yields to a microtask once a burst grows deep, so React's counter resets before continuing. Updates that settle in a single render -- virtually all of them -- behave as before; it only diverges under a deep re-entrant burst. batchUpdatesAndNotify still resolves only once the store reaches a fixpoint, so measure-after-render flows such as page-breaking are unaffected.

On by default. If you suspect it causes trouble, opt out at startup with disableSyncUpdateCoalescing() and please report the issue so it can be fixed. The burst threshold can be tuned with enableSyncUpdateCoalescing(limit).
@mstijak mstijak merged commit 769fbc8 into master Jul 1, 2026
2 checks passed
@mstijak mstijak deleted the fix/cx-sync-update-coalescing branch July 1, 2026 13:36
mstijak added a commit that referenced this pull request Jul 1, 2026
Re-entrant synchronous update coalescing in Cx to avoid React
max-update-depth (#1310) and the missing arrowIcon prop on
TreeNodeConfig (#1309).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant