Skip to content

fix(web): prevent StatusBar infinite render loop (React #185) - #1

Merged
Eliasriv748 merged 2 commits into
mainfrom
fix/statusbar-render-loop
Jun 15, 2026
Merged

Eliasriv748 merged 2 commits into
mainfrom
fix/statusbar-render-loop

Conversation

@Eliasriv748

Copy link
Copy Markdown
Owner

Problem

Opening a thread threw React error pingdotgg#185 ("Maximum update depth exceeded") — an infinite re-render loop. The desktop app's embedded server (port 3773) served the old bundle, so the loop fired on every affected build.

Root cause

StatusBar derived a fresh ContextWindowSnapshot object inside the useStore selector. Each store read returned a new object reference, so zustand's useSyncExternalStore saw a changed value every render → infinite loop. It only triggered once a thread had context/token data to show.

Fix

  • Select only the stable source data (activity ids + activity map) via useShallow, then derive the snapshot in useMemo so it recomputes only when the source changes.
  • Use stable module-level empty constants (EMPTY_ACTIVITY_IDS / EMPTY_ACTIVITY_MAP) for the fallback branches, so a freshly-opened thread with no activity yet can't defeat useShallow's reference comparison and re-loop.

Also included

  • chore(desktop): neverBundle: ["electron"] in pack/preload config (pre-existing local change).

Verification

  • apps/web rebuilt successfully (new bundle index-CLBfhs73.js).
  • Re-bundled into apps/server/dist/client; the old broken bundle is gone.
  • Restart desktop app + open thread to confirm the loop is resolved.

🤖 Generated with Claude Code

Eliasriv748 and others added 2 commits June 14, 2026 21:33
StatusBar derived a fresh ContextWindowSnapshot object inside the
useStore selector, so zustand's useSyncExternalStore saw a changed
reference on every render and triggered "Maximum update depth exceeded"
(React error pingdotgg#185) whenever a thread with context data was opened.

Split the selector into a useShallow selection of the stable source
data (activity ids + activity map) and a useMemo that derives the
snapshot only when those change. Also use stable module-level empty
constants for the fallback branches so a freshly-opened thread with no
activity yet cannot defeat useShallow's reference comparison and loop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Eliasriv748
Eliasriv748 merged commit f0e4452 into main Jun 15, 2026
@Eliasriv748
Eliasriv748 deleted the fix/statusbar-render-loop branch June 15, 2026 01:34
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