From d33508f9caa3ff301162dcf845e57bd4a8b4ec7e Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 30 Nov 2026 09:52:35 -0500 Subject: [PATCH 1/2] Treat --slomo 0 as 0 so reduced motion skips the motion waits Under prefers-reduced-motion propflip.css sets --slomo to 0, but the rail re-form, the hover release and the explorer read it with `|| 1`, so 0 became 1 and they still waited out the full animation. One slomo() in motion/propflip.ts now reads it for every caller, falling back to 1 only when the property is missing. Co-Authored-By: Claude Opus 5.5 --- .../src/components/explorer/explorer.ts | 9 +--- .../starpod/src/components/media/Island.tsx | 8 ++-- packages/starpod/src/layouts/Layout.astro | 10 ++--- packages/starpod/src/motion/propflip.ts | 9 ++++ tests/e2e/shell.spec.ts | 42 +++++++++++++++++++ tests/unit/Island.test.tsx | 2 + 6 files changed, 62 insertions(+), 18 deletions(-) diff --git a/packages/starpod/src/components/explorer/explorer.ts b/packages/starpod/src/components/explorer/explorer.ts index 4fdc89a5..0554deb0 100644 --- a/packages/starpod/src/components/explorer/explorer.ts +++ b/packages/starpod/src/components/explorer/explorer.ts @@ -31,6 +31,7 @@ import { onFlip, registerFlipTargets, reducedMotion, + slomo, type FlipRect } from '../../motion/propflip'; import { readPosition, resumePoint } from '../media/position'; @@ -134,14 +135,6 @@ const ANCHORED = const GLIDE_CLIP = typeof CSS !== 'undefined' && CSS.supports('overflow-clip-margin', '1px'); -function slomo() { - return ( - Number( - getComputedStyle(document.documentElement).getPropertyValue('--slomo') - ) || 1 - ); -} - /** The archive's sizes when it was last live, and what they depend on. */ let lastSize: { key: string; width: string; bar: string } | undefined; const sizeKey = () => diff --git a/packages/starpod/src/components/media/Island.tsx b/packages/starpod/src/components/media/Island.tsx index 1f2b756f..00dce23e 100644 --- a/packages/starpod/src/components/media/Island.tsx +++ b/packages/starpod/src/components/media/Island.tsx @@ -3,7 +3,7 @@ import { computed } from '@preact/signals'; import { createPortal } from 'preact/compat'; import { useLayoutEffect, useRef } from 'preact/hooks'; -import { flip } from '../../motion/propflip'; +import { flip, slomo } from '../../motion/propflip'; import { ArrowOutIcon, BackIcon, @@ -302,9 +302,9 @@ export function go(home: IslandHome) { // Reads happen where flip() has just measured (style and layout clean) and // writes inside its update, so go() forces no layout of its own (bar // WebKit's one read of where the island is going). - let slomo = 0; + let s = 0; const moves = flip([...island.children] as Array, () => { - slomo = parseFloat(getComputedStyle(island).getPropertyValue('--slomo')) || 0; + s = slomo(island); // The cascade runs from the far end on the way back to a smaller home. island.dataset.going = ISLAND_HOMES.indexOf(to) === 1 ? 'out' : 'in'; // Its own tween runs only for the journey (and the rail slot's growth); @@ -325,7 +325,7 @@ export function go(home: IslandHome) { island.style.removeProperty('width'); island.style.removeProperty('height'); syncPage(); - }, 900 * slomo + 50); + }, 900 * s + 50); // Parts at rest take their delay from CSS (sibling-index()); parts already // in flight keep the zero flip() gave them, so an interrupt never freezes. for (const move of moves) { diff --git a/packages/starpod/src/layouts/Layout.astro b/packages/starpod/src/layouts/Layout.astro index b02ad659..ea165195 100644 --- a/packages/starpod/src/layouts/Layout.astro +++ b/packages/starpod/src/layouts/Layout.astro @@ -565,7 +565,7 @@ const publicationLinkTag = // the page re-lays once and glides, and other areas' registered boxes // flip. The toggle, "[", double-click and the arrow keys take the same // glide. Also runs the collapsed rail's travelling tooltip. - import { flipLayout, nudge, reducedMotion } from '../motion/propflip'; + import { flipLayout, nudge, reducedMotion, slomo } from '../motion/propflip'; const root = document.documentElement; const wide = window.matchMedia('(min-width: 1024px)'); @@ -668,15 +668,14 @@ const publicationLinkTag = void getComputedStyle(rail).transitionDuration; delete rail.dataset.anchoring; clearTimeout(reforming); - const slomo = - parseFloat(getComputedStyle(root).getPropertyValue('--slomo')) || 1; + const s = slomo(); const at = ++reformed; requestAnimationFrame(() => requestAnimationFrame(() => { if (at === reformed) { reforming = window.setTimeout( () => delete rail.dataset.reforming, - 760 * slomo + 760 * s ); } }) @@ -1179,8 +1178,7 @@ const publicationLinkTag = apply(); return; } - const slomo = parseFloat(root.style.getPropertyValue('--slomo')) || 1; - hoverRelease.set(el, window.setTimeout(apply, 700 * slomo)); + hoverRelease.set(el, window.setTimeout(apply, 700 * slomo())); } for (const [type, on] of [ ['pointerenter', true], diff --git a/packages/starpod/src/motion/propflip.ts b/packages/starpod/src/motion/propflip.ts index 0c1bcedd..56d189ec 100644 --- a/packages/starpod/src/motion/propflip.ts +++ b/packages/starpod/src/motion/propflip.ts @@ -69,6 +69,15 @@ export function reducedMotion(): boolean { ); } +/** + * The page's `--slomo`, the factor every duration is scaled by: 0 under + * reduced motion (propflip.css), so a wait timed to a transition ends at once. + */ +export function slomo(el: Element = document.documentElement): number { + const s = parseFloat(getComputedStyle(el).getPropertyValue('--slomo')); + return Number.isNaN(s) ? 1 : s; +} + /** The current (possibly mid-transition) values of the four props. */ export function props(el: Element): FlipProps { const cs = getComputedStyle(el); diff --git a/tests/e2e/shell.spec.ts b/tests/e2e/shell.spec.ts index 5397ec52..f9bb6bef 100644 --- a/tests/e2e/shell.spec.ts +++ b/tests/e2e/shell.spec.ts @@ -594,6 +594,48 @@ test.describe('desktop rail', () => { await expect(page.locator(fly)).toBeHidden(); } }); + + // Dragging the divider past the middle re-forms the rail: its pieces leave + // their slots to travel, then settle back. How long they stay out, in ms. + const reformHold = async (page: Page) => { + await page.goto('/'); + await hydrated(page); + await page.evaluate(() => { + const rail = document.querySelector('.rail')!; + const w = window as unknown as { reform: number[] }; + w.reform = []; + new MutationObserver(() => w.reform.push(performance.now())).observe( + rail, + { attributeFilter: ['data-reforming'] } + ); + }); + const y = 450; + await page.mouse.move(await edgeX(page), y); + await page.mouse.down(); + await page.mouse.move(120, y, { steps: 4 }); + await page.waitForFunction( + () => (window as unknown as { reform: number[] }).reform.length >= 2, + undefined, + { timeout: 3000 } + ); + await page.mouse.up(); + const [out, back] = await page.evaluate( + () => (window as unknown as { reform: number[] }).reform + ); + return back! - out!; + }; + + test('a re-form holds its pieces out while they travel', async ({ page }) => { + expect(await reformHold(page)).toBeGreaterThan(600); + }); + + test.describe('with reduced motion', () => { + test.use({ contextOptions: { reducedMotion: 'reduce' } }); + + test('a re-form settles at once', async ({ page }) => { + expect(await reformHold(page)).toBeLessThan(200); + }); + }); }); test.describe('rail popovers', () => { diff --git a/tests/unit/Island.test.tsx b/tests/unit/Island.test.tsx index 941d08e9..536942a6 100644 --- a/tests/unit/Island.test.tsx +++ b/tests/unit/Island.test.tsx @@ -166,6 +166,8 @@ describe('Island', () => { currentEpisode.value = withVideo; const { rerender } = render(); const island = () => document.getElementById('player')!; + // Under reduced motion (propflip.css), so the island lands at once. + island().style.setProperty('--slomo', '0'); const landed = () => new Promise((done) => setTimeout(done, 80)); expect(island()).not.toHaveAttribute('role'); From 680d20c934934968d6f7b06f823fc3a40c52922d Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 30 Nov 2026 14:19:03 -0500 Subject: [PATCH 2/2] Time the rail re-form only in Chromium; unit test slomo() CI failed the new re-form tests in Firefox and WebKit. --slomo reads 0 under reduced motion in all three browsers, but headless WebKit took 560ms for two idle frames and Firefox's hold swung with load, so a wall-clock bound there measured the runner, not the fix. The timing tests now run in Chromium only, and slomo() gets unit tests that fail on the old `|| 1` read. Co-Authored-By: Claude Opus 5.5 --- tests/e2e/shell.spec.ts | 12 ++++++++++-- tests/unit/propflip.test.ts | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/e2e/shell.spec.ts b/tests/e2e/shell.spec.ts index f9bb6bef..d3f58394 100644 --- a/tests/e2e/shell.spec.ts +++ b/tests/e2e/shell.spec.ts @@ -625,14 +625,22 @@ test.describe('desktop rail', () => { return back! - out!; }; - test('a re-form holds its pieces out while they travel', async ({ page }) => { + // Wall-clock holds: headless WebKit and Firefox frame too unevenly (two + // idle frames can take over 500ms) for the reduced-motion bound to mean + // anything there. slomo() itself is unit tested. + test('a re-form holds its pieces out while they travel', async ({ + page, + browserName + }) => { + test.skip(browserName !== 'chromium', 'frame timing is only steady in Chromium'); expect(await reformHold(page)).toBeGreaterThan(600); }); test.describe('with reduced motion', () => { test.use({ contextOptions: { reducedMotion: 'reduce' } }); - test('a re-form settles at once', async ({ page }) => { + test('a re-form settles at once', async ({ page, browserName }) => { + test.skip(browserName !== 'chromium', 'frame timing is only steady in Chromium'); expect(await reformHold(page)).toBeLessThan(200); }); }); diff --git a/tests/unit/propflip.test.ts b/tests/unit/propflip.test.ts index 4f9f629a..9ed0a827 100644 --- a/tests/unit/propflip.test.ts +++ b/tests/unit/propflip.test.ts @@ -2,9 +2,28 @@ import { afterEach, describe, expect, it } from 'vitest'; import { flip, flipLayout, - registerFlipTargets + registerFlipTargets, + slomo } from 'starpod/src/motion/propflip'; +describe('slomo', () => { + afterEach(() => document.documentElement.style.removeProperty('--slomo')); + + it('keeps 0 under reduced motion, so waits timed to transitions end at once', () => { + document.documentElement.style.setProperty('--slomo', '0'); + expect(slomo()).toBe(0); + }); + + it('scales by the page value', () => { + document.documentElement.style.setProperty('--slomo', '2'); + expect(slomo()).toBe(2); + }); + + it('runs at normal speed when nothing sets it', () => { + expect(slomo()).toBe(1); + }); +}); + // A box whose rect is whatever the test says it is right now. function box(rect: { left: number; top: number }, log?: string[], name = '') { const el = document.createElement('div');