Skip to content

Commit 4dee0fb

Browse files
test(mobile): reload before each route measurement
Opening the root link does not pop the stack, so the second and later runs only refocused the screen they meant to mount. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1ef7cd8 commit 4dee0fb

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎apps/mobile/scripts/measure-renders.mts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,24 @@ const measureStreamReply = Effect.fn("measure.streamReply")(function* (
249249
return { report, stillStreaming: streamingItem(after) !== undefined };
250250
}, Effect.scoped);
251251

252-
/** Opens a screen from Home and records its mount and data settling. */
252+
/** Opens a screen from a freshly loaded Home and records its mount and data settling. */
253253
const measureRouteOpen = Effect.fn("measure.routeOpen")(function* (
254254
options: Options,
255255
route: string,
256256
run: number,
257257
) {
258+
// A link to an already-open screen only refocuses it, so each run starts from a reload.
259+
yield* Effect.scoped(
260+
Effect.flatMap(connectInspector(options.metro), (evaluate) =>
261+
evaluate("__t3RenderCounterReload()"),
262+
),
263+
);
264+
yield* Effect.sleep("15 seconds");
258265
const evaluate = yield* connectInspector(options.metro);
259-
const open = (path: string) =>
260-
evaluate(
261-
`__t3RenderCounterOpen(${encodeJson(`${options.scheme}://${path.replace(/^\//, "")}`)})`,
262-
);
263-
// Each run mounts the screen fresh rather than refocusing the previous one.
264-
yield* open("");
265-
yield* Effect.sleep("3 seconds");
266266
yield* evaluate("__t3RenderCounterStart()");
267-
yield* open(route);
267+
yield* evaluate(
268+
`__t3RenderCounterOpen(${encodeJson(`${options.scheme}://${route.replace(/^\//, "")}`)})`,
269+
);
268270
yield* Effect.sleep(`${options.windowSeconds} seconds`);
269271
const report = yield* decodeReport(yield* evaluate("JSON.stringify(__t3RenderCounterStop())"));
270272
if (report.commits === 0)

‎apps/mobile/src/features/development/render-counter.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ Object.assign(globalThis, {
151151
void Linking.openURL(url);
152152
return true;
153153
},
154+
/** Restarts the JS app on Home; deferred so the inspector call can reply first. */
155+
__t3RenderCounterReload() {
156+
const { DevSettings } = require("react-native") as typeof import("react-native");
157+
setTimeout(() => DevSettings.reload(), 100);
158+
return true;
159+
},
154160
__t3RenderCounterStart() {
155161
state.commits = 0;
156162
state.counts = new Map();

‎docs/internals/mobile-development.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ node apps/mobile/scripts/measure-renders.mts --server <server-origin> --token <t
5858
--metro http://<metro-lan-host>:8081 --project-root <scratch-dir>
5959
```
6060

61-
`--route /settings/usage` instead opens that app path from Home and records a 6 s window over
61+
`--route /settings/usage` instead reloads the app, opens that path from Home and records a 6 s window over
6262
mount and data settling, with no provider turn and no `--server`, `--token` or `--project-root`.
6363

6464
Compare before and after on the same base, on the same device, with the median of three runs.

0 commit comments

Comments
 (0)