Skip to content

fix(ratchets): catch aliased, helper-called and re-exported component calls and prop writes in the phone compiler hazard rules - #52876

Merged
AmoabaKelvin merged 9 commits into
mainfrom
fix-compiler-hazard-ratchet-gaps
Nov 30, 2026
Merged

AmoabaKelvin merged 9 commits into
mainfrom
fix-compiler-hazard-ratchet-gaps

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

#51418 added two lint rules that stop the phone app's React Compiler build from crashing or showing stale data. One catches components called like plain functions; the other catches code writing into what a component was given. Both rules only saw the exact form of the original bug. This teaches them the other common forms, so the same mistake can't come back in another form.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​217 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​217
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​563 $\color{#cf222e}{\Huge{\mathbf{−}}}$​184 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​379

What Changed

Before, the mobile React Compiler hazard ratchet missed three shapes. I confirmed each on fresh main, with all three probes present, the ratchet reported 0:

  • Renamed imports: a component called under an import alias or a default import.
  • Components called from helpers: a component called through a helper during render.
  • Prop writes: writes like model.x = … into a prop or hook argument during render.

Now each module's own components and helpers are resolved, and imports follow what their module actually exports:

  • Component calls: a component counts when called during render under an alias, as a default import (anonymous default exports included), as a namespace import (K.Child()), through an @/ import (the alias in mobile/tsconfig.json), or through a helper. The helper can be in the same module or come through an export { } list, a re-export or export *.
    • A "component" is a function that renders JSX or calls a hook while it runs, so capitalised factories don't count.
    • A component written as a PascalCase arrow, or an anonymous default export that returns another component's call, counts too.
    • Helper calls inside timer or handler callbacks don't count.
  • Prop writes: writes into a prop or hook argument during render count. That covers every assignment operator, ++/-- and delete, and sees through casts and !.
    • These are not counted: ref .current (also ['current']), Reanimated .value, writes in callbacks and effects, rest copies, and locals that shadow the argument.
    • Object.assign onto an argument now also counts only during render.
  • Fixture test: a new check-mobile-react-compiler-hazard-ratchet.test.mjs runs the real collector on throwaway git repos, one case per gap. Every case fails against main's ratchet.
  • File layout: the rules and the shared module-graph helpers moved to react-compiler-render-ownership-hazards.mjs and mobile-module-graph.mjs, to keep the ratchet under the 600-line limit. Changed-check selection runs the collector and its fixtures when either file changes. scopeDeclares is now exported from render-path-translate.mjs for binding resolution.

The ratchet still reports 0 on the app.

Why

Resolving each module's real bindings, rather than matching component names across all files, keeps the rules precise. An unrelated factory that shares a component's name no longer counts, and an aliased or re-exported component no longer slips through. Limiting writes to render time matches what the compiler actually breaks on: a handler writing into a mutable store argument is fine.

Linked Issue

Follow-up to #51418. No issue filed.

Visual Proof

N/A: build-time lint only, no app change.

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

  • The fixture test has 3 cases: component calls, helpers, writes. All pass, and all fail against main's ratchet.

  • The original fix(mobile): stop the Tasks page crashing on phones since the React Compiler build #51418 shape (return MobileTasksLegacySurface({ model }) plus Object.assign(model, …)) is still counted.

  • The ratchet reports 0 on the current app. A reviewer compared the old and new rules across all 3,204 scanned files: no app call site was gained or lost.

  • pnpm check:changed passes.

Performance

Build-time only. The collector takes about 2.0–2.4 s on the app, against about 1.6–2.1 s before: one extra pass over the module graph that settles in 3 iterations. No runtime cost.

Risk

A false positive blocks a PR at lint time until the code is changed or the rule is fixed. The rules report 0 on today's app, and their exemptions are covered by fixtures. A plain revert restores the previous rules.

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

Known limits, none present in the app today:

  • export * as NS from re-exports aren't followed.
  • require() imports aren't followed.
  • A component called inside a closure passed to an arbitrary function isn't counted. Only known synchronous callers (array methods, an immediately-run function, memo hooks) count, so timer callbacks are skipped.

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)

