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 22, 12:00 UTC
fix(mobile): share pull request refresh subscriptions (#23464)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com>
Victor Vogel committed
Oct 30, 2026 at 15:50 UTC
8bbe5aa384ed40f1582c06b010ff649e7bec2107
2 files changed
+69
-1
packages/client-runtime/src/state/pullRequests.test.ts
+53
@@ -1177,6 +1177,59 @@ it.effect("keeps hover previews fresh after edits and turns", () =>
1177
),
1178
);
1179
1180
+it.effect("shares one refresh stream between independently created pull request readers", () =>
1181
+ Effect.scoped(
1182
+ Effect.gen(function* () {
1183
+ const revision = yield* SubscriptionRef.make(0);
1184
+ let subscriptions = 0;
1185
+ let title = "Original title";
1186
+ const client = {
1187
+ [WS_METHODS.pullRequestsSubscribeRefreshes]: () =>
1188
+ Stream.unwrap(
1189
+ Effect.sync(() => {
1190
+ subscriptions++;
1191
+ return SubscriptionRef.changes(revision);
1192
+ }),
1193
+ ),
1194
+ [WS_METHODS.pullRequestsSummary]: () => Effect.sync(() => ({ title, state: "open" })),
1195
+ [WS_METHODS.pullRequestsDetail]: () => Effect.sync(() => ({ title, state: "open" })),
1196
+ } as unknown as WsRpcProtocolClient;
1197
+ const { runtime, atoms, registry } = yield* makeTestRuntime(client);
1198
+ const target = {
1199
+ environmentId: TARGET.environmentId,
1200
+ input: { projectId: ProjectId.make("project-1"), repository: "acme/web", number: 1 },
1201
+ };
1202
+ const summary = createLinkedPullRequestSummaryAtomFamily(runtime)(target);
1203
+ const detail = atoms.detail(target);
1204
+ for (const atom of [summary, detail]) {
1205
+ const unmount = registry.mount(atom);
1206
+ yield* Effect.addFinalizer(() => Effect.sync(unmount));
1207
+ expect((yield* AtomRegistry.getResult(registry, atom)).title).toBe(title);
1208
+ }
1209
+ yield* AtomRegistry.getResult(
1210
+ registry,
1211
+ atoms.refreshes({ environmentId: target.environmentId, input: {} }),
1212
+ );
1213
+ expect(subscriptions).toBe(1);
1214
+
1215
+ const changed = [summary, detail].map((atom) => {
1216
+ const ready = Latch.makeUnsafe();
1217
+ const stop = registry.subscribe(atom, (result) => {
1218
+ if (AsyncResult.isSuccess(result) && result.value.title === "Updated title") {
1219
+ ready.openUnsafe();
1220
+ }
1221
+ });
1222
+ return { ready, stop };
1223
+ });
1224
+ yield* Effect.addFinalizer(() => Effect.sync(() => changed.forEach(({ stop }) => stop())));
1225
+ title = "Updated title";
1226
+ yield* SubscriptionRef.update(revision, (value) => value + 1);
1227
+ for (const { ready } of changed) yield* ready.await;
1228
+ expect(subscriptions).toBe(1);
1229
+ }),
1230
+ ),
1231
+);
1232
+
1233
it.effect("shares close, reopen, and merge with an untouched client's mounted PR readers", () =>
1234
Effect.scoped(
1235
Effect.gen(function* () {
packages/client-runtime/src/state/pullRequests.ts
+16
-1
@@ -115,7 +115,7 @@ function updateCached<A, E>(
115
registry.update(atom, AsyncResult.map(update));
116
}
117
118
-function createPullRequestRefreshAtomFamily<R, E>(
118
+function makePullRequestRefreshAtomFamily<R, E>(
119
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
120
) {
121
return createEnvironmentRpcSubscriptionAtomFamily(runtime, {
@@ -124,6 +124,21 @@ function createPullRequestRefreshAtomFamily<R, E>(
124
});
125
}
126
127
+const refreshFamiliesByRuntime = new WeakMap<
128
+ object,
129
+ ReturnType<typeof makePullRequestRefreshAtomFamily>
130
+>();
131
+
132
+function createPullRequestRefreshAtomFamily<R, E>(
133
+ runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
134
+): ReturnType<typeof makePullRequestRefreshAtomFamily<R, E>> {
135
+ const existing = refreshFamiliesByRuntime.get(runtime);
136
+ if (existing) return existing as ReturnType<typeof makePullRequestRefreshAtomFamily<R, E>>;
137
+ const refreshes = makePullRequestRefreshAtomFamily(runtime);
138
+ refreshFamiliesByRuntime.set(runtime, refreshes);
139
+ return refreshes;
140
+}
141
+
142
export function createLinkedPullRequestSummaryAtomFamily<R, E>(
143
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
144
refreshes = createPullRequestRefreshAtomFamily(runtime),