The best way to control Claude Code, Codex and more from any computer or phone
refactor(client): drop the VCS wake and dispatcher element scope options nobody uses (#25152)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 25, 2026 at 18:27 UTC
7a95549b94742dc55dd40f1075dda71d3bb40646
4 files changed
+27
-124
apps/web/src/shortcuts/dispatcher.browser.test.ts
+13
-33
@@ -1,12 +1,7 @@
1
import type { KeybindingCommand, ResolvedKeybindingsConfig } from "@t3tools/contracts";
2
import { describe, expect, it, vi } from "vite-plus/test";
3
4
-import {
5
- commandScopeRef,
6
- dispatchMenuAction,
7
- registerCommands,
8
- registerMenuAction,
9
-} from "./dispatcher";
4
+import { dispatchMenuAction, registerCommands, registerMenuAction } from "./dispatcher";
5
6
function bindings(entries: ReadonlyArray<[string, KeybindingCommand]>): ResolvedKeybindingsConfig {
7
return entries.map(([key, command]) => ({
@@ -34,10 +29,6 @@ function press(key: string): KeyboardEvent {
29
return event;
30
}
31
37
-function mountScope(...args: Parameters<typeof commandScopeRef>): () => void {
38
- return commandScopeRef(...args)(document.body) ?? (() => {});
39
-}
40
-
32
describe("command dispatcher", () => {
33
it("runs the newest scope's handler and nothing below it", () => {
34
const global = vi.fn();
@@ -45,8 +36,8 @@ describe("command dispatcher", () => {
36
const inner = vi.fn();
37
using stack = new DisposableStack();
38
stack.defer(registerCommands({ "chat.new": global }, { keybindings }));
48
- stack.defer(mountScope({ "chat.new": outer }, { keybindings }));
49
- stack.defer(mountScope({ "chat.new": inner }, { keybindings }));
39
+ stack.defer(registerCommands({ "chat.new": outer }, { keybindings }));
40
+ stack.defer(registerCommands({ "chat.new": inner }, { keybindings }));
41
42
press("k");
43
@@ -61,9 +52,9 @@ describe("command dispatcher", () => {
52
const guarded = vi.fn();
53
using stack = new DisposableStack();
54
stack.defer(registerCommands({ "chat.new": global }, { keybindings }));
64
- stack.defer(mountScope({ "chat.new": declined }, { keybindings }));
65
- stack.defer(mountScope({ "chat.newLocal": vi.fn() }, { keybindings }));
66
- stack.defer(mountScope({ "chat.new": guarded }, { keybindings, when: () => false }));
55
+ stack.defer(registerCommands({ "chat.new": declined }, { keybindings }));
56
+ stack.defer(registerCommands({ "chat.newLocal": vi.fn() }, { keybindings }));
57
+ stack.defer(registerCommands({ "chat.new": guarded }, { keybindings, when: () => false }));
58
59
press("k");
60
@@ -72,19 +63,6 @@ describe("command dispatcher", () => {
63
expect(global).toHaveBeenCalledOnce();
64
});
65
75
- it("element scopes win over global commands registered after them", () => {
76
- const element = vi.fn();
77
- const global = vi.fn();
78
- using stack = new DisposableStack();
79
- stack.defer(mountScope({ "chat.new": element }, { keybindings }));
80
- stack.defer(registerCommands({ "chat.new": global }, { keybindings }));
81
-
82
- press("k");
83
-
84
- expect(element).toHaveBeenCalledOnce();
85
- expect(global).not.toHaveBeenCalled();
86
- });
87
-
66
it("stops once a handler prevents default, and unregisters on cleanup", () => {
67
const lower = vi.fn();
68
const upper = vi.fn((event: KeyboardEvent) => {
@@ -92,13 +70,13 @@ describe("command dispatcher", () => {
70
return false;
71
});
72
using stack = new DisposableStack();
95
- stack.defer(mountScope({ "chat.new": lower }, { keybindings }));
96
- const unmountUpper = mountScope({ "chat.new": upper }, { keybindings });
73
+ stack.defer(registerCommands({ "chat.new": lower }, { keybindings }));
74
+ const unregisterUpper = registerCommands({ "chat.new": upper }, { keybindings });
75
76
press("k");
77
expect(lower).not.toHaveBeenCalled();
78
101
- unmountUpper();
79
+ unregisterUpper();
80
press("k");
81
expect(upper).toHaveBeenCalledOnce();
82
expect(lower).toHaveBeenCalledOnce();
@@ -108,7 +86,7 @@ describe("command dispatcher", () => {
86
const onEscape = vi.fn((event: KeyboardEvent) => (event.key === "Escape" ? undefined : false));
87
const command = vi.fn();
88
using stack = new DisposableStack();
111
- stack.defer(mountScope({ "chat.new": command }, { keybindings, onKeyDown: onEscape }));
89
+ stack.defer(registerCommands({ "chat.new": command }, { keybindings, onKeyDown: onEscape }));
90
91
press("Escape");
92
press("k");
@@ -123,7 +101,9 @@ describe("command dispatcher", () => {
101
stack.defer(
102
registerCommands({}, { observe: (_event, consumed) => calls.push(`observe:${consumed}`) }),
103
);
126
- stack.defer(mountScope({ "chat.new": () => void calls.push("command") }, { keybindings }));
104
+ stack.defer(
105
+ registerCommands({ "chat.new": () => void calls.push("command") }, { keybindings }),
106
+ );
107
108
press("k");
109
press("x");
apps/web/src/shortcuts/dispatcher.ts
+4
-18
@@ -22,12 +22,12 @@ export interface CommandScopeOptions {
22
/** For shortcuts that are not keybinding commands (Escape, "/"); runs before command lookup. */
23
readonly onKeyDown?: CommandHandler;
24
/**
25
- * App-global only: run in the capture phase, ahead of focused widgets that consume the key
25
+ * Run in the capture phase, ahead of focused widgets that consume the key
26
* themselves (the terminal encodes Ctrl+Shift+T and stops propagation).
27
*/
28
readonly capture?: boolean;
29
/**
30
- * App-global only: hear every bubbling keydown after the scopes ran, with whether one of them
30
+ * Hear every bubbling keydown after the scopes ran, with whether one of them
31
* (or the page) consumed it. Observers never consume. For listeners that react to keys other
32
* scopes may also handle, such as scroll keys.
33
*/
@@ -39,8 +39,7 @@ interface CommandScope {
39
readonly options: CommandScopeOptions;
40
}
41
42
-// Element scopes sit above app-global scopes; within each list the newest wins.
43
-const elementScopes: CommandScope[] = [];
42
+// Within each list the newest scope wins.
43
const globalScopes: CommandScope[] = [];
44
const captureScopes: CommandScope[] = [];
45
const observerScopes: CommandScope[] = [];
@@ -81,8 +80,7 @@ function dispatchCaptureKeyDown(event: KeyboardEvent): void {
80
}
81
82
function dispatchKeyDown(event: KeyboardEvent): void {
84
- const consumed =
85
- runScopes(elementScopes, event) || runScopes(globalScopes, event) || event.defaultPrevented;
83
+ const consumed = runScopes(globalScopes, event) || event.defaultPrevented;
84
for (const scope of observerScopes.slice()) scope.options.observe?.(event, consumed);
85
}
86
@@ -112,18 +110,6 @@ export function registerCommands(
110
return pushScope(scopes, { commands, options });
111
}
112
115
-/**
116
- * Ref callback that keeps a command scope registered while its element is
117
- * mounted. Handlers should read changing values from stores at event time so
118
- * the callback stays stable across renders.
119
- */
120
-export function commandScopeRef(
121
- commands: CommandHandlers,
122
- options: CommandScopeOptions = {},
123
-): (node: Element | null) => (() => void) | undefined {
124
- return (node) => (node === null ? undefined : pushScope(elementScopes, { commands, options }));
125
-}
126
-
113
type MenuActionHandler = () => void;
114
const menuActionHandlers = new Map<string, MenuActionHandler[]>();
115
let menuActionInstalled = false;
packages/client-runtime/src/state/vcsStatusRevalidation.test.ts
+5
-44
@@ -6,28 +6,15 @@ import { createVcsStatusRevalidationAtomFamily } from "./vcsStatusRevalidation.t
6
7
const environmentId = EnvironmentId.make("environment-1");
8
9
-function setup(options: { readonly connected?: boolean; readonly wake?: boolean }) {
10
- const connectedAtom = Atom.make(options.connected ?? false);
11
- const wakes = new Set<() => void>();
9
+function setup(options: { readonly connected: boolean }) {
10
+ const connectedAtom = Atom.make(options.connected);
11
const run = vi.fn(async () => AsyncResult.success(null));
12
const family = createVcsStatusRevalidationAtomFamily({
13
refreshStatus: { label: "refresh-status", run },
15
- ...(options.connected === undefined ? {} : { connected: () => connectedAtom }),
16
- ...(options.wake
17
- ? {
18
- subscribeWake: (wake: () => void) => {
19
- wakes.add(wake);
20
- return () => wakes.delete(wake);
21
- },
22
- wakeDebounceMs: 250,
23
- }
24
- : {}),
14
+ connected: () => connectedAtom,
15
});
16
const registry = AtomRegistry.make();
27
- const wake = () => {
28
- for (const listener of wakes) listener();
29
- };
30
- return { registry, family, connectedAtom, run, wakes, wake };
17
+ return { registry, family, connectedAtom, run };
18
}
19
20
describe("createVcsStatusRevalidationAtomFamily", () => {
@@ -59,35 +46,9 @@ describe("createVcsStatusRevalidationAtomFamily", () => {
46
unmount();
47
});
48
62
- it("debounces wake signals and stops listening with the last subscriber", () => {
63
- vi.useFakeTimers();
64
- try {
65
- const { registry, family, run, wakes, wake } = setup({ wake: true });
66
- const unmount = registry.mount(family({ environmentId, cwd: "/repo" }));
67
- expect(run).not.toHaveBeenCalled();
68
-
69
- wake();
70
- vi.advanceTimersByTime(100);
71
- wake();
72
- vi.advanceTimersByTime(249);
73
- expect(run).not.toHaveBeenCalled();
74
- vi.advanceTimersByTime(1);
75
- expect(run).toHaveBeenCalledTimes(1);
76
-
77
- wake();
78
- unmount();
79
- vi.runAllTimers();
80
- expect(run).toHaveBeenCalledTimes(1);
81
- expect(wakes.size).toBe(0);
82
- } finally {
83
- vi.useRealTimers();
84
- }
85
- });
86
-
49
it("does nothing for an idle target", () => {
88
- const { registry, family, run, wakes } = setup({ connected: true, wake: true });
50
+ const { registry, family, run } = setup({ connected: true });
51
registry.mount(family(null))();
52
expect(run).not.toHaveBeenCalled();
91
- expect(wakes.size).toBe(0);
53
});
54
});
packages/client-runtime/src/state/vcsStatusRevalidation.ts
+5
-29
@@ -1,4 +1,3 @@
1
-// @effect-diagnostics globalTimers:off - The wake debounce runs in an atom subscription, outside an Effect runtime.
1
import type { EnvironmentId } from "@t3tools/contracts";
2
import { Atom, type AtomRegistry } from "effect/reactivity";
3
@@ -10,10 +9,9 @@ interface VcsStatusRevalidationTarget {
9
}
10
11
/**
13
- * One atom per environment and cwd that refreshes VCS status while mounted and
14
- * shared by every subscriber. Refreshes only when `connected` is given and true
15
- * (on mount and on each reconnect), and on `subscribeWake` (debounced); the wake
16
- * subscription and timer end with the last subscriber.
12
+ * One atom per environment and cwd, shared by every subscriber, that refreshes
13
+ * VCS status while mounted: on mount and on each reconnect, once `connected`
14
+ * is true.
15
*/
16
export function createVcsStatusRevalidationAtomFamily<R>(input: {
17
readonly refreshStatus: AtomCommand<
@@ -21,9 +19,7 @@ export function createVcsStatusRevalidationAtomFamily<R>(input: {
19
R,
20
unknown
21
>;
24
- readonly connected?: (environmentId: EnvironmentId) => Atom.Atom<boolean>;
25
- readonly subscribeWake?: (wake: () => void) => () => void;
26
- readonly wakeDebounceMs?: number;
22
+ readonly connected: (environmentId: EnvironmentId) => Atom.Atom<boolean>;
23
readonly onRefreshed?: (result: AtomCommandResult<R, unknown>) => void;
24
}) {
25
const family = Atom.family((target: VcsStatusRevalidationTarget) => {
@@ -40,29 +36,9 @@ export function createVcsStatusRevalidationAtomFamily<R>(input: {
36
input.onRefreshed?.(result);
37
};
38
43
- const wakeAtom = Atom.make((get) => {
44
- const subscribeWake = input.subscribeWake;
45
- if (subscribeWake === undefined) return;
46
- const registry = get.registry;
47
- let timer: ReturnType<typeof setTimeout> | undefined;
48
- const unsubscribe = subscribeWake(() => {
49
- if (timer !== undefined) clearTimeout(timer);
50
- timer = setTimeout(() => {
51
- timer = undefined;
52
- void refresh(registry);
53
- }, input.wakeDebounceMs ?? 0);
54
- });
55
- get.addFinalizer(() => {
56
- if (timer !== undefined) clearTimeout(timer);
57
- unsubscribe();
58
- });
59
- }).pipe(Atom.withLabel(`vcs-status-revalidation:wake:${key}`));
60
-
39
return Atom.make((get) => {
62
- get(wakeAtom);
63
- const connected = input.connected;
40
// Rebuilds only when the connection flag flips, so each reconnect refreshes once.
65
- if (connected !== undefined && get(connected(environmentId))) {
41
+ if (get(input.connected(environmentId))) {
42
void refresh(get.registry);
43
}
44
}).pipe(Atom.withLabel(`vcs-status-revalidation:${key}`));