Skip to content

Commit c1fcf75

Browse files
committed
fix(studio): clear stale color scopes
1 parent 20ef48a commit c1fcf75

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ export function PropertyPanelColorScopes({
189189
});
190190

191191
useEffect(() => {
192-
if (analysis && canvasRef.current) drawScope(canvasRef.current, mode, analysis);
192+
const canvas = canvasRef.current;
193+
if (!canvas) return;
194+
if (analysis) {
195+
drawScope(canvas, mode, analysis);
196+
return;
197+
}
198+
const context = canvas.getContext("2d");
199+
if (context) drawGrid(context, canvas.width, canvas.height);
193200
}, [analysis, mode]);
194201

195202
return (

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function Harness({
2727
return (
2828
<>
2929
<span data-status>{scopes.status}</span>
30+
<span data-analysis>{scopes.analysis ? "ready" : "empty"}</span>
3031
<button type="button" onClick={scopes.refresh}>
3132
Refresh
3233
</button>
@@ -104,4 +105,39 @@ describe("useColorGradingScopes", () => {
104105
expect(host.querySelector("[data-status]")?.textContent).toBe("unavailable");
105106
act(() => root.unmount());
106107
});
108+
109+
it("clears stale analysis while a refresh is pending and when it is unavailable", async () => {
110+
vi.useFakeTimers();
111+
installPixelDecode();
112+
let resolveRefresh: (frame: ColorGradingCapturedFrame | null) => void = () => {};
113+
const pendingRefresh = new Promise<ColorGradingCapturedFrame | null>((resolve) => {
114+
resolveRefresh = resolve;
115+
});
116+
const captureFrame = vi
117+
.fn()
118+
.mockResolvedValueOnce({
119+
dataUrl: "data:image/png;base64,scope",
120+
width: 1,
121+
height: 1,
122+
})
123+
.mockReturnValueOnce(pendingRefresh);
124+
const host = document.body.appendChild(document.createElement("div"));
125+
const root = createRoot(host);
126+
act(() => root.render(<Harness open refreshKey="a" captureFrame={captureFrame} />));
127+
128+
await act(async () => vi.advanceTimersByTimeAsync(180));
129+
expect(host.querySelector("[data-analysis]")?.textContent).toBe("ready");
130+
131+
act(() => {
132+
host.querySelector("button")?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
133+
});
134+
act(() => vi.advanceTimersByTime(180));
135+
expect(host.querySelector("[data-status]")?.textContent).toBe("loading");
136+
expect(host.querySelector("[data-analysis]")?.textContent).toBe("empty");
137+
138+
await act(async () => resolveRefresh(null));
139+
expect(host.querySelector("[data-status]")?.textContent).toBe("unavailable");
140+
expect(host.querySelector("[data-analysis]")?.textContent).toBe("empty");
141+
act(() => root.unmount());
142+
});
107143
});

‎packages/studio/src/components/editor/useColorGradingScopes.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ export function useColorGradingScopes({
2626

2727
useEffect(() => {
2828
if (!open) {
29+
setAnalysis(null);
2930
setStatus("idle");
3031
return;
3132
}
3233
let cancelled = false;
3334
const timer = window.setTimeout(async () => {
35+
setAnalysis(null);
3436
setStatus("loading");
3537
try {
3638
const frame = await captureRef.current();

0 commit comments

Comments
 (0)