Skip to content

Commit cc8f203

Browse files
drdatorclaude
andcommitted
fix(web): settle a cancelled picker's pending frame when it closes
Escape left the frame-batched commit queued until the next frame. Flush it on every close so the cancel gate drops it immediately and a reopen cannot pick it up. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 781f6db commit cc8f203

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎apps/web/src/components/settings/ThemeColorPicker.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ function ThemeColorPicker({
252252
onInteract?: () => void;
253253
}) {
254254
const [committer] = useState(createFrameCommitter);
255-
// Escape reverts the edit, so drop the pending frame and any drag still firing through the exit
256-
// animation instead of committing them over the restored colors.
255+
// Escape reverts the edit, so commits after it (the pending frame flushed on close, or a drag
256+
// still firing through the exit animation) are dropped instead of landing on the restored colors.
257257
const cancelledRef = useRef(false);
258258
// Unmounting with the popover open (the editor closes mid-drag) never fires onOpenChange.
259259
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- flushes the frame committer on unmount, since an open popover never fires onOpenChange
@@ -262,9 +262,12 @@ function ThemeColorPicker({
262262
<Popover
263263
onOpenChange={(open, eventDetails) => {
264264
cancelledRef.current = !open && eventDetails.reason === "escape-key";
265-
if (open) onEditStart?.();
266-
else if (cancelledRef.current) onEditCancel?.();
267-
else committer.flush();
265+
if (open) {
266+
onEditStart?.();
267+
return;
268+
}
269+
committer.flush();
270+
if (cancelledRef.current) onEditCancel?.();
268271
}}
269272
>
270273
<Tooltip>

0 commit comments

Comments
 (0)