Skip to content

Commit 89d98e0

Browse files
fix(mobile): restore Expo 58 widget runtime startup
1 parent 99e0852 commit 89d98e0

3 files changed

Lines changed: 125 additions & 4 deletions

File tree

‎patches/[email protected]‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ index c9f4dfe..dc0792e 100644
1313
/**
1414
* Whether the activity is displayed in a context with reduced luminance.
1515
* @platform iOS 16+
16+
diff --git a/bundle/react-stub.ts b/bundle/react-stub.ts
17+
--- a/bundle/react-stub.ts
18+
+++ b/bundle/react-stub.ts
19+
@@ -3 +3,5 @@
20+
export const Fragment = 'react.fragment';
21+
+
22+
+// Widget layouts are evaluated once per render without a React reconciler.
23+
+// Keep memoized @expo/ui components callable by the widget tree normalizer.
24+
+export const memo = <T>(component: T): T => component;
1625
diff --git a/ios/Widgets/Utils.swift b/ios/Widgets/Utils.swift
1726
index 76b2199..6cb52c3 100644
1827
--- a/ios/Widgets/Utils.swift

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// @effect-diagnostics nodeBuiltinImport:off - Executes the actual native extension bundle in an isolated VM.
2+
import * as NodeChildProcess from "node:child_process";
3+
import * as NodeFS from "node:fs";
4+
import * as NodeOS from "node:os";
5+
import * as NodePath from "node:path";
6+
import * as NodeVM from "node:vm";
7+
import { afterAll, beforeAll, expect, it } from "vite-plus/test";
8+
9+
const mobileRoot = new URL("../apps/mobile/", import.meta.url).pathname;
10+
const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-widget-runtime-"));
11+
const context = NodeVM.createContext({ console });
12+
const now = Date.parse("2026-10-01T12:00:00Z");
13+
NodeVM.runInContext(`Date.now = () => ${now}`, context);
14+
15+
beforeAll(() => {
16+
const bundle = NodePath.join(directory, "ExpoWidgets.bundle");
17+
NodeChildProcess.execFileSync(
18+
process.execPath,
19+
["node_modules/expo-widgets/scripts/build-bundle.mjs", ".", "ios", bundle],
20+
{
21+
cwd: mobileRoot,
22+
stdio: "pipe",
23+
},
24+
);
25+
// Execute the real extension runtime, including Expo UI and Expo's React stub.
26+
// Mocked layout tests cannot catch failures while this bundle initializes.
27+
NodeVM.runInContext(NodeFS.readFileSync(bundle, "utf8"), context);
28+
}, 120_000);
29+
30+
afterAll(() => NodeFS.rmSync(directory, { recursive: true, force: true }));
31+
32+
function render(name: string, props: unknown, environment: object) {
33+
const layout = NodeChildProcess.execFileSync(
34+
process.execPath,
35+
[
36+
"--input-type=commonjs",
37+
"-e",
38+
`
39+
const { createRequire } = require('node:module');
40+
const vm = require('node:vm');
41+
const requireMobile = createRequire(process.cwd() + '/package.json');
42+
const babel = requireMobile(requireMobile.resolve('@babel/core', {
43+
paths: [requireMobile.resolve('babel-preset-expo')]
44+
}));
45+
const result = babel.transformFileSync('src/widgets/${name}.tsx', {
46+
caller: { name: 'metro', platform: 'ios', supportsStaticESM: false, isDev: false }
47+
});
48+
const capture = (_, layout) => process.stdout.write(layout);
49+
vm.runInNewContext(result.code, {
50+
exports: {},
51+
require: name => name === 'expo-widgets'
52+
? { createWidget: capture, createLiveActivity: capture } : {}
53+
});
54+
`,
55+
],
56+
{ cwd: mobileRoot, encoding: "utf8" },
57+
);
58+
NodeVM.runInContext(`globalThis.__expoWidgetLayout = (${layout})`, context);
59+
return NodeVM.runInContext(
60+
`JSON.stringify(__expoWidgetRender(${JSON.stringify(props)}, ${JSON.stringify(environment)}))`,
61+
context,
62+
) as string;
63+
}
64+
65+
it("renders the Live Activity banner and Dynamic Island with the bundled runtime", () => {
66+
const result = JSON.parse(
67+
render(
68+
"AgentActivity",
69+
{
70+
title: "T3 Code",
71+
subtitle: "Agent work in progress",
72+
activeCount: 1,
73+
activities: [
74+
{
75+
phase: "running",
76+
threadTitle: "Audit widgets",
77+
projectTitle: "T3",
78+
status: "Working",
79+
deepLink: "/threads/test",
80+
},
81+
],
82+
},
83+
{ colorScheme: "dark", isStale: false, timestamp: now },
84+
),
85+
);
86+
expect(JSON.stringify(result.banner)).toContain("Audit widgets");
87+
expect(JSON.stringify(result.compactLeading)).toContain("ImageView");
88+
expect(JSON.stringify(result.compactTrailing)).toContain("1");
89+
});
90+
91+
it.each(["systemSmall", "systemMedium", "systemLarge", "accessoryRectangular"])(
92+
"renders fresh usage and its expired state in %s",
93+
(widgetFamily) => {
94+
const props = {
95+
checkedAt: now,
96+
providers: [
97+
{
98+
name: "Codex",
99+
detail: "Subscription remaining",
100+
windows: [{ remaining: 70, label: "Session", kind: "session", reset: "Resets soon" }],
101+
expiresAt: now + 60_000,
102+
totalWindows: 1,
103+
},
104+
],
105+
};
106+
const environment = { widgetFamily, colorScheme: "dark", widgetRenderingMode: "fullColor" };
107+
expect(render("SubscriptionUsage", props, { ...environment, timestamp: now })).toContain("70");
108+
expect(
109+
render("SubscriptionUsage", props, { ...environment, timestamp: now + 60_001 }),
110+
).toContain("Open T3 to refresh");
111+
},
112+
);

0 commit comments

Comments
 (0)