You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(mobile): stop the Tasks page crashing on phones since the React Compiler build - #51418
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
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
}
… 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
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
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.
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.
What Changed
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.MobileTasksScreenthen calledMobileTasksLegacySurface({ 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.{ ...model, …fields }). A changed stage now gives the model a new identity, so memos keyed on it recompute exactly when something changed.MobileTasksScreenrenders<MobileTasksLegacySurface model={…} />as JSX, so the surface's hooks belong to its own component.Object.assignonto a component's props or a hook's argument. Both are at 0 on this branch, and the ratchet flagsMobileTasksScreenplus 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:
'use no memo'opt-out would hide the pattern, and the existing hazard ratchet counts opt-outs as hazards.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:
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 #300before 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~1and faults at7bf178e58da. 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
MobileTasksScreenshows the cachedMobileTasksLegacySurface({ model: stage36 })call.No unit test added. The guard is the hazard ratchet: on main's sources it flags
MobileTasksScreen.tsxand the 30 stage files, and on this branch it reports 0.pnpm check:changedand 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
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
model.x = ywrites. A scan of the app found none of either today.mobile/app,mobile/srcandmobile/web-entryfound one other component called as a function:MobileAgentSessionHistoryIcon, from arenderIconcallback. It has no hooks and isn't called during a component's render, so it's left as is.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)