Skip to content

Commit 86ead17

Browse files
committed
fix(core): resolve sub-composition start time through data-composition-file
createRuntimeStartTimeResolver's walk-up-to-host fallback (for an inner root with no data-start of its own) only recognized a host carrying data-composition-src or data-composition-id. Once inlining strips data-composition-src and replaces it with data-composition-file, an anonymous host (no data-composition-id of its own) matched neither check, so the walk-up silently failed and the composition's own timeline got seeked using its start time as the fallback (0) instead of the host's real data-start. This surfaced once the previous commit restored data-composition-id onto the flattened wrapper for anonymous hosts: the composition's self-query started resolving to that wrapper, but resolveStartForElement still couldn't find its actual mount time through the host, so any composition with real entrance/exit animation timing rendered stuck at t=0 (visually: missing or frozen at its hidden initial state) instead of at the correct point in its own timeline.
1 parent 86d3693 commit 86ead17

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎packages/core/src/runtime/startResolver.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,39 @@ describe("createRuntimeStartTimeResolver", () => {
178178
expect(resolver.resolveStartForElement(video)).toBe(54);
179179
});
180180

181+
it("walks up to the host's data-start when the inner root has none (host has its own data-composition-id)", () => {
182+
const host = document.createElement("div");
183+
host.setAttribute("data-composition-id", "montage");
184+
host.setAttribute("data-start", "10");
185+
document.body.appendChild(host);
186+
187+
const innerRoot = document.createElement("div");
188+
innerRoot.setAttribute("data-composition-id", "scene-10");
189+
host.appendChild(innerRoot);
190+
191+
const resolver = createRuntimeStartTimeResolver({});
192+
expect(resolver.resolveStartForElement(innerRoot)).toBe(10);
193+
});
194+
195+
it("walks up to the host's data-start via data-composition-file (anonymous host, post-inlining)", () => {
196+
// A host mounted via data-composition-src with no data-composition-id of
197+
// its own. After inlining, data-composition-src is stripped and replaced
198+
// with data-composition-file, and the composition's own id is restored
199+
// onto the wrapper (which has no data-start of its own).
200+
const host = document.createElement("div");
201+
host.setAttribute("data-composition-file", "compositions/reveal1.html");
202+
host.setAttribute("data-start", "4.619");
203+
document.body.appendChild(host);
204+
205+
const wrapper = document.createElement("div");
206+
wrapper.setAttribute("data-composition-id", "reveal1");
207+
wrapper.setAttribute("data-hf-inner-root", "true");
208+
host.appendChild(wrapper);
209+
210+
const resolver = createRuntimeStartTimeResolver({});
211+
expect(resolver.resolveStartForElement(wrapper)).toBe(4.619);
212+
});
213+
181214
it("keeps nested references in the host composition timeline", () => {
182215
const host = document.createElement("div");
183216
host.id = "slide-5";

‎packages/core/src/runtime/startResolver.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,20 @@ export function createRuntimeStartTimeResolver(params: {
161161
// If this element is a loaded composition inner root (has data-composition-id
162162
// but no data-start), walk up to the host parent which carries the actual
163163
// timing. This happens when the host uses a different data-composition-id
164-
// than the loaded file — e.g. host="montage" but file has "scene-10".
165-
// Check both data-composition-src (runtime) and data-composition-id (bundled,
166-
// where data-composition-src is stripped after inlining).
164+
// than the loaded file — e.g. host="montage" but file has "scene-10", or
165+
// when the host itself has no data-composition-id at all (an "anonymous"
166+
// host) and the composition's own id was restored onto the inlined wrapper.
167+
// Check data-composition-src (runtime, not yet inlined), data-composition-id
168+
// (bundled/compiled host with its own id), and data-composition-file (the
169+
// marker every inlined host gets, compiled or bundled, once
170+
// data-composition-src is stripped — covers the anonymous-host case).
167171
if (element.hasAttribute("data-composition-id")) {
168172
const parent = element.parentElement;
169173
if (
170174
parent &&
171175
(parent.hasAttribute("data-composition-src") ||
172-
parent.hasAttribute("data-composition-id"))
176+
parent.hasAttribute("data-composition-id") ||
177+
parent.hasAttribute("data-composition-file"))
173178
) {
174179
const parentStart = resolveStartForElementInternal(parent, fallback);
175180
startCache.set(element, parentStart);

0 commit comments

Comments
 (0)