Skip to content

Commit 267cdfc

Browse files
committed
fix(studio): resolve 8 confirmed adversarial-review findings across the flat-inspector stack
Fixes issues raised in the Deepwork re-review of heygen-com#2120-heygen-com#2190 that weren't covered by heygen-com#2225's earlier fix pass: - useColorGradingController: reset grading/compare/mediaMetadata state (and cancel pending persist/status timers) when selection changes to a different element — this hook is called unconditionally on every render (unlike legacy ColorGradingSection, remounted via a selectionIdentityKey React key), so switching selection reused the previous element's state. - useColorGradingController: stop permanently caching a non-OK /media/metadata response as null — a transient server error poisoned the HDR banner for that asset for the whole page lifetime. - FlatSelectRow: preserve a valid authored value outside the preset list (e.g. mix-blend-mode: difference, an arbitrary object-position) instead of silently misrepresenting it as the first preset — touching the control would overwrite real persisted state. - FlatSlider: the throttled trailing commit now reads onCommit through a ref updated every render instead of closing over it at schedule time — a caller whose onCommit spreads other current state (Grade's per-detail commits) could otherwise have a delayed commit revert whatever the user changed on a different control in the same 40ms window. - FlatSlider: flush a still-queued trailing commit on unmount instead of dropping it, and disable the reset button when the slider itself is disabled. - FlatSlider: add touch-action: none to the track so touch drags don't compete with page scroll. - FlatColorGradingAccessory: clean up the compare-hold's window listeners on unmount, not only on release — switching selection mid-hold used to leak them. - Align (flat Text): re-clicking the option already visually active for a logical start/end value no longer rewrites it to the physical left/right, preserving RTL semantics. - FlatSegmentedRow: give every option an accessible name and aria-pressed state — two visually-identical glyph buttons (upright/italic "A") had no way to be told apart by assistive tech. - PropertyPanelFlat: the panel body falls back to its own scroll when the collapsed group headers alone exceed the available height, so groups can't become permanently unreachable in a short pane. New regression tests for all of the above; full studio suite at the known pre-existing baseline (55 failures unrelated to this stack).
1 parent cdd5083 commit 267cdfc

11 files changed

Lines changed: 550 additions & 142 deletions

