The best way to control Claude Code, Codex and more from any computer or phone
| 1 | # Mobile development lifecycle |
| 2 | |
| 3 | The [connection runtime's HMR boundary](../../apps/mobile/src/lib/hot-swappable-atom-runtime.ts) |
| 4 | keeps a stable atom runtime and replaces its Effect layer through a writable atom. |
| 5 | It accepts the update only after installing the new layer. Otherwise importers |
| 6 | retain the old behavior even though Metro reports a successful refresh. |
| 7 | |
| 8 | Do not reset the shared atom registry to refresh a connection-runtime edit. Reset |
| 9 | removes listeners from mounted consumers that Metro has no reason to rerender. |
| 10 | When the registry or managed-runtime module itself changes, normal Metro propagation |
| 11 | disposes its old resources. This boundary does not make arbitrary module-level atom |
| 12 | families safe to hot-swap. Production uses an ordinary atom runtime. |
| 13 | |
| 14 | [Environment supervisor scopes](../../packages/client-runtime/src/connection/registry.ts) |
| 15 | are children of the registry scope. The per-environment map supports targeted |
| 16 | shutdown, but a supervisor created after its cleanup runs would escape it. A closed |
| 17 | parent scope also closes late arrivals, preventing interrupted startup or runtime |
| 18 | replacement from leaving a WebSocket alive outside the new registry. |
| 19 | |
| 20 | Uniwind compiles CSS on Metro updates so newly used classes are discovered. It |
| 21 | skips global style invalidation only when the generated stylesheet and theme list |
| 22 | are unchanged. Skipping compilation would lose new classes; invalidating every |
| 23 | consumer for unchanged output makes an ordinary component edit refresh the whole |
| 24 | app. The fingerprint is recorded only after initialization succeeds. |
| 25 | |
| 26 | The native modules under `apps/mobile/modules/` are `file:` dependencies, and pnpm |
| 27 | copies those into its virtual store instead of linking them. Metro bundles the copy, |
| 28 | so an edit to a module's TypeScript is invisible to a running dev client until |
| 29 | `vp i` re-syncs it, while Gradle and CocoaPods compile the worktree directory |
| 30 | directly. A JavaScript change that "has no effect" on device is usually this. |
| 31 | |
| 32 | ## Measuring renders |
| 33 | |
| 34 | [`render-counter.ts`](../../apps/mobile/src/features/development/render-counter.ts) counts the |
| 35 | components React rendered in each commit and why: a changed state slot, changed props, or |
| 36 | context. It wraps the DevTools hook from the first import in `index.ts` and loads only when |
| 37 | `__DEV__` and `EXPO_PUBLIC_T3_RENDER_COUNTER=1`, so release bundles never contain it. The walk |
| 38 | skips subtrees React bailed out of. A probe that checks `flags & 1` on every fiber reports |
| 39 | renders that never happened, because bailed-out fibers keep flags from older commits. |
| 40 | |
| 41 | [`measure-renders.mts`](../../apps/mobile/scripts/measure-renders.mts) drives a measurement from |
| 42 | outside the app. It evaluates the counter's globals through Metro's Hermes inspector proxy, which |
| 43 | works the same for iOS simulators and Android emulators and needs no taps, `simctl`, or `adb`. It |
| 44 | starts a real provider turn through the server, opens the thread with an app link, records a window |
| 45 | mid-stream, and prints the median renders, commits, top components and top causes. Expo drops inspector sockets whose `Origin` is not the URL Metro advertises, so |
| 46 | pass that URL (the LAN address with `--lan`) as `--metro`. |
| 47 | |
| 48 | ```bash |
| 49 | EXPO_PUBLIC_T3_RENDER_COUNTER=1 vp run dev:client # in apps/mobile, then pair the app |
| 50 | node apps/server/src/bin.ts auth session issue --base-dir <base-dir> --token-only |
| 51 | node apps/mobile/scripts/measure-renders.mts --server <server-origin> --token <token> \ |
| 52 | --metro http://<metro-lan-host>:8081 --project-root <scratch-dir> |
| 53 | ``` |
| 54 | |
| 55 | `--route /settings/usage` instead reloads the app, opens that path from Home and records a 6 s window over |
| 56 | mount and data settling, with no provider turn and no `--server`, `--token` or `--project-root`. |
| 57 | With `--server` as well, the app reloads, opens that path (`/` stays on Home) and the reply streams in a |
| 58 | new thread the app never shows, which measures what streaming elsewhere costs the screen in front. |
| 59 | |
| 60 | Compare before and after on the same base, on the same device, with the median of three runs. |
| 61 | Provider output varies run to run, so a single run or a comparison across bases is noise. |
| 62 | |
| 63 | ## React Compiler |
| 64 | |
| 65 | Metro runs the compiler only because `experiments.reactCompiler` is set in `app.config.ts`. Expo |
| 66 | then passes `supportsReactCompiler` to `babel-preset-expo`, which owns the plugin options; there is |
| 67 | no `babel.config.js` entry to look for. Release bundles use `panicThreshold: "NONE"`, so a function |
| 68 | the compiler can't prove safe ships unmemoized with no build error. |
| 69 | [`reactCompilerCoverage.test.ts`](../../apps/mobile/src/reactCompilerCoverage.test.ts) runs the |
| 70 | same preset over every source file. It fails on a new bailout, and on a file in `KNOWN_BAILOUTS` |
| 71 | that now compiles, so the list only shrinks. When you fix a listed file, delete its entry and its |
| 72 | manual `useMemo`/`useCallback`/`memo` in the same change. Most mobile bailouts are `try` without |
| 73 | `catch` or with `finally`, and refs read during render; see [Web UI](web-ui.md#react-compiler) |
| 74 | for the usual rewrites. Mobile runs `t3code/no-manual-memo` with `allowMemoHooks`, so memo |
| 75 | directives are errors but the hooks stay legal until `KNOWN_BAILOUTS` is empty. |
| 76 | `t3code/no-hookless-use-function` rejects a `use*` function that calls no hook, since the compiler |
| 77 | leaves it uncached. A platform stub of a real hook, such as an `.android.ts` file, keeps the hook |
| 78 | name and suppresses the rule with a reason. |