fix(mobile): the split-view sidebar no longer crashes in an update loop#21867

merged2
main
GitHub fork: pixpmusic/android-sidebar-update-loop
opened27d agobyAAlex
View on GitHubTwo-way sync enabledPR last imported 26d ago

Fixes #21866.

Problem

On an unfolded Android foldable, opening a thread's inspector in split view crashes the sidebar with Maximum update depth exceeded ("The sidebar couldn't be displayed").

#21133 left AdaptiveWorkspaceLayout's baseLayout, layout, fileInspector, and panes to the React Compiler. The compiler can't memoize them because they stay live across later hook calls, so the compiled component rebuilds all four on every render. That gives the workspace context a new value on every render, which then loops:

  1. The thread screen's useRegisterWorkspaceInspector registers its inspector, which sets layout state.
  2. The layout re-renders and publishes a new context.
  3. The thread screen re-renders, passes a new inspector renderer, and registers again.

One inspector open produced about 100 back-to-back registrations. The sidebar re-renders on every pass and its LegendList throws first.

Fix

  • AdaptiveWorkspaceLayout memoizes the four derivations again, with the dependencies they had before #21133. A comment says why the compiler can't.
  • ThreadNavigationSidebar memoizes projectScopes, projectTitleByProjectKey, projectByKey, and threadSearchMatchByKey again, which #21145 also left to the compiler. They reach LegendList as extraData, so a fresh copy on each sidebar render re-rendered every row. This alone doesn't stop the loop, but it is the same compiler gap and the reason every pass reached the list.

Mobile lint allows memo hooks (allowMemoHooks), and both files still compile under the React Compiler.

Why this qualifies as a small focused fix

It's one regression: derived values the compiler can't memoize, in the two components the loop runs through. Both changes restore the memoization those files had before #21133 and #21145.

Verification

On the Android 17 Pixel 9 Pro Fold emulator, unfolded, with the showcase Moonbase fixtures, opening a thread, then opening and closing the inspector:

  • Bisect: the commit before #21133 never loops, and #21133 loops on every run. Restoring only the old AdaptiveWorkspaceLayout.tsx stops it.
  • This branch, rebased on b20f55248d: 0 Maximum update depth errors in fresh sessions, where main hits it every time.
  • extraData: an instrumented build showed the sidebar's extraData changing on every render on main (35 times during one inspector open), against 2 real changes with this branch.
  • Checks:
    • vp run typecheck in apps/mobile passes.
    • vp lint on both files reports the same warnings as main.
    • reactCompilerCoverage.test.ts passes (878 tests).

#20813 also edits the layout, fileInspector, and panes calls, adding the rail width, and keeps them unmemoized. Whichever lands second needs a small conflict resolution and should keep the memoization, adding navigationRailWidth and width to the dependencies.

Before / After

Android 17 Pixel 9 Pro Fold emulator, unfolded, demo data. Each run opens a thread, then opens and closes the inspector.

Before (main)After (this branch)
External imageExternal image External image
Opening the inspector ends in Maximum update depth exceeded.The inspector opens and closes, and the sidebar comes back.
VideoVideo

Model: Claude Opus 5.5 | Harness: Claude Code in T3 Code

Checks

24 successful · 9 skipped
All checks passed
4b89f48

Added 2 commits

  • fix(mobile): sidebar rows re-render only when their data changes4b89f48
  • fix(mobile): the split-view sidebar no longer crashes in an update loop4bfb865
Synced from GitHub

Approvability

Verdict: Approved at 4b89f48

Macroscope's review found this PR approvable — This is a focused mobile bug fix that memoizes existing layout and sidebar derivations to stabilize context and list inputs, preventing the reported update loop and reducing unnecessary rerenders. It introduces no new capability, schema, infrastructure, security, billing, or static-analysis configuration changes.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0f37abe-ba80-45b7-9d5f-5ccd70e40939
📥 Commits

Reviewing files that changed from the base of the PR and between 034b50616165fc25195e25bfddb188639bfefa34 and 4b89f488c90b92e6611fc1b860fe74dc8dea47c7.

📒 Files selected for processing: 2
  • apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
  • apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The mobile workspace layout now memoizes derived layout objects. The thread navigation sidebar now memoizes search-match and project lookup data using their source inputs.

Changes: Adaptive workspace layout

Layer / File(s)Summary
Memoize workspace layout derivations
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
The base layout, hinge-aligned layout, file inspector, and panes are memoized with relevant input dependencies.

Thread navigation sidebar

Layer / File(s)Summary
Memoize sidebar lookup data
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
Search-match data and project scopes and lookup maps are memoized using their source data and relevant filter inputs.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to 4b89f

This change restores memoization to stop the Android split-view inspector update loop. It does not change layout or filtering logic. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Description checkPassedThe description is complete and directly matches the required template. It explains the problem, fix, scope, linked issue, verification results, UI evidence, and agent details.
Title checkPassedThe title clearly and concisely describes the main fix: preventing the mobile split-view sidebar from crashing in an update loop.
Linked Issues checkPassedThe PR addresses the coding requirement in #21866. AdaptiveWorkspaceLayoutContent memoizes baseLayout, layout, fileInspector, and panes, which stabilizes the workspace context inputs used du…
Out of Scope Changes checkPassedThe diff changes only AdaptiveWorkspaceLayout.tsx and ThreadNavigationSidebar.tsx. The added memoization and comments directly support the #21866 update-loop fix and sidebar rendering stability. N…
Full details: Linked Issues check

Explanation

The PR addresses the coding requirement in #21866. AdaptiveWorkspaceLayoutContent memoizes baseLayout, layout, fileInspector, and panes, which stabilizes the workspace context inputs used during inspector registration. ThreadNavigationSidebarPane memoizes the four derived maps passed through sidebar rendering and LegendList extraData. The reported unfolded Android verification shows the inspector opens and closes without update-depth errors. The reported apps/mobile typecheck and React Compiler coverage test also pass.

Full details: Out of Scope Changes check

Explanation

The diff changes only AdaptiveWorkspaceLayout.tsx and ThreadNavigationSidebar.tsx. The added memoization and comments directly support the #21866 update-loop fix and sidebar rendering stability. No unrelated behavior or files are included.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.