The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 00:30 UTC
fix(mobile): synchronize Expo network path updates (#22043)
Yash Singh committed
Oct 19, 2026 at 19:48 UTC
7c83530d1713e0a07a93c8415dedf54ff84b7721
6 files changed
+191
-3
apps/mobile/package.json
+2
-1
@@ -179,7 +179,8 @@
179
"react-native-screens",
180
"react-native-reanimated",
181
"@react-native-menu/menu",
182
- "expo-audio"
182
+ "expo-audio",
183
+ "expo-network"
184
]
185
}
186
},
apps/mobile/scripts/fixtures/NetworkModuleRegression.swift
new
+80
@@ -0,0 +1,80 @@
1
+import Foundation
2
+
3
+enum NWInterface {
4
+ enum InterfaceType {
5
+ case other, wifi, cellular, loopback, wiredEthernet
6
+ }
7
+}
8
+
9
+struct NWPath {
10
+ enum Status {
11
+ case satisfied, unsatisfied
12
+ }
13
+
14
+ // A reference inside the value models the native path's retained storage.
15
+ final class Storage {
16
+ let type: NWInterface.InterfaceType
17
+ init(_ type: NWInterface.InterfaceType) { self.type = type }
18
+ }
19
+
20
+ let status: Status
21
+ let storage: Storage
22
+
23
+ init(_ type: NWInterface.InterfaceType, status: Status = .satisfied) {
24
+ self.status = status
25
+ storage = Storage(type)
26
+ }
27
+
28
+ func usesInterfaceType(_ type: NWInterface.InterfaceType) -> Bool {
29
+ storage.type == type
30
+ }
31
+}
32
+
33
+final class NWPathMonitor {
34
+ static var scenario = "first"
35
+ static let deliveries = DispatchGroup()
36
+ var pathUpdateHandler: ((NWPath) -> Void)?
37
+
38
+ func start(queue: DispatchQueue) {
39
+ guard let handler = pathUpdateHandler else { fatalError("Missing path handler") }
40
+ if Self.scenario == "offline" {
41
+ handler(NWPath(.wifi, status: .unsatisfied))
42
+ } else if Self.scenario == "first" {
43
+ handler(NWPath(.wifi))
44
+ handler(NWPath(.cellular))
45
+ } else {
46
+ queue.async(group: Self.deliveries) {
47
+ handler(NWPath(.wifi))
48
+ DispatchQueue.concurrentPerform(iterations: 128) { index in
49
+ handler(NWPath(index.isMultiple(of: 2) ? .cellular : .wiredEthernet))
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ // Already queued callbacks can run after cancellation.
56
+ func cancel() {}
57
+}
58
+
59
+@main
60
+enum NetworkModuleRegression {
61
+ static func main() {
62
+ NWPathMonitor.scenario = CommandLine.arguments[1]
63
+ let module = NetworkModule()
64
+ if NWPathMonitor.scenario == "concurrent" {
65
+ DispatchQueue.concurrentPerform(iterations: 64) { _ in
66
+ let state = module.getNetworkStateAsync()
67
+ precondition(state["type"] as? String == "WIFI", "The first path must survive late callbacks")
68
+ precondition(state["isConnected"] as? Bool == true)
69
+ }
70
+ NWPathMonitor.deliveries.wait()
71
+ } else {
72
+ let state = module.getNetworkStateAsync()
73
+ let connected = NWPathMonitor.scenario != "offline"
74
+ precondition(state["type"] as? String == (connected ? "WIFI" : "NONE"))
75
+ precondition(state["isConnected"] as? Bool == connected)
76
+ precondition(state["isInternetReachable"] as? Bool == connected)
77
+ }
78
+ print("passed")
79
+ }
80
+}
apps/mobile/scripts/network-module.test.ts
new
+74
@@ -0,0 +1,74 @@
1
+// @effect-diagnostics nodeBuiltinImport:off - Compiles and runs the native dependency regression directly.
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 NodeURL from "node:url";
7
+import { afterAll, beforeAll, describe, expect, it } from "vite-plus/test";
8
+
9
+// oxlint-disable-next-line t3code/no-global-process-runtime -- This native integration test uses the host Swift compiler.
10
+describe.skipIf(NodeOS.platform() !== "darwin")("NetworkModule native path handoff", () => {
11
+ let directory: string;
12
+ let executable: string;
13
+
14
+ beforeAll(() => {
15
+ directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-network-test-"));
16
+ executable = NodePath.join(directory, "network-regression");
17
+ const source = NodeFS.readFileSync(
18
+ new URL("../node_modules/expo-network/ios/NetworkModule.swift", import.meta.url),
19
+ "utf8",
20
+ );
21
+ // Compile the dependency's query and conversion methods, replacing only
22
+ // NWPathMonitor so we can deliver updates during and after cancellation.
23
+ const start = source.indexOf(" private func getNetworkPathAsync()");
24
+ if (start === -1) throw new Error("NetworkModule query implementation not found");
25
+ const methods = source
26
+ .slice(start, source.lastIndexOf("\n}"))
27
+ .replace("private func getNetworkStateAsync", "func getNetworkStateAsync");
28
+ const module = NodePath.join(directory, "NetworkModule.swift");
29
+ NodeFS.writeFileSync(
30
+ module,
31
+ `import Foundation\nfinal class NetworkModule {\n private let monitorQueue = DispatchQueue.global(qos: .default)\n${methods}\n}\n`,
32
+ );
33
+ const types = NodePath.join(directory, "NetworkType.swift");
34
+ NodeFS.writeFileSync(
35
+ types,
36
+ NodeFS.readFileSync(
37
+ new URL("../node_modules/expo-network/ios/NetworkType.swift", import.meta.url),
38
+ "utf8",
39
+ ).replace(/^import Network\n/m, ""),
40
+ );
41
+ NodeChildProcess.execFileSync(
42
+ "swiftc",
43
+ [
44
+ "-swift-version",
45
+ "5",
46
+ "-sanitize=thread",
47
+ module,
48
+ types,
49
+ NodeURL.fileURLToPath(new URL("./fixtures/NetworkModuleRegression.swift", import.meta.url)),
50
+ "-o",
51
+ executable,
52
+ ],
53
+ { timeout: 30_000, encoding: "utf8" },
54
+ );
55
+ });
56
+
57
+ afterAll(() => {
58
+ if (directory) NodeFS.rmSync(directory, { recursive: true, force: true });
59
+ });
60
+
61
+ it.each([
62
+ ["first", "keeps the first path when several updates arrive before the query resumes"],
63
+ ["offline", "reports a disconnected path"],
64
+ ["concurrent", "reads paths during overlapping queries and late callbacks without data races"],
65
+ ])("%s: %s", (name) => {
66
+ expect(
67
+ NodeChildProcess.execFileSync(executable, [name], {
68
+ encoding: "utf8",
69
+ timeout: 15_000,
70
+ env: { ...process.env, TSAN_OPTIONS: "halt_on_error=1" },
71
+ }).trim(),
72
+ ).toBe("passed");
73
+ });
74
+});
patches/expo-network@58.0.3.patch
new
+31
@@ -0,0 +1,31 @@
1
+diff --git a/ios/NetworkModule.swift b/ios/NetworkModule.swift
2
+--- a/ios/NetworkModule.swift
3
++++ b/ios/NetworkModule.swift
4
+@@ -93,10 +93,18 @@
5
+ // since we want to wait for the result to be updated once:
6
+ let tempMonitor = NWPathMonitor()
7
+ var tempPath: NWPath?
8
++ let pathLock = NSLock()
9
+
10
+ let semaphore = DispatchSemaphore(value: 0)
11
+
12
+ tempMonitor.pathUpdateHandler = { updatedPath in
13
++ // Cancellation does not drain queued updates. Publish only the first path
14
++ // and synchronize its retain with the caller reading it on another queue.
15
++ pathLock.lock()
16
++ defer { pathLock.unlock() }
17
++ guard tempPath == nil else {
18
++ return
19
++ }
20
+ tempPath = updatedPath
21
+ semaphore.signal() // Notify that we got the path
22
+ }
23
+@@ -114,6 +122,8 @@
24
+ return nil
25
+ }
26
+
27
++ pathLock.lock()
28
++ defer { pathLock.unlock() }
29
+ return tempPath
30
+ }
31
+
pnpm-lock.yaml
+3
-2
@@ -177,6 +177,7 @@ patchedDependencies:
177
alchemy@2.0.0-beta.80: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd
178
dbus-next@0.10.2: cfff57561b0ee59b5addb3b2e6c6f20906e967507a530ab67e8db8108e520ba4
179
expo-audio@58.0.9: 2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add
180
+ expo-network@58.0.3: cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237
181
expo-sharing@58.0.19: ad248759641ddd71b8331c09dbb3b18c8a551785f2df507533805babd3c0c124
182
expo-widgets@58.0.20: 8623cb034b720c5ef2da8012c765805a7298909bd92eaf8381f64dbde41b77dd
183
mdast-util-math@3.0.0: afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c
@@ -508,7 +509,7 @@ importers:
509
version: 58.0.13(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))(react@19.3.0)(typescript@7.0.2)
510
expo-network:
511
specifier: ~58.0.3
511
- version: 58.0.3(expo@58.0.14)(react@19.3.0)
512
+ version: 58.0.3(patch_hash=cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237)(expo@58.0.14)(react@19.3.0)
513
expo-notifications:
514
specifier: ~58.1.5
515
version: 58.1.5(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))(react@19.3.0)(typescript@7.0.2)
@@ -19775,7 +19776,7 @@ snapshots:
19776
'@expo/modules-macros-win32-arm64': 0.20.0
19777
'@expo/modules-macros-win32-x64': 0.20.0
19778
19778
- expo-network@58.0.3(expo@58.0.14)(react@19.3.0):
19779
+ expo-network@58.0.3(patch_hash=cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237)(expo@58.0.14)(react@19.3.0):
19780
dependencies:
19781
expo: 58.0.14(1106b1d11fc0fad6d0556b6a93329d99)
19782
react: 19.3.0
pnpm-workspace.yaml
+1
@@ -322,6 +322,7 @@ patchedDependencies:
322
micromark-extension-gfm-table@2.1.1: patches/micromark-extension-gfm-table@2.1.1.patch
323
alchemy@2.0.0-beta.80: patches/alchemy@2.0.0-beta.80.patch
324
expo-audio@58.0.9: patches/expo-audio@58.0.9.patch
325
+ expo-network@58.0.3: patches/expo-network@58.0.3.patch
326
"@clerk/expo-native-components@0.2.0": patches/@clerk__expo-native-components@0.2.0.patch
327
"@effect/vitest@4.0.5": patches/@effect__vitest@4.0.5.patch
328
"@expo/metro-config@58.0.14": patches/@expo__metro-config@58.0.14.patch