… 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.
… 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.
…nchronous 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.
…t 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.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The pull request exports scopeDeclares without changing its behavior. It adds mobile module-graph utilities and React Compiler render-ownership hazard analysis. The ratchet uses the new analysis to detect component calls during render and writes to React function parameters. New tests cover detected and excluded cases. Changed-check selection now associates the shared analysis modules with the ratchet check.

Merge Risk: Low · previous review af7c8

This extends a lint-time ratchet. A few rare code patterns could be wrongly flagged and block a PR, and the check now takes a few hundred milliseconds longer. There is no production impact, and a revert is simple, so the merge risk is low.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the mobile React Compiler hazard ratchet now catches aliased, helper-called and re-exported component calls and prop writes. It matches the changeset and objectives. T…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with level, Agent skill upstream boundary…
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.
Full details: Title check

Explanation

The title names the main change: the mobile React Compiler hazard ratchet now catches aliased, helper-called and re-exported component calls and prop writes. It matches the changeset and objectives. The title is long (126 characters) and dense, but it is specific and on topic.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with level, Agent skill upstream boundary, Notes, and Checklist. Its content matches the objectives and the file summaries. The Linked Issue section says there is no issue, only a follow-up to #51418. The AI Disclosure section is empty, and the template's rule for that section applies to internal contributors only. The Performance section is filled in. The Testing section has checkboxes and details.

  • 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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Treat case and default clauses as one lexical scope in… · render-path-translate.mjs:261-267

config/scripts/localization/reactive-translate/render-path-translate.mjs:261-267
Minor · Functional Correctness · Quick win

Treat case and default clauses as one lexical scope in scopeDeclares.

scopeDeclares checks each CaseClause and DefaultClause only against its own statements. A switch shares one block scope across all its clauses, so a let or const declared in one clause is visible in the others. isOwnerParameter walks up from the identifier and stops at the first scope that declares the name. Within a switch, that walk misses a binding declared in a sibling clause, then matches the function parameter. A write to the switch-scoped local is then reported as a write to the parameter. The PR's stated exclusion for shadowing locals does not hold for this case.

Add a CaseBlock branch that checks every clause:

Suggested fix

   if (
     ts.isBlock(scope) ||
     ts.isModuleBlock(scope) ||
     ts.isCaseClause(scope) ||
     ts.isDefaultClause(scope)
   ) {
     return scope.statements.some((statement) => statementDeclares(statement, name))
   }
+  if (ts.isCaseBlock(scope)) {
+    return scope.clauses.some((clause) =>
+      clause.statements.some((statement) => statementDeclares(statement, name))
+    )
+  }
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: a47815c2-8e35-41fe-b372-84380ced6252
Commits

Reviewing files that changed from the base of the PR and between 7ee4c2f and ca382f5.

Files selected for processing: 6

  • config/scripts/localization/reactive-translate/render-path-translate.mjs
  • config/scripts/preflight/changed-checks/check-changed-selection.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.test.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/mobile-module-graph.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/react-compiler-render-ownership-hazards.mjs

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

…t 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.

@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: 1

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: dbdea637-0caa-481a-b2f6-41ccb1236b09
Commits

Reviewing files that changed from the base of the PR and between ca382f5 and 923e8d8.

Files selected for processing: 2

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

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

@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: 3

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: 21b8bb31-6b8b-4dbf-9639-43e1e52fb1e8
Commits

Reviewing files that changed from the base of the PR and between 923e8d8 and 34c347e.

Files selected for processing: 2

  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.test.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/react-compiler-render-ownership-hazards.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.

@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: 1

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: bd5be34e-2add-4fbf-9b89-bc39e3fe848a
Commits

Reviewing files that changed from the base of the PR and between 34c347e and e7ee841.

Files selected for processing: 2

  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.test.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/react-compiler-render-ownership-hazards.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.

@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: 1

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: f6285cc9-9126-404f-99b9-5d443b087de4
Commits

Reviewing files that changed from the base of the PR and between e7ee841 and af7c850.

Files selected for processing: 2

  • config/scripts/static-analysis/ratchets/react-compiler/check-mobile-react-compiler-hazard-ratchet.test.mjs
  • config/scripts/static-analysis/ratchets/react-compiler/react-compiler-render-ownership-hazards.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.

@AmoabaKelvin
AmoabaKelvin merged commit ed5c091 into main Nov 30, 2026
55 checks passed
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