Skip to content

Commit d5c7d3e

Browse files
committed
fix(studio): preserve composed media treatments
1 parent 39c2341 commit d5c7d3e

3 files changed

Lines changed: 54 additions & 17 deletions

File tree

‎packages/studio/src/components/editor/useColorGradingController.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,27 @@ describe("useColorGradingController", () => {
490490
vi.useRealTimers();
491491
});
492492

493-
it("resetGrading returns to the neutral preset", () => {
493+
it("resetGrading resets Grade fields without clearing Effects or Palette", () => {
494494
const { root, getState } = renderHook(vi.fn());
495+
const grading = normalizeHfColorGrading({
496+
preset: "bright-pop",
497+
lut: { src: "assets/luts/custom.cube", intensity: 0.6 },
498+
effects: { pixelate: 0.5 },
499+
palette: ["#112233", "#ffffff"],
500+
});
501+
if (!grading) throw new Error("expected grading to normalize");
495502
act(() => {
496-
getState().commitColorGrading(brightPopGrading());
503+
getState().commitColorGrading(grading);
497504
});
498505
act(() => {
499506
getState().resetGrading();
500507
});
501-
expect(getState().grading.preset).toBe("neutral");
508+
expect(getState().grading).toMatchObject({
509+
preset: "neutral",
510+
lut: null,
511+
effects: { pixelate: 0.5 },
512+
palette: ["#112233", "#ffffff"],
513+
});
502514
act(() => root.unmount());
503515
});
504516

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ export function useColorGradingController({
542542
commitCompare,
543543
setApplyScope,
544544
applyToScope,
545-
resetGrading: () => commitColorGrading(defaultColorGrading()),
545+
resetGrading: () => {
546+
const neutral = defaultColorGrading();
547+
commitColorGrading({
548+
...neutral,
549+
effects: latestGradingRef.current.effects,
550+
palette: latestGradingRef.current.palette,
551+
});
552+
},
546553
};
547554
}

‎packages/studio/src/hooks/useBlockCatalog.ts‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,51 @@ import {
66
resolveBlockCategory,
77
} from "../utils/blockCategories";
88

9-
export type CatalogItem = RegistryItem & {
9+
type CatalogItem = RegistryItem & {
1010
category: BlockCategory;
1111
};
1212

13+
let catalogCache: CatalogItem[] | null = null;
14+
let catalogRequest: Promise<CatalogItem[]> | null = null;
15+
16+
function loadCatalog(): Promise<CatalogItem[]> {
17+
catalogRequest ??= fetch("/api/registry/blocks")
18+
.then((response) => {
19+
if (!response.ok) throw new Error("Failed to load catalog");
20+
return response.json() as Promise<RegistryItem[]>;
21+
})
22+
.then((items) => {
23+
catalogCache = items
24+
.map((item) => ({ ...item, category: resolveBlockCategory(item.tags) }))
25+
.sort((a, b) => {
26+
const aIndex = BLOCK_CATEGORIES.findIndex((category) => category.id === a.category);
27+
const bIndex = BLOCK_CATEGORIES.findIndex((category) => category.id === b.category);
28+
return (aIndex === -1 ? 99 : aIndex) - (bIndex === -1 ? 99 : bIndex);
29+
});
30+
return catalogCache;
31+
})
32+
.catch((error: unknown) => {
33+
catalogRequest = null;
34+
throw error;
35+
});
36+
return catalogRequest;
37+
}
38+
1339
export function useBlockCatalog() {
14-
const [blocks, setBlocks] = useState<CatalogItem[]>([]);
15-
const [loading, setLoading] = useState(true);
40+
const [blocks, setBlocks] = useState<CatalogItem[]>(() => catalogCache ?? []);
41+
const [loading, setLoading] = useState(catalogCache === null);
1642
const [error, setError] = useState<string | null>(null);
1743
const [search, setSearch] = useState("");
1844
const [category, setCategory] = useState<BlockCategory | null>(null);
1945

2046
// fallow-ignore-next-line complexity
2147
useEffect(() => {
48+
if (catalogCache) return;
2249
let cancelled = false;
2350
(async () => {
2451
try {
25-
const res = await fetch("/api/registry/blocks");
26-
if (!res.ok) throw new Error("Failed to load catalog");
27-
const data = (await res.json()) as RegistryItem[];
52+
const items = await loadCatalog();
2853
if (cancelled) return;
29-
const items = data
30-
.map((b) => ({ ...b, category: resolveBlockCategory(b.tags) }))
31-
.sort((a, b) => {
32-
const ia = BLOCK_CATEGORIES.findIndex((c) => c.id === a.category);
33-
const ib = BLOCK_CATEGORIES.findIndex((c) => c.id === b.category);
34-
return (ia === -1 ? 99 : ia) - (ib === -1 ? 99 : ib);
35-
});
3654
setBlocks(items);
3755
} catch (err) {
3856
if (cancelled) return;

0 commit comments

Comments
 (0)