Skip to content

Commit 8ecb2d7

Browse files
fix(web): theme color picker still flushes its last drag frame on unmount
The theme editor can close while a color popover is open, which unmounts the picker without firing onOpenChange. Keep the ordinary unmount cleanup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 83cdaf2 commit 8ecb2d7

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useState } from "react";
1+
import { memo, useEffect, useState } from "react";
22
import { isThemeColor, themeColorToHex, type ThemeColorRole } from "../../themePalette";
33
import { cn } from "../../lib/utils";
44
import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color";
@@ -68,8 +68,8 @@ function themeRgbValue(hex: string) {
6868

6969
// Local state updates immediately for a smooth thumb; the parent commit
7070
// (which can regenerate a whole guided palette) is batched to one call per
71-
// animation frame. The popover flushes it on close and the drag surfaces on
72-
// release, so the final frame is never lost.
71+
// animation frame. The popover flushes it on close, the drag surfaces on
72+
// release, and the picker on unmount, so the final frame is never lost.
7373
function createFrameCommitter() {
7474
let pending: { readonly color: string; readonly commit: (color: string) => void } | null = null;
7575
let frame: number | null = null;
@@ -248,6 +248,8 @@ function ThemeColorPicker({
248248
onInteract?: () => void;
249249
}) {
250250
const [committer] = useState(createFrameCommitter);
251+
// Unmounting with the popover open (the editor closes mid-drag) never fires onOpenChange.
252+
useEffect(() => committer.flush, [committer]);
251253
return (
252254
<Popover
253255
onOpenChange={(open) => {

0 commit comments

Comments
 (0)