|
1 | | -import { memo, useState } from "react"; |
| 1 | +import { memo, useEffect, useState } from "react"; |
2 | 2 | import { isThemeColor, themeColorToHex, type ThemeColorRole } from "../../themePalette"; |
3 | 3 | import { cn } from "../../lib/utils"; |
4 | 4 | import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color"; |
@@ -68,8 +68,8 @@ function themeRgbValue(hex: string) { |
68 | 68 |
|
69 | 69 | // Local state updates immediately for a smooth thumb; the parent commit |
70 | 70 | // (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. |
73 | 73 | function createFrameCommitter() { |
74 | 74 | let pending: { readonly color: string; readonly commit: (color: string) => void } | null = null; |
75 | 75 | let frame: number | null = null; |
@@ -248,6 +248,8 @@ function ThemeColorPicker({ |
248 | 248 | onInteract?: () => void; |
249 | 249 | }) { |
250 | 250 | const [committer] = useState(createFrameCommitter); |
| 251 | + // Unmounting with the popover open (the editor closes mid-drag) never fires onOpenChange. |
| 252 | + useEffect(() => committer.flush, [committer]); |
251 | 253 | return ( |
252 | 254 | <Popover |
253 | 255 | onOpenChange={(open) => { |
|
0 commit comments