Skip to content

feat(mobile): build mobile and mobile-web with React Compiler - #50713

Merged
nwparker merged 4 commits into
mainfrom
nwparker/mobile-color
Nov 27, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/mobile-color

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

React Compiler makes the phone app skip re-rendering things whose inputs haven't changed. The app used to keep its colors and language in shared global objects and force screens to redraw when those changed. The compiler can't see those globals, so turning it on would have left screens stuck on the old theme or language. Now every screen gets its colors, styles and text from hooks the compiler can see, and the compiler is on for both the native app and mobile-web.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 916 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8369 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1853

What Changed

  • Theme: the live, mutated-in-place colors object is removed.

    • Components read useMobileColors() and useThemedStyles(sheet).
    • themedStyleSheet((colors, scheme) => …) now returns a per-scheme handle, { resolve(scheme) }, instead of a getter object.
    • Code outside render (handlers, effects, native calls) uses getMobilePalette() or sheet.resolve(getMobileColorScheme()).
    • The ~1,000 bare useMobileColorScheme() calls that only forced re-renders are gone.
  • Language:

    • Helpers that run during render (labels, formatters, option lists, getter-based copy) now take t, locale or colors from hooks instead of calling module-level translate() or getUiIntlLocale().
    • useMobileTranslation() now builds t from a module function keyed on the language revision. The old useMemo(() => …, [revision]) never read revision, so once compiled it kept one identity and live language switching broke. The compiled build on the simulator caught this.
  • Compiler hazards: useMemo/useCallback deps that the callback never reads (invalidation keys such as tick, revision, keyHash) now go through recomputeOn([dep], …) from mobile/src/hooks/recompute-on.ts, mirroring desktop. A few cases that keep a value per key use a new useKeptByKey.

  • Compiler on:

    • Native: app.json sets experiments.reactCompiler: true. Metro now resolves react (for react/compiler-runtime) from shared src/shared files to mobile's React; Expo compiles those files too.
    • mobile-web: a new esbuild plugin (mobile-web-react-compiler-plugin.mjs) compiles mobile/{app,src,web-entry} with oxc-transform-react. It uses the same compiler as the desktop compat ratchet, and ORCA_REACT_COMPILER=0 opts out.
  • Guard: new pnpm check:mobile-react-compiler-hazard-ratchet, auto-run by the ratchet runner and check:changed, with baseline 0. It fails on:

    • render-path reads of translate, getMobileUiLocale, getMobileColorScheme and getMobilePalette, followed transitively through module helpers across files
    • object getters that call translate
    • unread memo deps
    • desktop's source hazards, such as discarded useSyncExternalStore

    Removing the colors export and the getter sheets also makes typecheck reject the old patterns.

  • Smaller changes: a few files were split to stay under max-lines. The page-style constants moved out of build-mobile-web-app-bundle.mjs. The pre-existing use-open-bot-home.ts implicit-any errors are fixed.

Why

This is the alternative to keeping mobile off the compiler forever. Hook-returned values are the only inputs the compiler keys on, so theme and language have to come in as hook values. A remount key on the root was rejected: it would wipe navigation and input state on every theme or language switch.

Linked Issue

N/A (maintainer)

Visual Proof

iOS simulator, compiled dev-client build (compiler on). The Feed stayed mounted while I switched theme and language in Settings.

Before switching (light, English) Dark applied live Back on the still-mounted Feed after Light + Español
(screenshot removed: contained real product data) (screenshot removed: contained real product data) (screenshot removed: contained real product data)

