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, 17:00 UTC
refactor(web): branch toolbar and dialogs stop syncing through effects (#25072)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 25, 2026 at 18:13 UTC
9f7b8ade1b27e45d6d85a368f197abfbcde3f03f
5 files changed
+226
-222
apps/web/src/components/BranchToolbar.tsx
+138
-127
@@ -18,12 +18,10 @@ import {
18
type MouseEvent as ReactMouseEvent,
19
memo,
20
useImperativeHandle,
21
- useEffect,
22
- useEffectEvent,
23
- useLayoutEffect,
21
useRef,
22
useState,
23
} from "react";
24
+import { flushSync } from "react-dom";
25
26
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
27
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
@@ -465,144 +463,158 @@ function labelTextWidth(label: HTMLElement, range: Range): number {
463
return Number.isFinite(maxWidth) ? Math.min(width, maxWidth) : width;
464
}
465
468
-function useLabelsOverflow(element: HTMLDivElement | null): boolean {
466
+function animateLabelWidths(
467
+ previousRects: ReadonlyMap<HTMLElement, DOMRect>,
468
+ animations: Map<HTMLElement, Animation>,
469
+) {
470
+ for (const animation of animations.values()) animation.cancel();
471
+ animations.clear();
472
+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
473
+
474
+ for (const [label, previousRect] of previousRects) {
475
+ if (!label.isConnected) continue;
476
+ const nextWidth = label.getBoundingClientRect().width;
477
+ if (Math.abs(previousRect.width - nextWidth) < 0.5) continue;
478
+
479
+ const animation = label.animate(
480
+ [
481
+ { width: `${previousRect.width}px`, maxWidth: `${previousRect.width}px` },
482
+ { width: `${nextWidth}px`, maxWidth: `${nextWidth}px` },
483
+ ],
484
+ {
485
+ duration: COMPOSER_CONTEXT_MOTION_DURATION_MS,
486
+ easing: COMPOSER_CONTEXT_MOTION_EASING,
487
+ fill: "backwards",
488
+ },
489
+ );
490
+ animations.set(label, animation);
491
+ animation.addEventListener(
492
+ "finish",
493
+ () => {
494
+ if (animations.get(label) === animation) animations.delete(label);
495
+ },
496
+ { once: true },
497
+ );
498
+ }
499
+}
500
+
501
+/**
502
+ * Whether the strip's labels must collapse to icons. The strip is measured when
503
+ * it, a control group or a hosted control resizes, when its text or children
504
+ * change, and when fonts load, which covers everything the widths depend on.
505
+ */
506
+function useLabelsOverflow(): readonly [
507
+ attach: (element: HTMLDivElement | null) => (() => void) | undefined,
508
+ overflows: boolean,
509
+] {
510
const [overflows, setOverflows] = useState(false);
470
- const pendingLabelRectsRef = useRef<Map<HTMLElement, DOMRect> | null>(null);
471
- const labelAnimationsRef = useRef(new Map<HTMLElement, Animation>());
472
- const measure = useEffectEvent(() => {
473
- const current = element;
474
- const compact = overflows;
511
+
512
+ const attach = (current: HTMLDivElement | null) => {
513
if (!current) return;
476
- const stripWidth = current.clientWidth;
477
- if (stripWidth === 0) return;
478
- const stripStyle = getComputedStyle(current);
479
- const available =
480
- stripWidth -
481
- (Number.parseFloat(stripStyle.paddingInlineStart) || 0) -
482
- (Number.parseFloat(stripStyle.paddingInlineEnd) || 0);
483
- const contentWidth = (parent: Element): number => {
484
- const gap = Number.parseFloat(getComputedStyle(parent).columnGap) || 0;
485
- let width = 0;
486
- let counted = 0;
487
- for (const child of parent.children) {
514
+ const labelAnimations = new Map<HTMLElement, Animation>();
515
+
516
+ const measure = () => {
517
+ // The committed attribute, not render state, so a stale closure cannot misread it.
518
+ const compact = current.hasAttribute("data-compact");
519
+ const stripWidth = current.clientWidth;
520
+ if (stripWidth === 0) return;
521
+ const stripStyle = getComputedStyle(current);
522
+ const available =
523
+ stripWidth -
524
+ (Number.parseFloat(stripStyle.paddingInlineStart) || 0) -
525
+ (Number.parseFloat(stripStyle.paddingInlineEnd) || 0);
526
+ const contentWidth = (parent: Element): number => {
527
+ const gap = Number.parseFloat(getComputedStyle(parent).columnGap) || 0;
528
+ let width = 0;
529
+ let counted = 0;
530
+ for (const child of parent.children) {
531
+ if (!(child instanceof HTMLElement)) continue;
532
+ if (child.offsetWidth === 0) continue;
533
+ const style = getComputedStyle(child);
534
+ const position = style.position;
535
+ if (position === "absolute" || position === "fixed") continue;
536
+ width +=
537
+ child.offsetWidth +
538
+ (Number.parseFloat(style.marginInlineStart) || 0) +
539
+ (Number.parseFloat(style.marginInlineEnd) || 0);
540
+ counted += 1;
541
+ }
542
+ return width + gap * Math.max(0, counted - 1);
543
+ };
544
+ const stripGap = Number.parseFloat(stripStyle.columnGap) || 0;
545
+ let needed = 0;
546
+ let groups = 0;
547
+ for (const child of current.children) {
548
if (!(child instanceof HTMLElement)) continue;
489
- if (child.offsetWidth === 0) continue;
490
- const style = getComputedStyle(child);
491
- const position = style.position;
492
- if (position === "absolute" || position === "fixed") continue;
493
- width +=
494
- child.offsetWidth +
495
- (Number.parseFloat(style.marginInlineStart) || 0) +
496
- (Number.parseFloat(style.marginInlineEnd) || 0);
497
- counted += 1;
549
+ // Reserve overflowed controls' width to prevent repeated hiding and expansion.
550
+ const hostedControls = child.matches('[data-chat-resting-composer-controls-host="true"]')
551
+ ? child.querySelector<HTMLElement>('[data-chat-composer-resting-controls="true"]')
552
+ : null;
553
+ const hostedMeasurement = hostedControls
554
+ ? measureRestingComposerControls(hostedControls)
555
+ : null;
556
+ const width = hostedMeasurement
557
+ ? resolveRestingComposerControlsNaturalWidth(hostedMeasurement)
558
+ : contentWidth(hostedControls ?? child);
559
+ if (width <= 1) continue;
560
+ groups += 1;
561
+ needed += width;
562
}
499
- return width + gap * Math.max(0, counted - 1);
500
- };
501
- const stripGap = Number.parseFloat(stripStyle.columnGap) || 0;
502
- let needed = 0;
503
- let groups = 0;
504
- for (const child of current.children) {
505
- if (!(child instanceof HTMLElement)) continue;
506
- // Reserve overflowed controls' width to prevent repeated hiding and expansion.
507
- const hostedControls = child.matches('[data-chat-resting-composer-controls-host="true"]')
508
- ? child.querySelector<HTMLElement>('[data-chat-composer-resting-controls="true"]')
509
- : null;
510
- const hostedMeasurement = hostedControls
511
- ? measureRestingComposerControls(hostedControls)
512
- : null;
513
- const width = hostedMeasurement
514
- ? resolveRestingComposerControlsNaturalWidth(hostedMeasurement)
515
- : contentWidth(hostedControls ?? child);
516
- if (width <= 1) continue;
517
- groups += 1;
518
- needed += width;
519
- }
520
- needed += stripGap * Math.max(0, groups - 1);
521
- const range = document.createRange();
522
- for (const label of current.querySelectorAll<HTMLElement>("[data-composer-label]")) {
523
- needed += Math.max(0, labelTextWidth(label, range) - label.getBoundingClientRect().width);
524
- }
525
- const nextOverflows = resolveContextStripLabelsCompact({
526
- compact,
527
- neededWidth: needed,
528
- availableWidth: available,
529
- });
530
- if (nextOverflows !== compact) {
531
- pendingLabelRectsRef.current = new Map(
563
+ needed += stripGap * Math.max(0, groups - 1);
564
+ const range = document.createRange();
565
+ for (const label of current.querySelectorAll<HTMLElement>("[data-composer-label]")) {
566
+ needed += Math.max(0, labelTextWidth(label, range) - label.getBoundingClientRect().width);
567
+ }
568
+ const nextOverflows = resolveContextStripLabelsCompact({
569
+ compact,
570
+ neededWidth: needed,
571
+ availableWidth: available,
572
+ });
573
+ if (nextOverflows === compact) return;
574
+ const previousRects = new Map(
575
Array.from(current.querySelectorAll<HTMLElement>(COMPOSER_CONTEXT_LABEL_SELECTOR)).map(
533
- (label) => [label, label.getBoundingClientRect()],
576
+ (label) => [label, label.getBoundingClientRect()] as const,
577
),
578
);
536
- }
537
- setOverflows(nextOverflows);
538
- });
539
-
540
- useLayoutEffect(() => {
541
- const previousRects = pendingLabelRectsRef.current;
542
- if (!previousRects) return;
543
- pendingLabelRectsRef.current = null;
544
-
545
- for (const animation of labelAnimationsRef.current.values()) {
546
- animation.cancel();
547
- }
548
- labelAnimationsRef.current.clear();
549
-
550
- if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
551
-
552
- for (const [label, previousRect] of previousRects) {
553
- if (!label.isConnected) continue;
554
- const nextWidth = label.getBoundingClientRect().width;
555
- if (Math.abs(previousRect.width - nextWidth) < 0.5) continue;
579
+ flushSync(() => setOverflows(nextOverflows));
580
+ animateLabelWidths(previousRects, labelAnimations);
581
+ };
582
557
- const animation = label.animate(
583
+ let stopResize = () => {};
584
+ const observeSizes = () => {
585
+ stopResize();
586
+ stopResize = observeResize(
587
[
559
- { width: `${previousRect.width}px`, maxWidth: `${previousRect.width}px` },
560
- { width: `${nextWidth}px`, maxWidth: `${nextWidth}px` },
588
+ current,
589
+ ...Array.from(current.children),
590
+ ...Array.from(current.querySelectorAll("[data-chat-composer-resting-controls='true']")),
591
+ ...Array.from(current.querySelectorAll(COMPOSER_CONTEXT_LABEL_SELECTOR)),
592
],
562
- {
563
- duration: COMPOSER_CONTEXT_MOTION_DURATION_MS,
564
- easing: COMPOSER_CONTEXT_MOTION_EASING,
565
- fill: "backwards",
566
- },
593
+ measure,
594
);
568
- labelAnimationsRef.current.set(label, animation);
569
- animation.addEventListener(
570
- "finish",
571
- () => {
572
- if (labelAnimationsRef.current.get(label) === animation) {
573
- labelAnimationsRef.current.delete(label);
574
- }
575
- },
576
- { once: true },
595
+ };
596
+ observeSizes();
597
+ // Text and control changes alter natural widths without resizing a hidden
598
+ // or squeezed label, so they re-measure too. Only added or removed elements
599
+ // can change the observed set; re-subscribing delivers a measure itself.
600
+ const mutations = new MutationObserver((records) => {
601
+ const elementsChanged = records.some((record) =>
602
+ [...record.addedNodes, ...record.removedNodes].some((node) => node instanceof Element),
603
);
578
- }
579
- });
580
-
581
- useEffect(
582
- () => () => {
583
- for (const animation of labelAnimationsRef.current.values()) {
584
- animation.cancel();
585
- }
586
- },
587
- [],
588
- );
589
-
590
- useLayoutEffect(() => {
591
- // oxlint-disable-next-line react/set-state-in-effect -- The label mode comes from measuring the committed DOM, which render cannot read.
592
- measure();
593
- });
594
-
595
- useEffect(() => {
596
- if (!element) return;
597
- const stopObserving = observeResize(element, measure);
604
+ if (elementsChanged) observeSizes();
605
+ else measure();
606
+ });
607
+ mutations.observe(current, { childList: true, characterData: true, subtree: true });
608
document.fonts.addEventListener("loadingdone", measure);
609
return () => {
600
- stopObserving();
610
+ stopResize();
611
+ mutations.disconnect();
612
document.fonts.removeEventListener("loadingdone", measure);
613
+ for (const animation of labelAnimations.values()) animation.cancel();
614
};
603
- }, [element]);
615
+ };
616
605
- return overflows;
617
+ return [attach, overflows] as const;
618
}
619
620
export const BranchToolbar = memo(function BranchToolbar({
@@ -698,8 +710,7 @@ export const BranchToolbar = memo(function BranchToolbar({
710
activeEnvironment: activeEnvironmentOption,
711
canPickEnvironment: hasMultipleEnvironments,
712
});
701
- const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
702
- const labelsOverflow = useLabelsOverflow(stripElement);
713
+ const [attachStrip, labelsOverflow] = useLabelsOverflow();
714
715
if (!activeProject) return null;
716
@@ -753,7 +764,7 @@ export const BranchToolbar = memo(function BranchToolbar({
764
765
return (
766
<ComposerSurface.ContextStrip
756
- ref={setStripElement}
767
+ ref={attachStrip}
768
data-compact={labelsOverflow ? "" : undefined}
769
className={cn(
770
"gap-1 text-xs font-normal text-foreground/70 dark:text-muted-foreground",
apps/web/src/components/CommandPaletteContent.tsx
+19
-10
@@ -1,9 +1,26 @@
1
import { ArrowDownIcon, ArrowUpIcon } from "lucide-react";
2
-import { type ComponentProps, type ReactNode, useEffect, useRef } from "react";
2
+import { type ComponentProps, type ReactNode } from "react";
3
4
import { Command, CommandFooter, CommandInput, CommandPanel } from "./ui/command";
5
import { Kbd, KbdGroup } from "./ui/kbd";
6
7
+/**
8
+ * A view replacing another inside an open dialog mounts with focus on the body,
9
+ * left there by the removed input. Claim it so typing cannot reach the composer
10
+ * behind the modal. On first open the dialog's own initial focus handles it.
11
+ */
12
+function claimFocusInOpenDialog(input: HTMLInputElement | null) {
13
+ if (!input) return;
14
+ const active = input.ownerDocument.activeElement;
15
+ if (
16
+ active === null ||
17
+ active === input.ownerDocument.body ||
18
+ input.closest('[role="dialog"]')?.contains(active)
19
+ ) {
20
+ input.focus();
21
+ }
22
+}
23
+
24
type CommandPaletteContentProps = Omit<ComponentProps<typeof Command>, "children"> & {
25
readonly children: ReactNode;
26
readonly escapeLabel?: ReactNode;
@@ -28,19 +45,11 @@ export function CommandPaletteContent({
45
testId,
46
...commandProps
47
}: CommandPaletteContentProps) {
31
- const inputRef = useRef<HTMLInputElement>(null);
32
-
33
- // Wait until the dialog records restoration focus before focusing a replaced input.
34
- useEffect(() => {
35
- const frame = requestAnimationFrame(() => inputRef.current?.focus());
36
- return () => cancelAnimationFrame(frame);
37
- }, []);
38
-
48
return (
49
<div className="contents" data-testid={testId}>
50
<Command {...commandProps}>
51
<div className="relative">
43
- <CommandInput autoFocus={false} {...inputProps} ref={inputRef} />
52
+ <CommandInput autoFocus={false} {...inputProps} ref={claimFocusInOpenDialog} />
53
{inputAccessory}
54
</div>
55
<CommandPanel
apps/web/src/components/PullRequestThreadDialog.tsx
+9
-13
@@ -8,7 +8,7 @@ import {
8
squashAtomCommandFailure,
9
} from "@t3tools/client-runtime/state/runtime";
10
import { useDebouncedValue } from "@tanstack/react-pacer";
11
-import { useEffect, useRef, useState } from "react";
11
+import { useRef, useState } from "react";
12
13
import {
14
readCachedPullRequestResolution,
@@ -90,17 +90,6 @@ export function PullRequestThreadDialog({
90
const terminology = sourceControlPresentation.terminology;
91
const SourceControlIcon = sourceControlPresentation.Icon;
92
93
- useEffect(() => {
94
- if (!open) return;
95
- const frame = window.requestAnimationFrame(() => {
96
- referenceInputRef.current?.focus();
97
- referenceInputRef.current?.select();
98
- });
99
- return () => {
100
- window.cancelAnimationFrame(frame);
101
- };
102
- }, [open]);
103
-
93
const parsedReference = parsePullRequestReference(reference);
94
const parsedDebouncedReference = parsePullRequestReference(debouncedReference);
95
const pullRequestResolution = usePullRequestResolution({
@@ -205,7 +194,14 @@ export function PullRequestThreadDialog({
194
}
195
}}
196
>
208
- <DialogPopup className="max-w-xl">
197
+ <DialogPopup
198
+ className="max-w-xl"
199
+ initialFocus={() => {
200
+ referenceInputRef.current?.focus();
201
+ referenceInputRef.current?.select();
202
+ return false;
203
+ }}
204
+ >
205
<DialogHeader>
206
<DialogTitle className="flex items-center">
207
<SourceControlIcon className="me-2 size-4" />
apps/web/src/components/projectScriptEditor.tsx
+52
-64
@@ -19,13 +19,7 @@ import {
19
PlayIcon,
20
WrenchIcon,
21
} from "lucide-react";
22
-import React, {
23
- type FormEvent,
24
- type KeyboardEvent,
25
- useLayoutEffect,
26
- useRef,
27
- useState,
28
-} from "react";
22
+import React, { type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from "react";
23
24
import {
25
keybindingValueForCommand,
@@ -172,6 +166,15 @@ export function ProjectScriptEditorDialog({
166
const setValidationError = (message: string | null) => {
167
if (request !== null) setErrorState({ request, message });
168
};
169
+ // The last opened request stays shown while the dialog animates closed. Each
170
+ // new request mounts a fresh form, which drops the previous request's save.
171
+ const [shown, setShown] = useState<{
172
+ readonly request: ProjectScriptEditorRequest;
173
+ readonly key: number;
174
+ } | null>(request === null ? null : { request, key: 0 });
175
+ if (request !== null && request !== shown?.request) {
176
+ setShown({ request, key: (shown?.key ?? 0) + 1 });
177
+ }
178
const [deleteConfirmOpen, setDeleteConfirmOpen] = useComposerMenuState(!canEditActions);
179
const [deleteName, setDeleteName] = useState("");
180
@@ -185,20 +188,23 @@ export function ProjectScriptEditorDialog({
188
>
189
{/* The form owns its fields so a keystroke re-renders it, not the dialog chrome. */}
190
<DialogPopup>
188
- <ProjectScriptEditorForm
189
- environmentId={environmentId}
190
- editScope={editScope}
191
- request={request}
192
- scripts={scripts}
193
- validationError={validationError}
194
- onValidationError={setValidationError}
195
- onSubmit={onSubmit}
196
- onRequestDelete={(name) => {
197
- setDeleteName(name);
198
- setDeleteConfirmOpen(true);
199
- }}
200
- onClose={onClose}
201
- />
191
+ {shown ? (
192
+ <ProjectScriptEditorForm
193
+ key={shown.key}
194
+ environmentId={environmentId}
195
+ editScope={editScope}
196
+ request={shown.request}
197
+ scripts={scripts}
198
+ validationError={validationError}
199
+ onValidationError={setValidationError}
200
+ onSubmit={onSubmit}
201
+ onRequestDelete={(name) => {
202
+ setDeleteName(name);
203
+ setDeleteConfirmOpen(true);
204
+ }}
205
+ onClose={onClose}
206
+ />
207
+ ) : null}
208
</DialogPopup>
209
</Dialog>
210
@@ -246,7 +252,7 @@ function ProjectScriptEditorForm({
252
}: {
253
environmentId: EnvironmentId;
254
editScope: typeof AuthOrchestrationOperateScope | typeof AuthSettingsWriteScope;
249
- request: ProjectScriptEditorRequest | null;
255
+ request: ProjectScriptEditorRequest;
256
scripts: ReadonlyArray<ProjectScript>;
257
validationError: string | null;
258
onValidationError: (error: string | null) => void;
@@ -260,52 +266,34 @@ function ProjectScriptEditorForm({
266
const canEditActions = useEnvironmentScope(environmentId, editScope);
267
const canWriteSettings = useEnvironmentScope(environmentId, AuthSettingsWriteScope);
268
const formId = React.useId();
263
- const [name, setName] = useState("");
264
- const [command, setCommand] = useState("");
265
- const [icon, setIcon] = useState<ProjectScriptIcon>("play");
269
+ const [name, setName] = useState(request.initial.name);
270
+ const [command, setCommand] = useState(request.initial.command);
271
+ const [icon, setIcon] = useState<ProjectScriptIcon>(request.initial.icon);
272
const [iconPickerOpen, setIconPickerOpen] = useComposerMenuState(!canEditActions);
267
- const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(false);
268
- const [waitForSetup, setWaitForSetup] = useState(false);
269
- const [runOnSettle, setRunOnSettle] = useState(false);
270
- const [keybinding, setKeybinding] = useState("");
271
- const [previewUrl, setPreviewUrl] = useState("");
272
- const [autoOpenPreview, setAutoOpenPreview] = useState(false);
273
- const [savingRequest, setSavingRequest] = useState<ProjectScriptEditorRequest | null>(null);
274
- const pendingSubmissionRef = useRef<{ request: ProjectScriptEditorRequest } | null>(null);
275
-
276
- const isEditing = request?.scriptId != null;
277
- const isSaving = request !== null && savingRequest === request;
278
-
279
- useLayoutEffect(
273
+ const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(
274
+ request.initial.runOnWorktreeCreate,
275
+ );
276
+ const [waitForSetup, setWaitForSetup] = useState(request.initial.waitForSetup);
277
+ const [runOnSettle, setRunOnSettle] = useState(request.initial.runOnSettle);
278
+ const [keybinding, setKeybinding] = useState(request.initial.keybinding ?? "");
279
+ const [previewUrl, setPreviewUrl] = useState(request.initial.previewUrl ?? "");
280
+ const [autoOpenPreview, setAutoOpenPreview] = useState(request.initial.autoOpenPreview);
281
+ const [isSaving, setIsSaving] = useState(false);
282
+ const pendingSubmissionRef = useRef<object | null>(null);
283
+ // A save that settles after this form is replaced must not close or error
284
+ // the request that replaced it.
285
+ useEffect(
286
() => () => {
281
- if (pendingSubmissionRef.current?.request === request) {
282
- pendingSubmissionRef.current = null;
283
- }
287
+ pendingSubmissionRef.current = null;
288
},
285
- [request],
289
+ [],
290
);
291
288
- const [formRequest, setFormRequest] = useState<ProjectScriptEditorRequest | null>(null);
289
- if (request !== formRequest) {
290
- setFormRequest(request);
291
- if (request) {
292
- setName(request.initial.name);
293
- setCommand(request.initial.command);
294
- setIcon(request.initial.icon);
295
- setIconPickerOpen(false);
296
- setRunOnWorktreeCreate(request.initial.runOnWorktreeCreate);
297
- setWaitForSetup(request.initial.waitForSetup);
298
- setRunOnSettle(request.initial.runOnSettle);
299
- setKeybinding(request.initial.keybinding ?? "");
300
- setPreviewUrl(request.initial.previewUrl ?? "");
301
- setAutoOpenPreview(request.initial.autoOpenPreview);
302
- setSavingRequest(null);
303
- }
304
- }
292
+ const isEditing = request.scriptId != null;
293
294
const close = () => {
295
pendingSubmissionRef.current = null;
308
- setSavingRequest(null);
296
+ setIsSaving(false);
297
setIconPickerOpen(false);
298
onClose();
299
};
@@ -326,7 +314,7 @@ function ProjectScriptEditorForm({
314
315
const submit = async (event: FormEvent) => {
316
event.preventDefault();
329
- if (!request || pendingSubmissionRef.current !== null) return;
317
+ if (pendingSubmissionRef.current !== null) return;
318
if (!readEnvironmentScope(environmentId, editScope)) {
319
setValidationError("This connection cannot change project actions.");
320
return;
@@ -381,9 +369,9 @@ function ProjectScriptEditorForm({
369
return;
370
}
371
384
- const submission = { request };
372
+ const submission = {};
373
pendingSubmissionRef.current = submission;
386
- setSavingRequest(request);
374
+ setIsSaving(true);
375
setIconPickerOpen(false);
376
try {
377
const result = await onSubmit(request.scriptId, payload);
@@ -404,7 +392,7 @@ function ProjectScriptEditorForm({
392
}
393
if (pendingSubmissionRef.current === submission) {
394
pendingSubmissionRef.current = null;
407
- setSavingRequest(null);
395
+ setIsSaving(false);
396
}
397
};
398
apps/web/src/components/search/ProjectContentSearchDialog.tsx
+8
-8
@@ -1,7 +1,7 @@
1
import { Spinner } from "~/components/ui/spinner";
2
import { AuthFilesystemReadScope, type ProjectContentMatch } from "@t3tools/contracts";
3
4
-import { useEffect, useState, type ReactNode } from "react";
4
+import { useState, type ReactNode } from "react";
5
6
import { useActiveProjectTarget, type ActiveProjectTarget } from "~/hooks/useActiveProjectTarget";
7
import { useRenderedAppearance, useTheme } from "~/hooks/useTheme";
@@ -97,6 +97,10 @@ function EmptyContentSearchDialog() {
97
);
98
}
99
100
+const scrollSelectedRowIntoView = (row: HTMLElement | null) => {
101
+ row?.scrollIntoView({ block: "nearest" });
102
+};
103
+
104
function OpenContentSearchDialog(props: {
105
readonly onOpenChange: (open: boolean) => void;
106
readonly target: ActiveProjectTarget;
@@ -134,12 +138,6 @@ function OpenContentSearchDialog(props: {
138
const visibleMatches = matches.slice(0, visibleCount);
139
const groups = groupMatches(visibleMatches);
140
137
- useEffect(() => {
138
- document
139
- .querySelector<HTMLElement>(`[data-content-search-result="${selectedIndex}"]`)
140
- ?.scrollIntoView({ block: "nearest" });
141
- }, [selectedIndex]);
142
-
141
const observeLoadMoreSentinel = (sentinel: HTMLElement | null) => {
142
if (!sentinel) return;
143
const observer = new IntersectionObserver((entries) => {
@@ -280,7 +278,9 @@ function OpenContentSearchDialog(props: {
278
<button
279
type="button"
280
key={`${match.path}:${match.lineNumber}:${match.resultIndex}`}
283
- data-content-search-result={match.resultIndex}
281
+ ref={
282
+ match.resultIndex === selectedIndex ? scrollSelectedRowIntoView : undefined
283
+ }
284
className={cn(
285
"flex h-7 w-full min-w-0 items-center gap-3 px-3 text-left font-mono text-xs hover:bg-accent/60 disabled:pointer-events-none",
286
match.resultIndex === selectedIndex && "bg-accent text-accent-foreground",