From ba62d7748943f2a2cb89e091a9ee50dd95d41489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 17 Nov 2026 21:36:28 +0000 Subject: [PATCH] fix(studio): the edit bench waits out the preview swap once a plain element gains keyframes (#8113) --- .../studio/tests/e2e/edit-accuracy/case.mjs | 4 ++- .../tests/e2e/edit-accuracy/ratchet.mjs | 12 +------ .../tests/e2e/edit-accuracy/sequences.mjs | 8 +++++ .../tests/e2e/edit-accuracy/settle.test.mjs | 34 ++++++++++++++++++- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/packages/studio/tests/e2e/edit-accuracy/case.mjs b/packages/studio/tests/e2e/edit-accuracy/case.mjs index 4d3d64af1a..727a7e5fe6 100644 --- a/packages/studio/tests/e2e/edit-accuracy/case.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/case.mjs @@ -315,7 +315,9 @@ const previewFrames = (page) => async function hiddenTarget(page, selector = "#target") { for (const f of page.frames().filter((f) => f.url().includes("/preview"))) { const host = await f.frameElement().catch(() => null); - const shown = await host?.evaluate((e) => e.checkVisibility({ visibilityProperty: true })); + const shown = await host + ?.evaluate((e) => e.checkVisibility({ visibilityProperty: true })) + .catch(() => null); if (shown === false && (await f.$(selector).catch(() => null))) return true; } return false; diff --git a/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs b/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs index 9adc2c22e3..99ab1efe6f 100644 --- a/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs @@ -55,17 +55,7 @@ export function bankable(runs) { * Cases a real Studio race flips run to run, with the PR fixing it: measured and listed every run, never gated. * The fixing PR deletes its own ids here and re-banks them in the same PR. */ -export const QUARANTINED = { - // Undo or redo of a keyframed plain element restores the bytes but sometimes leaves the box 230-400px off. - "seqplainkeys-none-center-r0-nested-z100": "#6989", - "seqplainkeys-none-center-r0-root-z100": "#6989", - "seqplainkeys-none-center-r30-root-z100": "#6989", - "seqplainkeys-none-pct-r0-root-z100": "#6989", - "seqplainkeys-none-pct-r30-root-z100": "#6989", - "seqplainkeys-none-px-r0-nested-z100": "#6989", - "seqplainkeys-none-px-r30-nested-z100": "#6989", - "seqplainkeys-none-px-r30-root-z100": "#6989", -}; +export const QUARANTINED = {}; /** * Every run of every case: each shard's run plus the re-runs of the cases it flipped. `scope`, for a run of diff --git a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs b/packages/studio/tests/e2e/edit-accuracy/sequences.mjs index bb739ec465..b84fb83c60 100644 --- a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/sequences.mjs @@ -423,6 +423,13 @@ function rememberBox(step, state, m) { } /** Under auto-record, size keys hold their nearest value before the first and after the last. */ +/** An element that gains keyframes mid-sequence is keyframed from then on: its settles wait out Studio's swap. */ +export function keyedBy(ctx, step, state) { + const writesKeys = step.do === "addkey" || (step.do === "drag" && state.autokey); + const c = ctx[step.element ?? "A"]; + if (writesKeys && c && !c.keys) c.keys = true; +} + export function heldSize(sizeKeys, time) { const times = [...sizeKeys.keys()].sort((a, b) => a - b); if (!times.length) return undefined; @@ -496,6 +503,7 @@ async function measureSequence({ spec, dir, files, evidence }, session, control, for (const step of spec.steps) { if (step.do !== "drag") await collect(); steps.push(await driveStep(ctx, step, state)); + keyedBy(ctx, step, state); if (spec.settle) await settleStep(ctx.A, steps, step, state, watcher); } // Every saving step saves once (a nudge burst saves once); wait for all of them. An undo may diff --git a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs index 930ba4310f..f284d4779c 100644 --- a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs @@ -12,7 +12,7 @@ import { swapPending, unsettledBy, } from "./case.mjs"; -import { heldSize } from "./sequences.mjs"; +import { heldSize, keyedBy } from "./sequences.mjs"; describe("settling on the shown preview", () => { const read = (pending, x = 0, frames = "a") => ({ @@ -53,6 +53,19 @@ describe("settling on the shown preview", () => { expect(await swapPending({ page: page(frame("/studio", false, true)), keys })).toBe(false); }); + it("reads a preview that went away mid-read as holding nothing, not as an error", async () => { + const gone = { + url: () => "/preview/a?_t=1", + frameElement: async () => ({ + evaluate: async () => { + throw new Error("Attempted to use detached Frame"); + }, + }), + $: async () => ({}), + }; + expect(await swapPending({ page: page(gone), keys })).toBe(false); + }); + it("calls a swap pending while Studio says the preview is changing, with no hidden preview yet", async () => { const changing = (on) => ({ frames: () => [], evaluate: async () => on }); expect(await swapPending({ page: changing(true), keys })).toBe(true); @@ -66,6 +79,25 @@ describe("settling on the shown preview", () => { }); }); +describe("a plain element that gains keyframes mid-sequence", () => { + const changing = { frames: () => [], evaluate: async () => true }; + const plain = () => ({ A: { page: changing }, B: { page: changing } }); + + it("waits out Studio's swap from the step that writes its first keyframe", async () => { + const ctx = plain(); + keyedBy(ctx, { do: "drag" }, { autokey: false }); + expect(await swapPending(ctx.A), "a drag with auto-keyframe off writes none").toBe(false); + keyedBy(ctx, { do: "addkey" }, { autokey: false }); + expect(await swapPending(ctx.A)).toBe(true); + }); + + it("keys the element a drag with auto-keyframe on moved, and only that one", async () => { + const ctx = plain(); + keyedBy(ctx, { do: "drag", element: "B" }, { autokey: true }); + expect([await swapPending(ctx.A), await swapPending(ctx.B)]).toEqual([false, true]); + }); +}); + describe("settling on the page's network", () => { const read = (busy, activity) => ({ pending: false,