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, 05:45 UTC
fix(server): streamed Browser clicks no longer wait behind queued wheel bursts (#28236)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 2, 2026 at 18:30 UTC
f80be8e0374d75dc74f0e4c5011d93a6e2e170f8
4 files changed
+95
-29
apps/server/src/preview/ServerBrowser.test.ts
+39
-2
@@ -1083,6 +1083,26 @@ it.effect.each([
1083
{ type: "mouseReleased", x: 119 },
1084
],
1085
},
1086
+ {
1087
+ name: "wheel burst before a click",
1088
+ inputs: [
1089
+ ...Array.from({ length: 120 }, () => ({
1090
+ type: "wheel",
1091
+ x: 100,
1092
+ y: 200,
1093
+ deltaX: 0,
1094
+ deltaY: 12,
1095
+ })),
1096
+ { type: "mouse", action: "down", x: 100, buttons: 1, button: "left" },
1097
+ { type: "mouse", action: "up", x: 100, buttons: 0, button: "left" },
1098
+ ],
1099
+ expected: [
1100
+ { type: "mouseMoved", x: -1 },
1101
+ { type: "mouseWheel", x: 100, y: 200, deltaX: 0, deltaY: 1440 },
1102
+ { type: "mousePressed", x: 100 },
1103
+ { type: "mouseReleased", x: 100 },
1104
+ ],
1105
+ },
1106
{
1107
name: "modifier changes and drag points",
1108
inputs: [
@@ -1117,13 +1137,30 @@ it.effect.each([
1137
expected: [
1138
{ type: "mouseMoved", x: -1 },
1139
{ type: "mouseMoved", x: 1 },
1120
- { type: "mouseWheel", deltaY: 20 },
1121
- { type: "mouseWheel", deltaY: 30 },
1140
+ { type: "mouseWheel", deltaY: 50 },
1141
{ type: "mouseMoved", x: 2 },
1142
{ type: "keyDown", key: "a" },
1143
{ type: "mouseMoved", x: 3 },
1144
],
1145
},
1146
+ {
1147
+ name: "wheel position, modifier and direction boundaries",
1148
+ inputs: [
1149
+ { type: "wheel", x: 1, deltaX: 5, deltaY: 10 },
1150
+ { type: "wheel", x: 1, deltaX: 5, deltaY: 10 },
1151
+ { type: "wheel", x: 2, deltaY: 10 },
1152
+ { type: "wheel", x: 2, deltaY: 10, modifiers: 2 },
1153
+ { type: "wheel", x: 2, deltaY: -10, modifiers: 2 },
1154
+ { type: "wheel", x: 2, deltaY: -10, modifiers: 2 },
1155
+ ],
1156
+ expected: [
1157
+ { type: "mouseMoved", x: -1 },
1158
+ { type: "mouseWheel", x: 1, deltaX: 10, deltaY: 20, modifiers: 0 },
1159
+ { type: "mouseWheel", x: 2, deltaX: 0, deltaY: 10, modifiers: 0 },
1160
+ { type: "mouseWheel", x: 2, deltaY: 10, modifiers: 2 },
1161
+ { type: "mouseWheel", x: 2, deltaY: -20, modifiers: 2 },
1162
+ ],
1163
+ },
1164
{
1165
name: "text, navigation and resize boundaries",
1166
inputs: [
apps/server/src/preview/ServerBrowser.ts
+22
-3
@@ -2639,16 +2639,35 @@ const make = Effect.gen(function* () {
2639
: {}),
2640
});
2641
} else {
2642
- const dispatch = () => dispatchViewerInput(tab, session, viewer, message);
2642
+ const dispatch = (input: Record<string, unknown>) =>
2643
+ dispatchViewerInput(tab, session, viewer, input);
2644
if (
2645
message.type === "mouse" &&
2646
message.action === "move" &&
2647
message.button === "none" &&
2648
message.buttons === 0
2649
) {
2649
- await tab.control.humanLatest(viewer.id, `hover:${modifiersOf(message)}`, dispatch);
2650
+ await tab.control.humanLatest(
2651
+ viewer.id,
2652
+ `hover:${modifiersOf(message)}`,
2653
+ message,
2654
+ dispatch,
2655
+ );
2656
+ } else if (message.type === "wheel") {
2657
+ // A reversal stays separate so scrolling clamped at an edge behaves as if unmerged.
2658
+ await tab.control.humanLatest(
2659
+ viewer.id,
2660
+ `wheel:${num(message.x)}:${num(message.y)}:${modifiersOf(message)}:${Math.sign(num(message.deltaX))}:${Math.sign(num(message.deltaY))}`,
2661
+ message,
2662
+ dispatch,
2663
+ (waiting, next) => ({
2664
+ ...next,
2665
+ deltaX: num(waiting.deltaX) + num(next.deltaX),
2666
+ deltaY: num(waiting.deltaY) + num(next.deltaY),
2667
+ }),
2668
+ );
2669
} else {
2651
- await tab.control.human(viewer.id, dispatch);
2670
+ await tab.control.human(viewer.id, () => dispatch(message));
2671
}
2672
}
2673
} catch {
apps/server/src/preview/SessionControl.test.ts
+18
-18
@@ -9,14 +9,14 @@ describe("SessionControl", () => {
9
const started = Promise.withResolvers<void>();
10
const finish = Promise.withResolvers<void>();
11
const events: Array<number | string> = [];
12
- const running = control.humanLatest("viewer", "hover:0", async () => {
12
+ const running = control.humanLatest("viewer", "hover:0", undefined, async () => {
13
events.push("running");
14
started.resolve();
15
await finish.promise;
16
});
17
await started.promise;
18
const moves = Array.from({ length: 120 }, (_, position) =>
19
- control.humanLatest("viewer", "hover:0", async () => {
19
+ control.humanLatest("viewer", "hover:0", undefined, async () => {
20
events.push(position);
21
}),
22
);
@@ -36,7 +36,7 @@ describe("SessionControl", () => {
36
const finish = Promise.withResolvers<void>();
37
const events: string[] = [];
38
const running = control.human("viewer", () => finish.promise);
39
- const before = control.humanLatest("viewer", "hover:0", async () => {
39
+ const before = control.humanLatest("viewer", "hover:0", undefined, async () => {
40
events.push("before");
41
});
42
const recordBarrier = async () => {
@@ -44,11 +44,11 @@ describe("SessionControl", () => {
44
};
45
const between =
46
barrier === "modifiers"
47
- ? control.humanLatest("viewer", "hover:2", recordBarrier)
47
+ ? control.humanLatest("viewer", "hover:2", undefined, recordBarrier)
48
: barrier === "system"
49
? control.system(recordBarrier)
50
: control.human("viewer", recordBarrier);
51
- const after = control.humanLatest("viewer", "hover:0", async () => {
51
+ const after = control.humanLatest("viewer", "hover:0", undefined, async () => {
52
events.push("after");
53
});
54
finish.resolve();
@@ -63,15 +63,15 @@ describe("SessionControl", () => {
63
const finish = Promise.withResolvers<void>();
64
const events: string[] = [];
65
const running = control.human("viewer", () => finish.promise);
66
- const stale = control.humanLatest("viewer", "hover", async () => {
66
+ const stale = control.humanLatest("viewer", "hover", undefined, async () => {
67
events.push("stale");
68
});
69
await expect(
70
- control.humanLatest("other", "hover", async () => {
70
+ control.humanLatest("other", "hover", undefined, async () => {
71
events.push("other");
72
}),
73
).rejects.toThrow(BrowserControlInterrupted);
74
- const latest = control.humanLatest("viewer", "hover", async () => {
74
+ const latest = control.humanLatest("viewer", "hover", undefined, async () => {
75
events.push("latest");
76
});
77
finish.resolve();
@@ -93,16 +93,16 @@ describe("SessionControl", () => {
93
});
94
await started.promise;
95
const stale = expect(
96
- control.humanLatest("viewer", "hover", async () => {
96
+ control.humanLatest("viewer", "hover", undefined, async () => {
97
events.push("stale");
98
}),
99
).rejects.toThrow(BrowserControlInterrupted);
100
const released = control[handoff]("viewer");
101
const retaken = control.take("viewer");
102
- const fresh = control.humanLatest("viewer", "hover", async () => {
102
+ const fresh = control.humanLatest("viewer", "hover", undefined, async () => {
103
events.push("fresh");
104
});
105
- const latest = control.humanLatest("viewer", "hover", async () => {
105
+ const latest = control.humanLatest("viewer", "hover", undefined, async () => {
106
events.push("latest");
107
});
108
finish.resolve();
@@ -124,14 +124,14 @@ describe("SessionControl", () => {
124
await started.promise;
125
const waiting = [1, 2].map((position) =>
126
expect(
127
- control.humanLatest("viewer", "hover", async () => {
127
+ control.humanLatest("viewer", "hover", undefined, async () => {
128
events.push(`hover ${position}`);
129
}),
130
).rejects.toThrow("closed"),
131
);
132
const closed = control.close();
133
await expect(
134
- control.humanLatest("viewer", "hover", async () => {
134
+ control.humanLatest("viewer", "hover", undefined, async () => {
135
events.push("after close");
136
}),
137
).rejects.toThrow("closed");
@@ -147,18 +147,18 @@ describe("SessionControl", () => {
147
const events: string[] = [];
148
const running = control.human("viewer", () => finish.promise);
149
const first = expect(
150
- control.humanLatest("viewer", "hover", async () => {
150
+ control.humanLatest("viewer", "hover", undefined, async () => {
151
events.push("superseded");
152
}),
153
).rejects.toThrow("dispatch failed");
154
const last = expect(
155
- control.humanLatest("viewer", "hover", async () => {
155
+ control.humanLatest("viewer", "hover", undefined, async () => {
156
throw new Error("dispatch failed");
157
}),
158
).rejects.toThrow("dispatch failed");
159
finish.resolve();
160
await Promise.all([running, first, last]);
161
- await control.humanLatest("viewer", "hover", async () => {
161
+ await control.humanLatest("viewer", "hover", undefined, async () => {
162
events.push("recovered");
163
});
164
expect(events).toEqual(["recovered"]);
@@ -177,10 +177,10 @@ describe("SessionControl", () => {
177
);
178
return "started";
179
});
180
- const first = control.humanLatest("viewer", "hover", async () => {
180
+ const first = control.humanLatest("viewer", "hover", undefined, async () => {
181
events.push("superseded");
182
});
183
- const latest = control.humanLatest("viewer", "hover", async () => {
183
+ const latest = control.humanLatest("viewer", "hover", undefined, async () => {
184
events.push("latest");
185
});
186
await expect(navigation).resolves.toBe("started");
apps/server/src/preview/SessionControl.ts
+16
-6
@@ -23,7 +23,7 @@ export class SessionControl {
23
private readonly onGenerationChange: () => void;
24
private tail: Promise<unknown> = Promise.resolve();
25
private latestHuman: {
26
- entry: { viewerId: string; key: string; run: () => Promise<void> };
26
+ entry: { viewerId: string; key: string; input: unknown; run: (input: never) => Promise<void> };
27
result: Promise<void>;
28
} | null = null;
29
private pending: Promise<void> = Promise.resolve();
@@ -134,18 +134,28 @@ export class SessionControl {
134
return this.action(() => this.owner === viewerId, run);
135
}
136
137
- /** Replace only adjacent waiting work; the running action and intervening actions keep their order. */
138
- humanLatest(viewerId: string, key: string, run: () => Promise<void>): Promise<void> {
139
- if (this.closed || this.owner !== viewerId) return this.human(viewerId, run);
137
+ /**
138
+ * Merge into only adjacent waiting work with the same key; the running action and
139
+ * intervening actions keep their order. Work sharing a key must share its input type.
140
+ */
141
+ humanLatest<A>(
142
+ viewerId: string,
143
+ key: string,
144
+ input: A,
145
+ run: (input: A) => Promise<void>,
146
+ merge: (waiting: A, next: A) => A = (_waiting, next) => next,
147
+ ): Promise<void> {
148
+ if (this.closed || this.owner !== viewerId) return this.human(viewerId, () => run(input));
149
const latest = this.latestHuman;
150
if (latest?.entry.viewerId === viewerId && latest.entry.key === key) {
151
+ latest.entry.input = merge(latest.entry.input as A, input);
152
latest.entry.run = run;
153
return latest.result;
154
}
145
- const entry = { viewerId, key, run };
155
+ const entry = { viewerId, key, input, run };
156
const result = this.human(viewerId, async () => {
157
if (this.latestHuman?.entry === entry) this.latestHuman = null;
148
- await entry.run();
158
+ await entry.run(entry.input);
159
});
160
this.latestHuman = { entry, result };
161
return result;