‎packages/studio/src/components/editor/PropertyPanelFlat.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export function PropertyPanelFlat({
516516
onUngroup={onUngroup}
517517
showUngroup={Boolean(onUngroup && element.dataAttributes["hf-group"] != null)}
518518
/>
519-
<div data-flat-panel-body="true" className="flex min-h-0 flex-1 flex-col overflow-hidden">
519+
<div data-flat-panel-body="true" className="flex min-h-0 flex-1 flex-col overflow-y-auto">
520520
{beforeOpen.map((g) => (
521521
<FlatGroupHeader
522522
key={g.id}

‎packages/studio/src/components/editor/propertyPanelFlatColorGradingSection.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useRef, useState } from "react";
1+
import { useEffect, useMemo, useRef, useState } from "react";
22
import {
33
HF_COLOR_GRADING_PRESETS,
44
isHfColorGradingActive,
@@ -32,6 +32,18 @@ export function FlatColorGradingAccessory({
3232
}) {
3333
const { grading, compareEnabled, runtimeStatus, commitCompare, resetGrading } = state;
3434
const gradingActive = isHfColorGradingActive(grading);
35+
// Tracks the active hold's cleanup so it can be torn down on unmount too —
36+
// without this, switching selection away mid-hold (unmounting this
37+
// accessory) leaves the pointerup/pointercancel/blur listeners registered
38+
// on `window` forever, each holding a closure over the old commitCompare.
39+
const releaseRef = useRef<(() => void) | null>(null);
40+
useEffect(
41+
() => () => {
42+
releaseRef.current?.();
43+
releaseRef.current = null;
44+
},
45+
[],
46+
);
3547

3648
return (
3749
<span className="flex items-center gap-2.5">
@@ -50,7 +62,9 @@ export function FlatColorGradingAccessory({
5062
window.removeEventListener("pointerup", release);
5163
window.removeEventListener("pointercancel", release);
5264
window.removeEventListener("blur", release);
65+
releaseRef.current = null;
5366
};
67+
releaseRef.current = release;
5468
window.addEventListener("pointerup", release);
5569
window.addEventListener("pointercancel", release);
5670
window.addEventListener("blur", release);

‎packages/studio/src/components/editor/propertyPanelFlatLayoutSection.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ export function LayoutFlexBlock({
203203
<FlatSegmentedRow
204204
label="Direction"
205205
options={[
206-
{ key: "row", node: "→ Row", active: direction === "row" },
207-
{ key: "column", node: "Column", active: direction === "column" },
206+
{ key: "row", node: "→ Row", label: "Row", active: direction === "row" },
207+
{ key: "column", node: "Column", label: "Column", active: direction === "column" },
208208
]}
209209
disabled={disabled}
210210
onChange={(next) => void onSetStyle("flex-direction", next)}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import {
2+
buildInsetClipPathSides,
3+
buildInsetClipPathValue,
4+
formatNumericValue,
5+
formatPxMetricValue,
6+
getClipPathInsetPx,
7+
inferClipPathPreset,
8+
parseInsetClipPathSides,
9+
parsePxMetricValue,
10+
type ClipPathInsetSides,
11+
} from "./propertyPanelHelpers";
12+
import { FlatSlider } from "./propertyPanelFlatPrimitives";
13+
import { MetricField } from "./propertyPanelPrimitives";
14+
15+
/* ------------------------------------------------------------------ */
16+
/* Flat Mask inset — uniform slider + per-side fields */
17+
/* (split out of propertyPanelFlatStyleSections.tsx to stay under the */
18+
/* 600-line file-size gate) */
19+
/* ------------------------------------------------------------------ */
20+
21+
export function FlatMaskInsetRows({
22+
clipPathValue,
23+
radiusValue,
24+
disabled,
25+
onSetStyle,
26+
}: {
27+
clipPathValue: string;
28+
radiusValue: number;
29+
disabled: boolean;
30+
onSetStyle: (prop: string, value: string) => void | Promise<void>;
31+
}) {
32+
const clipPathPreset = inferClipPathPreset(clipPathValue);
33+
const parsedClipInsets = parseInsetClipPathSides(clipPathValue);
34+
const clipInsetValue = getClipPathInsetPx(clipPathValue);
35+
const clipInsetSides = parsedClipInsets ?? {
36+
top: clipInsetValue,
37+
right: clipInsetValue,
38+
bottom: clipInsetValue,
39+
left: clipInsetValue,
40+
radius: radiusValue,
41+
};
42+
const showClipInsetSides = clipPathPreset === "inset" || parsedClipInsets != null;
43+
44+
const commitClipInsetSide = (side: keyof ClipPathInsetSides, nextValue: string) => {
45+
const next = parsePxMetricValue(nextValue);
46+
if (next == null) return;
47+
const sides: ClipPathInsetSides = {
48+
top: clipInsetSides.top,
49+
right: clipInsetSides.right,
50+
bottom: clipInsetSides.bottom,
51+
left: clipInsetSides.left,
52+
};
53+
sides[side] = next;
54+
void onSetStyle("clip-path", buildInsetClipPathSides(sides, clipInsetSides.radius));
55+
};
56+
57+
return (
58+
<>
59+
<FlatSlider
60+
label="Mask inset"
61+
value={clipInsetValue}
62+
min={0}
63+
max={Math.max(120, Math.ceil(clipInsetValue))}
64+
step={1}
65+
tier={clipInsetValue > 0 ? "explicitCustom" : "default"}
66+
displayValue={`${formatNumericValue(clipInsetValue)}px`}
67+
disabled={disabled}
68+
onCommit={(next) =>
69+
void onSetStyle("clip-path", buildInsetClipPathValue(next, radiusValue))
70+
}
71+
/>
72+
{showClipInsetSides && (
73+
<div className="grid grid-cols-4 gap-2">
74+
<MetricField
75+
label="T"
76+
value={formatPxMetricValue(clipInsetSides.top)}
77+
disabled={disabled}
78+
onCommit={(next) => commitClipInsetSide("top", next)}
79+
/>
80+
<MetricField
81+
label="R"
82+
value={formatPxMetricValue(clipInsetSides.right)}
83+
disabled={disabled}
84+
onCommit={(next) => commitClipInsetSide("right", next)}
85+
/>
86+
<MetricField
87+
label="B"
88+
value={formatPxMetricValue(clipInsetSides.bottom)}
89+
disabled={disabled}
90+
onCommit={(next) => commitClipInsetSide("bottom", next)}
91+
/>
92+
<MetricField
93+
label="L"
94+
value={formatPxMetricValue(clipInsetSides.left)}
95+
disabled={disabled}
96+
onCommit={(next) => commitClipInsetSide("left", next)}
97+
/>
98+
</div>
99+
)}
100+
</>
101+
);
102+
}

‎packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx‎

Lines changed: 170 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe("FlatSegmentedRow", () => {
8989
<FlatSegmentedRow
9090
label="Align"
9191
options={[
92-
{ key: "left", node: "L", active: false },
93-
{ key: "right", node: "R", active: true },
92+
{ key: "left", node: "L", label: "left", active: false },
93+
{ key: "right", node: "R", label: "right", active: true },
9494
]}
9595
onChange={onChange}
9696
/>,
@@ -105,6 +105,25 @@ describe("FlatSegmentedRow", () => {
105105
expect(onChange).toHaveBeenCalledWith("left");
106106
act(() => root.unmount());
107107
});
108+
109+
it("gives each option an accessible name and pressed state — glyphs alone (e.g. two 'A' buttons) aren't a valid accessible name", () => {
110+
const { host, root } = renderInto(
111+
<FlatSegmentedRow
112+
label="Case · Style"
113+
options={[
114+
{ key: "normal", node: "A", label: "upright", active: true },
115+
{ key: "italic", node: "A", label: "italic", active: false },
116+
]}
117+
onChange={vi.fn()}
118+
/>,
119+
);
120+
const options = host.querySelectorAll<HTMLButtonElement>('[data-flat-segment="true"]');
121+
expect(options[0]?.getAttribute("aria-label")).toBe("upright");
122+
expect(options[0]?.getAttribute("aria-pressed")).toBe("true");
123+
expect(options[1]?.getAttribute("aria-label")).toBe("italic");
124+
expect(options[1]?.getAttribute("aria-pressed")).toBe("false");
125+
act(() => root.unmount());
126+
});
108127
});
109128

110129
describe("FlatGroupHeader", () => {
@@ -554,6 +573,130 @@ describe("FlatSlider — Grade extensions", () => {
554573
act(() => root.unmount());
555574
});
556575

576+
it("disables the reset button when the slider itself is disabled", () => {
577+
const onReset = vi.fn();
578+
const { host, root } = renderInto(
579+
<FlatSlider
580+
label="Exposure"
581+
value={20}
582+
min={0}
583+
max={100}
584+
tier="explicitCustom"
585+
displayValue="20"
586+
disabled
587+
onReset={onReset}
588+
onCommit={vi.fn()}
589+
/>,
590+
);
591+
const resetButton = host.querySelector<HTMLButtonElement>('[data-flat-slider-reset="true"]');
592+
expect(resetButton?.disabled).toBe(true);
593+
act(() => resetButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
594+
expect(onReset).not.toHaveBeenCalled();
595+
act(() => root.unmount());
596+
});
597+
598+
it("a trailing throttled commit uses the current render's onCommit, not the one captured when it was scheduled", () => {
599+
vi.useFakeTimers();
600+
const onCommitA = vi.fn();
601+
const { host, root } = renderInto(
602+
<FlatSlider
603+
label="Exposure"
604+
value={0}
605+
min={-100}
606+
max={100}
607+
tier="explicitCustom"
608+
displayValue="0"
609+
onCommit={onCommitA}
610+
/>,
611+
);
612+
const track = host.querySelector<HTMLElement>('[data-flat-slider-track="true"]');
613+
if (!track) throw new Error("expected a track element");
614+
Object.defineProperty(track, "getBoundingClientRect", {
615+
value: () => ({ left: 0, width: 200, top: 0, height: 20, right: 200, bottom: 20 }),
616+
});
617+
act(() => {
618+
// Leading-edge commit fires synchronously with onCommitA (clientX 150
619+
// on a -100..100 track maps to 50, distinct from the initial value 0).
620+
track.dispatchEvent(
621+
new PointerEvent("pointerdown", { bubbles: true, clientX: 150, pointerId: 1 }),
622+
);
623+
});
624+
expect(onCommitA).toHaveBeenCalledTimes(1);
625+
act(() => {
626+
// Within the 40ms throttle window — queues a trailing commit (to 80,
627+
// distinct from the just-committed 50) instead of firing immediately.
628+
track.dispatchEvent(
629+
new PointerEvent("pointermove", { bubbles: true, clientX: 180, pointerId: 1 }),
630+
);
631+
});
632+
expect(onCommitA).toHaveBeenCalledTimes(1);
633+
// Simulate the real-world race: something else causes this slider to
634+
// re-render with a NEW onCommit closure before the queued timer fires
635+
// (e.g. Grade's per-detail onCommit spreads the render-time whole
636+
// grading object, so a different control committing in between produces
637+
// a fresh closure). The stale closure must not win.
638+
const onCommitB = vi.fn();
639+
act(() => {
640+
root.render(
641+
<FlatSlider
642+
label="Exposure"
643+
value={0}
644+
min={-100}
645+
max={100}
646+
tier="explicitCustom"
647+
displayValue="0"
648+
onCommit={onCommitB}
649+
/>,
650+
);
651+
});
652+
act(() => {
653+
vi.advanceTimersByTime(45);
654+
});
655+
expect(onCommitB).toHaveBeenCalledTimes(1);
656+
expect(onCommitB).toHaveBeenCalledWith(80);
657+
expect(onCommitA).toHaveBeenCalledTimes(1);
658+
act(() => root.unmount());
659+
vi.useRealTimers();
660+
});
661+
662+
it("flushes a still-queued trailing commit on unmount instead of dropping it", () => {
663+
vi.useFakeTimers();
664+
const onCommit = vi.fn();
665+
const { host, root } = renderInto(
666+
<FlatSlider
667+
label="Opacity"
668+
value={5}
669+
min={0}
670+
max={100}
671+
tier="explicitCustom"
672+
displayValue="5%"
673+
onCommit={onCommit}
674+
/>,
675+
);
676+
const track = host.querySelector<HTMLElement>('[data-flat-slider-track="true"]');
677+
if (!track) throw new Error("expected a track element");
678+
Object.defineProperty(track, "getBoundingClientRect", {
679+
value: () => ({ left: 0, width: 200, top: 0, height: 20, right: 200, bottom: 20 }),
680+
});
681+
act(() => {
682+
track.dispatchEvent(
683+
new PointerEvent("pointerdown", { bubbles: true, clientX: 20, pointerId: 1 }),
684+
);
685+
});
686+
expect(onCommit).toHaveBeenCalledTimes(1);
687+
act(() => {
688+
// Queues a trailing commit that never gets to fire before unmount.
689+
track.dispatchEvent(
690+
new PointerEvent("pointermove", { bubbles: true, clientX: 160, pointerId: 1 }),
691+
);
692+
});
693+
expect(onCommit).toHaveBeenCalledTimes(1);
694+
act(() => root.unmount());
695+
expect(onCommit).toHaveBeenCalledTimes(2);
696+
expect(onCommit).toHaveBeenNthCalledWith(2, 80);
697+
vi.useRealTimers();
698+
});
699+
557700
it("supports keyboard operation: focusable, arrow keys step, Home/End clamp to range", () => {
558701
const onCommit = vi.fn();
559702
const { host, root } = renderInto(
@@ -728,6 +871,31 @@ describe("FlatSelectRow — label/value options", () => {
728871
expect(options).toEqual(["normal", "multiply", "screen"]);
729872
act(() => root.unmount());
730873
});
874+
875+
it("preserves a valid authored value outside the preset list instead of misrepresenting it as the first option", () => {
876+
const onChange = vi.fn();
877+
const { host, root } = renderInto(
878+
<FlatSelectRow
879+
label="Blend"
880+
value="difference"
881+
options={["normal", "multiply", "screen", "overlay"]}
882+
tier="explicitCustom"
883+
onChange={onChange}
884+
/>,
885+
);
886+
const select = host.querySelector<HTMLSelectElement>("select");
887+
// A native <select> whose `value` matches no <option> falls back to
888+
// selectedIndex 0 — silently showing "normal" as selected even though
889+
// the real persisted value is "difference". The row must add an option
890+
// for the current value so it's genuinely representable.
891+
expect(select?.value).toBe("difference");
892+
const options = Array.from(host.querySelectorAll("option")).map((o) => o.textContent);
893+
expect(options).toContain("difference");
894+
// And reselecting the (still-present) first preset must be an explicit
895+
// user choice, not something that already happened silently.
896+
expect(onChange).not.toHaveBeenCalled();
897+
act(() => root.unmount());
898+
});
731899
});
732900

733901
describe("FlatToggle", () => {

0 commit comments

Comments
 (0)