Testing

  • I manually tested these changes locally: iOS simulator dev client, compiled. Switching Dark/Light and English/Español repaints the open screen and the mounted screens underneath. With the compiler disabled, the same flow was used to confirm the useMobileTranslation bug and its fix.
  • Automated tests added/updated, or explained why not below: one existing mock updated. The new ratchet is the regression guard; no UI tests per repo rules.
  • Every added test fails without this change and avoids the test anti-patterns (no new tests).
  • Checks run:
    • pnpm check:changed: all 55 pass.
    • mobile typecheck and check:tests-typecheck: clean.
    • mobile vitest: 59/59 pass.
    • pnpm build:mobile-web builds and verifies.
    • npx expo export --platform ios bundles: one React copy and 772 compiled memo caches.
    • Running the compiler over all 3,063 mobile files: 0 fatal errors. Functions it bails on stay uncompiled, which is safe.

Performance

  • Native: compiled components skip re-renders whose inputs are unchanged, and the ~1,000 forced whole-tree re-renders on scheme or language change are gone.
  • mobile-web: the eager bundle grows from 11,530,494 to about 12.65 MB because of the compiler's memo caches. The budget is raised by 1 MiB, with a dated note in verify-mobile-web-app-bundle.mjs. Building mobile-web with ORCA_REACT_COMPILER=0 avoids the growth if we'd rather not ship it there.

Risk

Level: Medium–High. The PR touches about 930 mobile files, mostly mechanically through a codemod plus per-directory hand fixes.

  • Riskiest part: a render-time read of theme or language that no guard catches would show stale colors or strings after a switch until the next remount. Navigation titles, key labels, option lists and diff/PR labels were all converted. Data is unaffected.
  • Fingerprint: the native fingerprint changes because of the app.json experiment, so dev clients need one rebuild. Release builds pick it up normally.
  • Shared rewind factory: src/shared createAgentSessionRewindHook still takes a module say function, so its disabled-reason text can lag a language switch until the next state change. That is the same trade-off desktop already ships.
  • Back out: a plain revert. For a narrower rollback, set experiments.reactCompiler: false and drop the esbuild plugin; the hook-based theme and i18n code is correct with or without the compiler.

AI Disclosure

Written with Claude Code (Opus 5.5), using a ts-morph codemod plus parallel sub-agents per directory. I reviewed the changes and verified them on the simulator.

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.

Checklist

  • This PR is small and focused: it's a large mechanical migration, but one concern.
  • I explained what changed and why
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered: mobile-only. Native iOS was verified; Android uses the same JS and Metro path; mobile-web build verified.
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (via check:changed + build:mobile-web)

@nwparker
nwparker force-pushed the nwparker/mobile-color branch 2 times, most recently from ff089e0 to d3d4591 Compare November 27, 2026 10:56
Render code no longer reads theme or language from module state, so
compiled memos keep dark/light and live language switches working.

- colors/styles: the live `colors` object is gone; components read
  useMobileColors() and useThemedStyles(sheet). themedStyleSheet now
  returns a per-scheme handle; non-render code uses getMobilePalette().
- i18n: helpers that run during render take `t`/locale from hooks;
  useMobileTranslation's identity now follows the language revision
  under the compiler (a useMemo dep it never read was dropped).
- memo deps the callback never reads now go through recomputeOn().
- New ratchet check:mobile-react-compiler-hazard-ratchet (baseline 0)
  guards render-path theme/language reads, translate getters, unread
  memo deps and discarded subscriptions.
- Native: app.json experiments.reactCompiler; Metro resolves
  react/compiler-runtime for compiled shared files to mobile's React.
- mobile-web: esbuild plugin compiles mobile sources with
  oxc-transform-react; eager bundle budget +1 MiB for memo caches.
@nwparker
nwparker force-pushed the nwparker/mobile-color branch from d3d4591 to 0fbafef Compare November 27, 2026 11:22
@nwparker
nwparker merged commit 7bf178e into main Nov 27, 2026
68 checks passed
AmoabaKelvin added a commit that referenced this pull request Nov 28, 2026
…ompiler build (#51418)

* fix(mobile): stop the Tasks page crashing when it re-renders

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.

* fix(ratchets): count arrow components and destructured props in the compiler hazard rules

* fix(ratchets): don't count writes to a rest-props object as mutating props
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