Skip to content

Commit adf9b0c

Browse files
committed
fix(studio): activate a composition at any path, not just compositions/
The Comps panel sets activeCompositionPath to the selected file, but useCompositionStack's effect only pushed a stack level when that path started with compositions/. A project laying its comps out anywhere else, for example a generated multi-part build with parts/part-1.html next to the root index.html, matched no branch at all: the row highlighted and the URL hash updated while the stack silently kept the master mounted, so the canvas and timeline stayed on index.html and any edit landed in the root file instead of the part. Replaced the prefix test with a plain truthiness check, so the root stays on the master level and every other path pushes its own level. Label derivation is unchanged, matching CompositionsTab's own convention.
1 parent af1cb1c commit adf9b0c

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

‎packages/studio/src/components/nle/useCompositionStack.test.tsx‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,72 @@ describe("useCompositionStack — project scoping", () => {
4242
});
4343
}
4444
});
45+
46+
describe("useCompositionStack — activating a composition by path", () => {
47+
afterEach(() => {
48+
document.body.innerHTML = "";
49+
});
50+
51+
function mountStack(activeCompositionPath: string | null) {
52+
const host = document.createElement("div");
53+
document.body.append(host);
54+
const root = createRoot(host);
55+
const seen: { stack: ReturnType<typeof useCompositionStack>["compositionStack"] } = {
56+
stack: [],
57+
};
58+
59+
function Harness(props: { activeCompositionPath: string | null }) {
60+
seen.stack = useCompositionStack({ projectId: "p", ...props }).compositionStack;
61+
return null;
62+
}
63+
64+
return { root, seen, Harness, activeCompositionPath };
65+
}
66+
67+
// The root stays on the master level; everything else pushes a second level.
68+
for (const path of [
69+
"compositions/scene-a.html",
70+
"parts/part-1.html",
71+
"chapter-2.html",
72+
"a/b/c/deep.html",
73+
]) {
74+
it(`pushes a level for ${path}`, async () => {
75+
const { root, seen, Harness } = mountStack(path);
76+
77+
await act(async () => {
78+
root.render(<Harness activeCompositionPath={path} />);
79+
});
80+
81+
expect(seen.stack).toHaveLength(2);
82+
expect(seen.stack[1]?.id).toBe(path);
83+
expect(seen.stack[1]?.previewUrl).toBe(`/api/projects/p/preview/comp/${path}`);
84+
85+
act(() => root.unmount());
86+
});
87+
}
88+
89+
it("labels a non-compositions/ path without mangling it", async () => {
90+
const { root, seen, Harness } = mountStack("parts/part-1.html");
91+
92+
await act(async () => {
93+
root.render(<Harness activeCompositionPath="parts/part-1.html" />);
94+
});
95+
96+
expect(seen.stack[1]?.label).toBe("parts/part-1");
97+
98+
act(() => root.unmount());
99+
});
100+
101+
it("keeps the master alone for the root composition", async () => {
102+
const { root, seen, Harness } = mountStack("index.html");
103+
104+
await act(async () => {
105+
root.render(<Harness activeCompositionPath="index.html" />);
106+
});
107+
108+
expect(seen.stack).toHaveLength(1);
109+
expect(seen.stack[0]?.id).toBe("master");
110+
111+
act(() => root.unmount());
112+
});
113+
});

‎packages/studio/src/components/nle/useCompositionStack.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,21 @@ export function useCompositionStack({
108108
if (activeCompositionPath === "index.html") {
109109
usePlayerStore.getState().setElements([]);
110110
updateCompositionStack([master]);
111-
} else if (activeCompositionPath && activeCompositionPath.startsWith("compositions/")) {
111+
} else if (activeCompositionPath) {
112+
// Any composition file that isn't the root, wherever it lives. Gating
113+
// this on a `compositions/` prefix meant a project laying its comps out
114+
// anywhere else (`parts/part-1.html`, generated multi-part builds) hit
115+
// no branch at all: the stack kept the master mounted while the Comps
116+
// panel highlighted the row, so the canvas and timeline stayed on
117+
// index.html and edits landed in the root file.
112118
const label = activeCompositionPath.replace(/^compositions\//, "").replace(/\.html$/, "");
113119
const previewUrl = `/api/projects/${projectId}/preview/comp/${encodePreviewPath(activeCompositionPath)}`;
114120
usePlayerStore.getState().setElements([]);
115121
updateCompositionStack((prev) => {
116122
if (prev[prev.length - 1]?.id === activeCompositionPath) return prev;
117123
return [master, { id: activeCompositionPath, label, previewUrl }];
118124
});
119-
} else if (!activeCompositionPath) {
125+
} else {
120126
usePlayerStore.getState().setElements([]);
121127
updateCompositionStack([master]);
122128
}

0 commit comments

Comments
 (0)