diff --git a/packages/core/src/runtime/init.test.ts b/packages/core/src/runtime/init.test.ts index c2657f3d6a..93c9911528 100644 --- a/packages/core/src/runtime/init.test.ts +++ b/packages/core/src/runtime/init.test.ts @@ -5755,6 +5755,23 @@ describe("initSandboxRuntimeModular", () => { expect(card.style.height).toBe("100%"); }); + it("leaves a still-loading image at its own size instead of filling the frame", () => { + const root = makeRoot(); + const logo = document.createElement("img"); + logo.setAttribute("data-start", "0"); + logo.setAttribute("data-duration", "5"); + logo.style.width = "340px"; + root.appendChild(logo); + // Before its file loads, a width-only measures 0px tall. + modelBrowserLayout(logo, { width: "340px", height: "0px" }); + + window.__timelines = { main: createMockTimeline(10) }; + initSandboxRuntimeModular(); + + expect(logo.style.height).toBe(""); + expect(logo.style.width).toBe("340px"); + }); + it("puts back an author's display:none !important after measuring the clip", () => { const root = makeRoot(); const card = document.createElement("div"); diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index 28a1ea4638..8bb1b1c231 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -1027,6 +1027,7 @@ export function initSandboxRuntimeModular(): void { el.style.position = "absolute"; } if (tag !== "audio") { + const sizedByItsFile = tag === "img"; const forcedWidth = parseDimensionPx(el.getAttribute("data-width")); const forcedHeight = parseDimensionPx(el.getAttribute("data-height")); const hasMeaningfulComputedWidth = computed.width !== "0px" && computed.width !== "auto"; @@ -1035,14 +1036,14 @@ export function initSandboxRuntimeModular(): void { if (!el.style.width && !hasMeaningfulComputedWidth) { el.style.width = forcedWidth; } - } else if (!el.style.width && computed.width === "0px") { + } else if (!sizedByItsFile && !el.style.width && computed.width === "0px") { el.style.width = "100%"; } if (forcedHeight) { if (!el.style.height && !hasMeaningfulComputedHeight) { el.style.height = forcedHeight; } - } else if (!el.style.height && computed.height === "0px") { + } else if (!sizedByItsFile && !el.style.height && computed.height === "0px") { el.style.height = "100%"; } }