Skip to content

Commit 414b226

Browse files
test(mobile): run React hooks through the release compiler
1 parent bd728da commit 414b226

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

‎apps/mobile/src/features/pull-requests/guide/useReviewGuide.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
22
import { useFocusEffect } from "@react-navigation/native";
33
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
44
import { AsyncResult } from "effect/reactivity";
5-
import { useCallback, useRef, useState } from "react";
5+
import { useRef, useState } from "react";
66
import { usePullRequestConnected } from "../usePullRequestConnected";
77
import { composerPullRequests } from "../../../state/pull-requests";
88
import { useEnvironmentQuery } from "../../../state/query";
@@ -34,15 +34,13 @@ export function useReviewGuide(params: PullRequestParams) {
3434
const pending = useRef(false);
3535
const running = starting || query.data?.run?._tag === "Running";
3636
const refresh = query.refresh;
37-
useFocusEffect(
38-
useCallback(() => {
39-
if (!enabled) return;
40-
refresh();
41-
if (!running) return;
42-
const timer = setInterval(refresh, 5_000);
43-
return () => clearInterval(timer);
44-
}, [enabled, refresh, running]),
45-
);
37+
useFocusEffect(() => {
38+
if (!enabled) return;
39+
refresh();
40+
if (!running) return;
41+
const timer = setInterval(refresh, 5_000);
42+
return () => clearInterval(timer);
43+
});
4644
const write = async () => {
4745
if (!enabled || !canWrite || running || pending.current) return;
4846
pending.current = true;

‎apps/mobile/vite.config.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as NodeModule from "node:module";
12
import { defineConfig } from "vite-plus";
23
import "vite-plus/test/config";
34

@@ -18,6 +19,15 @@ const reactTests = [
1819
"src/state/use-selected-thread-git-actions.test.tsx",
1920
];
2021

22+
const require = NodeModule.createRequire(import.meta.url);
23+
const babel: {
24+
transformAsync: (
25+
code: string,
26+
options: Record<string, unknown>,
27+
) => Promise<{ code?: string | null; map?: object | null } | null>;
28+
} = require("@babel/core");
29+
const babelConfig = require("./babel.config.js")({ cache: () => {} });
30+
2131
export default defineConfig({
2232
test: {
2333
hookTimeout: 60_000,
@@ -37,6 +47,44 @@ export default defineConfig({
3747
},
3848
{
3949
extends: true,
50+
plugins: [
51+
{
52+
name: "mobile-release-react-compiler",
53+
enforce: "pre",
54+
async transform(code, id) {
55+
if (
56+
!id.startsWith(new URL("./src/", import.meta.url).pathname) ||
57+
!/\.tsx?$/.test(id) ||
58+
/\.test\.tsx?$/.test(id)
59+
) {
60+
return;
61+
}
62+
const result = await babel.transformAsync(code, {
63+
...babelConfig,
64+
presets: babelConfig.presets.map(([name, options]: [string, object]) => [
65+
require.resolve(name),
66+
// Vite runs in Node; inline Babel helpers instead of Metro runtime imports.
67+
{ ...options, enableBabelRuntime: false },
68+
]),
69+
filename: id,
70+
babelrc: false,
71+
configFile: false,
72+
sourceMaps: true,
73+
caller: {
74+
name: "metro",
75+
bundler: "metro",
76+
platform: "ios",
77+
isDev: false,
78+
isServer: false,
79+
isNodeModule: false,
80+
supportsStaticESM: true,
81+
supportsReactCompiler: true,
82+
},
83+
});
84+
if (result?.code) return { code: result.code, map: result.map };
85+
},
86+
},
87+
],
4088
test: {
4189
name: "react",
4290
include: reactTests,

0 commit comments

Comments
 (0)