Skip to content

fix(mobile): stop the Tasks page crashing on phones since the React Compiler build - #51418

Merged
AmoabaKelvin merged 3 commits into
mainfrom
fix-mobile-tasks-compiler-crash
Nov 28, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
fix-mobile-tasks-compiler-crash

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

Opening Tasks on a phone paired to a host built from current main showed "The downloaded app could not be opened" instead of the task list. Tasks works again.

Files Added Deleted Net
Test 0 0 0 0
Prod 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​191 $\color{#cf222e}{\Huge{\mathbf{−}}}$​56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​135

What Changed

  • Before: the phone's Tasks page crashed during render with React error feat: add autosaving #300 ("Rendered fewer hooks than expected"). The phone's page shell caught the fault and showed "The downloaded app could not be opened". This happened on every host built from main since feat(mobile): build mobile and mobile-web with React Compiler #50713, with or without repos or connected trackers, on both iOS and Android.
  • Cause: feat(mobile): build mobile and mobile-web with React Compiler #50713 started building the phone page with React Compiler. The Tasks screen is a chain of 36 stage hooks. Each stage wrote its fields into one shared model object with Object.assign(model, …). The compiler memoizes the first stage's result, so that object kept its identity across renders while later stages changed what was inside it. MobileTasksScreen then called MobileTasksLegacySurface({ model }) as a plain function, and the compiler cached that call on the model's identity. When the cache hit, the surface's own hooks (color scheme, themed styles, translation, state) didn't run in that render: 444 hooks in one render, 435 in the next, then React threw.
  • Fix:
    • Each stage returns a new object ({ ...model, …fields }). A changed stage now gives the model a new identity, so memos keyed on it recompute exactly when something changed.
    • MobileTasksScreen renders <MobileTasksLegacySurface model={…} /> as JSX, so the surface's hooks belong to its own component.
    • The mobile React Compiler hazard ratchet now also flags a component called as a plain function during render, and Object.assign onto a component's props or a hook's argument. Both are at 0 on this branch, and the ratchet flags MobileTasksScreen plus the 30 stage hooks on main.

Why

The compiler assumes props and hook arguments are never mutated, and that components are rendered rather than called. The Tasks chain broke both assumptions. Making each stage return a new object fixes the cause rather than hiding it:

  • A 'use no memo' opt-out would hide the pattern, and the existing hazard ratchet counts opt-outs as hazards.
  • Rendering the surface as JSX alone would only trade the crash for stale renders, because the model's identity would still lie.

The stage types already chain each stage's input to the previous stage's return type, so no stage can read a field that a later stage adds. Returning new objects therefore keeps what every stage sees the same as before #50713.

Linked Issue

No issue filed. This is a regression from #50713.

Visual Proof

iOS simulator (the 0.0.71 app), paired to a headless serve built from the worktree, opening Tasks. The phone's cached page was cleared before each capture so the right build ran:

Before: page built from main After: page built from this branch (light) After (dark, after a live theme switch re-render)
(screenshot removed: contained real product data) (screenshot removed: contained real product data) (screenshot removed: contained real product data)

The same before/after result reproduces on the 0.0.71 Android release app. There, logcat shows [web-shell] the page faulted … Minified React error #300 before the fix and no fault after it.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • Bisected on the Android release app against a worktree serve. Each page build was checked on its second open, because the first open after a host restart runs the phone's cached page. The page renders at 7bf178e58da~1 and faults at 7bf178e58da. It also renders with the compiler plugin turned off, or with development React.

  • On the faulting render, a debugger pause read the hook lists of the current and in-progress fibers: 444 hooks, then 435. The missing hooks were the surface's top-level hooks, and the compiled MobileTasksScreen shows the cached MobileTasksLegacySurface({ model: stage36 }) call.

  • No unit test added. The guard is the hazard ratchet: on main's sources it flags MobileTasksScreen.tsx and the 30 stage files, and on this branch it reports 0.

  • pnpm check:changed and the mobile typecheck pass. macOS host only; there's no platform-specific code.

Performance

The model is now copied instead of mutated in place. That's about 13k shallow property copies on a full rebuild of the 565-field model, measured at about 0.04 ms per Tasks render in V8. The cost doesn't grow with the number of tasks or repos, because it copies references and not collections. Tasks renders only on events (search typing, RPC replies, connection changes), never per terminal or agent update. The surface is now its own component, so bottom-bar height updates no longer rerun the 36-stage parent. The two ratchet rules add about 0.1 s to a build-time scan and nothing at runtime.

Risk

The riskiest part is Tasks behavior that relied on the shared object being mutated. Stage types make reading a later stage's field a type error, and a review checked every stage's keys and all test harnesses for that. If something was missed, a Tasks action would see an older value for one render. A plain revert brings the crash back.

Level: Low

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • No store build is needed. Tasks is a host-served page; native Metro builds use the same compiler and get the same fix.
  • The ratchet doesn't yet catch a component called from inside a lowercase render helper, or model.x = y writes. A scan of the app found none of either today.
  • The same sweep across mobile/app, mobile/src and mobile/web-entry found one other component called as a function: MobileAgentSessionHistoryIcon, from a renderIcon callback. It has no hooks and isn't called during a component's render, so it's left as is.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Since the page is built with React Compiler (#50713), Tasks faulted with React
error #300 and the phone showed 'The downloaded app could not be opened'. The
Tasks stage hooks wrote their fields into one shared model with Object.assign,
so the compiler-memoized model kept its identity while its contents changed,
and MobileTasksScreen called MobileTasksLegacySurface as a plain function that
the compiler cached on that identity. A cache hit skipped the surface's hooks.

Each stage now returns a new model object, the surface renders as JSX, and the
compiler hazard ratchet flags components called as functions and mutated props
or hook arguments.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The ratchet now counts render-time calls to PascalCase components and Object.assign mutations of React-function parameters, except in /test-support/ files. MobileTasksScreen renders MobileTasksLegacySurface through JSX. Multiple hooks now return new objects containing model properties and existing derived values or actions instead of mutating the model.

Merge Risk: Low · up to 304aa

The mobile Tasks crash fix looks mechanically sound. The new hazard ratchet has a few minor detection gaps: import aliases, rest-pattern bindings, and a possible false positive. These affect only the static check and not app behavior, so they can be fixed as a follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix, the affected page, and the platform: it stops the Tasks page crashing on phones after the React Compiler build. The changeset matches this. It moves the Tasks hook chain from …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is thorough and follows the template. It has an ELI5, a What Changed section with before/after and mechanism, a Why section that explains the alternatives rejected, a Visual Proof sect…
Full details: Title check

Explanation

The title names the fix, the affected page, and the platform: it stops the Tasks page crashing on phones after the React Compiler build. The changeset matches this. It moves the Tasks hook chain from in-place Object.assign mutation to returning new objects, renders MobileTasksLegacySurface as JSX, and extends the React Compiler hazard ratchet. The title does not name the root cause, but it covers the main change.

Full details: Description check

Explanation

The description is thorough and follows the template. It has an ELI5, a What Changed section with before/after and mechanism, a Why section that explains the alternatives rejected, a Visual Proof section with before/after images, a detailed Testing section, a Performance section, a Risk section with a Low level and a revert note, and a Notes and Checklist section. The Linked Issue section says no issue was filed and calls the change a regression from #50713. The template asks for a 'Fixes #' link, and the author did not provide one. The AI Disclosure section is empty, and the template only asks for it from non-team contributors. The 'Every added test fails without this change' box is unchecked, which matches the author's note that no unit test was added. Overall the description is mostly complete, and the gaps are the missing linked issue and the empty AI Disclosure section.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 685fb54f-bfd1-4318-a421-92ee91182421
Commits

Reviewing files that changed from the base of the PR and between 7ccda16 and 9bb3417.

Files selected for processing: 32

  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.mjs
  • mobile/src/tasks/MobileTasksScreen.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-detail-comment-renderers.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-github-check-file-actions.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-github-reply-merge-actions.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-gitlab-github-status-actions.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-hosted-comment-review-actions.tsx
  • mobile/src/tasks/item-detail/use-mobile-tasks-hosted-metadata-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-picker-projection.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-file-merge-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-loading-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-metadata-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-projection.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-repository-resolution.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-review-check-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-thread-reply-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-project-workspace-comment-actions.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-provider-view-projection.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-workspace-and-project-state.tsx
  • mobile/src/tasks/project-board/use-mobile-tasks-workspace-create-projection.tsx
  • mobile/src/tasks/providers/linear/use-mobile-tasks-linear-item-actions.tsx
  • mobile/src/tasks/screen-state/use-mobile-tasks-client-settings-actions.tsx
  • mobile/src/tasks/screen-state/use-mobile-tasks-connection-presentation.tsx
  • mobile/src/tasks/screen-state/use-mobile-tasks-runtime-hydration.tsx
  • mobile/src/tasks/task-list/use-mobile-tasks-list-and-detail-effects.tsx
  • mobile/src/tasks/task-list/use-mobile-tasks-provider-load-actions.tsx
  • mobile/src/tasks/task-list/use-mobile-tasks-task-create-actions.tsx
  • mobile/src/tasks/task-list/use-mobile-tasks-task-list-loading.tsx
  • mobile/src/tasks/task-list/use-mobile-tasks-task-pagination-actions.tsx
  • mobile/src/tasks/workspace-creation/use-mobile-tasks-workspace-create-actions.tsx
  • mobile/src/tasks/workspace-creation/use-mobile-tasks-workspace-sparse-actions.tsx
  • mobile/src/tasks/workspace-creation/use-mobile-tasks-workspace-ssh-state.tsx

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

if (
ts.isCallExpression(node) &&
ts.isIdentifier(node.expression) &&
components.has(node.expression.text) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Resolve imported component aliases before matching calls.

If one module exports Child and another imports { Child as RenamedChild }, a render-time RenamedChild() call is not counted unless some scanned declaration also happens to use that alias. The set at Line 482 contains declaration names, not import-local names.

Map named imports to their local bindings before this check. Keep the shadowing check so unrelated local bindings remain excluded.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3c0a86f1-dbce-4479-868e-8a49eb881275
Commits

Reviewing files that changed from the base of the PR and between 9bb3417 and 304aaf0.

Files selected for processing: 1

  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.mjs

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

}
// A rest element (...props) is a fresh object, so writing to it mutates nothing passed in.
return name.elements.flatMap((element) =>
ts.isOmittedExpression(element) || element.dotDotDotToken ? [] : parameterNames(element.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Keep bindings nested inside array rest patterns.

In useTask([first, ...[model]]), model still references an element of the caller’s array. Skipping the entire rest pattern means Object.assign(model, ...) is not detected as an argument mutation. Exclude the fresh rest array itself, but traverse nested binding patterns.


Minor · Functional Correctness · Quick win

Count rest-element bindings as shadowing names in parameterBinder.

A rest binding, such as update({ ...model }) nested inside useTask(model), shadows the outer model. parameterBinder ignores this binding because parameterNames skips rest elements. The search then reaches the outer useTask parameter. Object.assign(model, {}) inside update writes only to the fresh rest object, yet the ratchet counts it as a mutation of the hook argument.

Use a separate name lookup for shadowing. It returns rest-bound names, and parameterNames stays unchanged for mutation counting.

Suggested fix

+// Every name a parameter binds, including rest elements, so a shadowing rest binding is found.
+function boundNames(name) {
+  if (ts.isIdentifier(name)) {
+    return [name.text]
+  }
+  return name.elements.flatMap((element) =>
+    ts.isOmittedExpression(element) ? [] : boundNames(element.name)
+  )
+}
+
 // The nearest function whose own parameter binds `name`, so an inner helper's parameter of the same name is not the hook's.
 function parameterBinder(node, name) {
   for (let current = node.parent; current; current = current.parent) {
     if (
       (ts.isFunctionDeclaration(current) ||
         ts.isFunctionExpression(current) ||
         ts.isArrowFunction(current)) &&
-      current.parameters.some((param) => parameterNames(param.name).includes(name))
+      current.parameters.some((param) => boundNames(param.name).includes(name))
     ) {
       return current
     }
   }
   return null
 }

@AmoabaKelvin
AmoabaKelvin merged commit c7fe873 into main Nov 28, 2026
59 checks passed
AmoabaKelvin added a commit that referenced this pull request Nov 30, 2026
… calls and prop writes in the phone compiler hazard rules (#52876)

* fix(ratchets): catch aliased components, helper-called components and prop writes in the compiler hazard rules

The rules added in #51418 missed a component called under an import alias or
as a default import, a component called through a helper (here or in another
module) during render, and writes like model.x = ... into a prop or hook
argument during render. All three now count, with a fixture case each; ref
.current, Reanimated .value and writes inside callbacks or effects do not.
The rules and the shared module-graph helpers move to their own files to keep
the ratchet under the line limit.

* fix(ratchets): follow export lists, re-exports and namespace imports, and resolve prop writes by binding

Component seeds are now functions that render JSX or call hooks, so a
capitalized factory no longer spreads through helpers. Export lists,
re-exports, export * and namespace imports carry component callers across
modules, and anonymous default-exported components count. Prop writes unwrap
casts and non-null assertions, cover every assignment operator, read literal
element keys (ref['current']), and are attributed by the identifier's real
binding, so a shadowing local or a rest copy is not the argument. Changed-check
selection runs the collector and its fixtures when either extracted module
changes.

* fix(ratchets): resolve component callers per module and count only synchronous render-time calls

Component seeds are each module's own functions that render JSX or call hooks
(React.useX too) while they run, and imports resolve through what their module
exports, so a factory sharing a component's name elsewhere no longer counts.
Helper propagation follows namespace calls and skips timer or handler
callbacks, and Object.assign onto an argument counts only during render. The
write fixtures split into counted and uncounted files.

* fix(ratchets): resolve @/ imports and count arrow or anonymous-default components that call a component

The phone app's tsconfig maps @/* to src/*, so module resolution follows it
(this also covers the theme and language wrapper rule). A component written as
a PascalCase arrow or an anonymous default export that returns another
component's call now counts, as a named function declaration already did.

* fix(ratchets): tighten compiler hazard rules for nested names, default exports, rest arrays, refs and props

Seeds are module-level components only. A lowercase named default export that
renders counts. Writes into a rest-parameter array, or through a ref's
.current, don't count, while a component's own props.value or props.current
does. Object.assign into a member of an argument counts like a member write.

* fix(ratchets): count prop writes in components that only call hooks

* fix(ratchets): attribute prop writes to the nearest component or hook, default exports and IIFEs included

* fix(ratchets): recognize parenthesized default-export components

* fix(ratchets): ignore a shadowed Object in the Object.assign rule
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