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