Skip to content

Commit b6509b1

Browse files
authored
fix(Popover): the touch growth shows its content from its first frame (#10757)
fix(Popover): the touch growth shows its content from its first frame Chromium skips drawing a layer at exactly opacity 0 as its animation starts. Under a finger, Popover's growth faded in from 0, so Chromium rasterized the popover again once the fade made it visible, and the first frames showed it without its content. The growth now fades in from opacity 0.001, a quarter of one step of an 8-bit channel: Chromium draws its first frame, and no pixel changes. The floor is defined once, in motion/opacityFloor.ts, for compositor entrances that fade in from transparent. The start values keep opacity 0, so Reduce Motion, which replaces the growth with a cross-fade, still fades in from transparent. A new proof reads the compositor's record of each frame it presents: the growth shows its content from its first frames, also with a tap outside while it grows. component:Popover records the floor as PR5.
1 parent 1f9ac71 commit b6509b1

7 files changed

Lines changed: 143 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Under a finger, Popover's growth shows its content from its first frame. The growth starts at opacity 0.001 rather than 0: Chromium skips drawing a layer at exactly 0, so the first frames of a growth from 0 showed the popover without its content. No 8-bit pixel differs from transparent at 0.001.
6+
7+
@vjeux

‎docs/specs/components/Popover/Popover.spec.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ verified_by:
1717
packages/core/src/Popover/usePopover.doc.mjs,
1818
packages/core/src/hooks/useFocusTrap.test.tsx,
1919
packages/core/src/Popover/PopoverPresentation.test.tsx,
20+
packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts,
2021
packages/cli/foundation/discovery/theming-targets.mjs,
2122
packages/cli/foundation/discovery/theming-targets.test.mjs,
2223
scripts/check-knowledge.mjs,
@@ -267,6 +268,10 @@ table owns their semantic effect.
267268
touch growth and shrink do no Layout or Paint per frame. Known platform cost:
268269
in Chromium, a page with its own `requestAnimationFrame` loop makes an
269270
anchored, animating layer lay out and paint every frame.
271+
- **PR5 — The touch growth's first frames.** Under a finger, the growth starts
272+
at opacity 0.001 rather than 0, since Chromium skips drawing a layer at
273+
exactly 0. The first frame then shows its content, and no 8-bit pixel differs
274+
from transparent.
270275

271276
## Accessibility contract
272277

@@ -373,6 +378,7 @@ consumers that need distinct theme reachability provide and document an owned
373378
| FR8 | `Popover.test.tsx` surface-padding suite | Default rung, `0`, an explicit rung, a direct hook composition with and without a rung | A default other than step 3, a rung landing on a box inside the surface, or the hook painting a rung it was not given fails the suite. | `audit:Popover/theming` |
374379
| FR9 | `spec:AST-094` verification for FR31 and FR35 | Under a finger: open, close, a touch during growth; a mouse | A Popover that does not grow from and shrink into its trigger, a changed dismissal, or a changed mouse path fails. | `audit:Popover/behavior` |
375380
| PR4 | `spec:AST-094` verification for FR5 | The touch growth and shrink in a Chromium trace, on a page with no other frame work | A Layout or a Paint during either motion on such a page | `audit:Popover/resources` |
381+
| PR5 | `PopoverTouchMotion.interaction.browser.spec.ts` "the growth shows its content from its first frames", from the compositor's record of each frame it presents (Chromium) | A tap that opens the popover; a tap outside while it grows | A growth whose first opacity keyframe is 0 presents a frame without the popover's content among its first five | `audit:Popover/resources` |
376382
| FR5 | `Popover.test.tsx` scheduling and observer-lifecycle suites | Closed, opened, repeated signals, cleanup | Constructing observers while closed or measuring more than once per pending frame fails lifecycle assertions. | `audit:Popover/resources` |
377383
| FR6, FR7 and theming anatomy | `Popover.test.tsx`, `Popover.doc.mjs`, `usePopover.doc.mjs`, `astryx theme targets Popover --json`, and `scripts/check-knowledge.mjs` | One real surface with canonical `popover` plus composed-component refinements | A fake anatomy part, missing canonical output, or an active target without a real owner fails review or validation. | `audit:Popover/theming` |
378384
| AR5 | `Popover.stories.tsx` manual-AT fixture and PR #5373 test record | Read-only dialog manual-AT fixture; no recorded NVDA/VoiceOver announcement result | A fixture without recorded AT/browser observations cannot be cited as announcement proof. | `audit:Popover/at-evidence` |

‎packages/core/src/Popover/__tests__/PopoverTouchMotion.interaction.browser.spec.ts‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,98 @@ test('the task that opens it lays out no more than a mouse opening does: the pre
903903
}
904904
});
905905

906+
/**
907+
* The frames the compositor presents while `body` runs and for `ms` after it,
908+
* in order. Each says whether the frame was presented with content missing: a
909+
* tile not yet rasterized. It reads the compositor's own record of each frame
910+
* (`PipelineReporter`), so it is Chromium-only.
911+
*/
912+
async function presentedFrames(
913+
page: Page,
914+
body: () => Promise<unknown>,
915+
ms: number,
916+
): Promise<{sequence: number; missingContent: boolean}[]> {
917+
const cdp = await page.context().newCDPSession(page);
918+
const events: {name: string; ph?: string; args?: Record<string, unknown>}[] =
919+
[];
920+
cdp.on('Tracing.dataCollected', ({value}) => {
921+
events.push(...(value as unknown as typeof events));
922+
});
923+
const complete = new Promise<void>(resolve =>
924+
cdp.once('Tracing.tracingComplete', () => resolve()),
925+
);
926+
await cdp.send('Tracing.start', {
927+
transferMode: 'ReportEvents',
928+
traceConfig: {
929+
includedCategories: [
930+
'cc',
931+
'benchmark',
932+
'viz',
933+
'disabled-by-default-devtools.timeline.frame',
934+
],
935+
excludedCategories: ['*'],
936+
},
937+
});
938+
await body();
939+
await page.waitForTimeout(ms);
940+
await cdp.send('Tracing.end');
941+
await complete;
942+
await cdp.detach();
943+
const frames = new Map<number, boolean>();
944+
for (const event of events) {
945+
const report = (
946+
event.args as {frame_reporter?: Record<string, unknown>} | undefined
947+
)?.frame_reporter;
948+
if (
949+
event.name !== 'PipelineReporter' ||
950+
event.ph === 'e' ||
951+
report == null ||
952+
!String(report.state).includes('PRESENTED')
953+
) {
954+
continue;
955+
}
956+
frames.set(
957+
Number(report.frame_sequence),
958+
report.has_missing_content === true,
959+
);
960+
}
961+
return [...frames.entries()]
962+
.sort(([a], [b]) => a - b)
963+
.map(([sequence, missingContent]) => ({sequence, missingContent}));
964+
}
965+
966+
for (const tapOutside of [false, true]) {
967+
test(`the growth shows its content from its first frames${
968+
tapOutside ? ', with a tap outside while it grows' : ''
969+
}`, async ({page, browserName}) => {
970+
test.skip(
971+
browserName !== 'chromium',
972+
'the compositor frame record is Chromium-only',
973+
);
974+
const story = await openDefault(page);
975+
const outside = outsidePoint(page);
976+
const frames = await presentedFrames(
977+
page,
978+
async () => {
979+
await story.driver.tap(story.center);
980+
if (tapOutside) {
981+
await story.driver.tap(outside);
982+
}
983+
},
984+
700,
985+
);
986+
// Chromium does not draw a layer at opacity 0. A growth that started
987+
// there showed its first frames without its content.
988+
const first = frames.slice(0, 5);
989+
expect(first, 'frames presented').toHaveLength(5);
990+
expect(
991+
first.filter(frame => frame.missingContent).map(frame => frame.sequence),
992+
'first frames presented with content missing',
993+
).toEqual([]);
994+
await expect(story.trigger).toHaveAttribute('aria-expanded', 'true');
995+
});
996+
}
997+
906998
test('a style read after the opening tap finds no CSS entrance running on the layer', async ({
907999
page,
9081000
}) => {

‎packages/core/src/Popover/popoverSurfaceMotion.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
1717
import {isInHeldLayer, isInputShield} from '../Layer/inputHold';
1818
import {cubicBezier} from '../motion/bezier';
19+
import {ENTRANCE_OPACITY_FLOOR} from '../motion/opacityFloor';
1920
import {parseCssEasing, parseMotionRoleValue} from '../motion/roles';
2021
import {popover, timing} from '../motion/uikit';
2122
import {findPopoverExitCopy} from '../privateAttributes/popoverExit.stylex';
@@ -370,8 +371,11 @@ describe('createPopoverSurfaceMotion', () => {
370371
expect(endMs).toBeLessThanOrEqual(ENTRANCE.ms + 1);
371372
expect(endMs).toBeGreaterThan(ENTRANCE.ms * 0.8);
372373
expect(peak).toBeLessThanOrEqual(1);
374+
// It starts at the floor, not at 0: Chromium draws the start frame.
373375
const [opacityAnimation] = live('opacity');
374-
expect(Number(opacityAnimation.keyframes[0].opacity)).toBe(0);
376+
expect(Number(opacityAnimation.keyframes[0].opacity)).toBe(
377+
ENTRANCE_OPACITY_FLOOR,
378+
);
375379
expect(Number(opacityAnimation.keyframes.at(-1)!.opacity)).toBe(1);
376380
});
377381

‎packages/core/src/Popover/popoverSurfaceMotion.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type MotionHandle,
2828
} from '../motion/animator';
2929
import {holdInput} from '../Layer/inputHold';
30+
import {ENTRANCE_OPACITY_FLOOR} from '../motion/opacityFloor';
3031
import {mapProgress, mapRange} from '../motion/progress';
3132
import {
3233
easedProgress,
@@ -62,18 +63,20 @@ function surfaceCurves(
6263
to: SurfaceState,
6364
axis: 'x' | 'y',
6465
progress: MotionCurve,
66+
opacityFloor = 0,
6567
): Record<'scaleX' | 'scaleY' | 'opacity', MotionCurve> {
6668
// Unclamped, so an easing that overshoots carries the channels with it.
6769
const lerp = (a: number, b: number) =>
6870
mapRange([0, 1], [a, b], {clamp: false});
6971
const scale = lerp(from.scale, to.scale);
7072
const length = lerp(from.length, to.length);
73+
const opacity = lerp(from.opacity, to.opacity);
7174
const across = mapProgress(progress, scale);
7275
const along = mapProgress(progress, p => scale(p) * length(p));
7376
return {
7477
scaleX: axis === 'x' ? along : across,
7578
scaleY: axis === 'y' ? along : across,
76-
opacity: mapProgress(progress, lerp(from.opacity, to.opacity)),
79+
opacity: mapProgress(progress, p => Math.max(opacityFloor, opacity(p))),
7780
};
7881
}
7982

@@ -308,8 +311,17 @@ export function createPopoverSurfaceMotion(
308311
'transform-origin',
309312
`${next.originX}px ${next.originY}px`,
310313
);
314+
// The growth fades in from the floor, so Chromium draws its first frame.
315+
// The start values keep opacity 0. Reduce Motion replaces this curve with a
316+
// cross-fade, which then starts from transparent.
311317
const handle = animator.play(
312-
surfaceCurves(start, PRESENTED, next.axis, timing),
318+
surfaceCurves(
319+
start,
320+
PRESENTED,
321+
next.axis,
322+
timing,
323+
ENTRANCE_OPACITY_FLOOR,
324+
),
313325
);
314326
presentHandle = handle;
315327
endHold();

‎packages/core/src/motion/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ roles through `resolveMotion`.
4848
| `progress.ts` | A spring's progress, one curve mapped from another (companions, clamped ranges), the velocity that continues a motion. |
4949
| `presentation.ts` | Where each moving element is drawn relative to where the engine hit-tests it, reported by the animator while translate runs; read by the gesture host at touch-down. |
5050
| `reducedMotionPlan.ts` | The animator's Reduce Motion planner: what one call becomes, a cross-fade whose travel lands while transparent or at once. |
51+
| `opacityFloor.ts` | The lowest opacity a compositor entrance fades in from: Chromium skips drawing a layer at exactly 0 as its animation starts. |
5152
| `__tests__/animator.interaction.browser.spec.ts` | Browser proofs on the interaction harness (Chromium and WebKit): busy main thread, end state through a block, no Layout / Paint, seeked curves, a dialog's backdrop. |
5253

5354
Component-specific values (a sheet's detents, a switch's geometry, a context
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file opacityFloor.ts
5+
* @input None
6+
* @output Exports `ENTRANCE_OPACITY_FLOOR`
7+
* @position A motion constant for entrances that fade in from transparent as
8+
* Web Animations
9+
*
10+
* Chromium skips drawing a layer at exactly opacity 0 as its animation starts.
11+
* It rasterizes the layer again once the fade makes it visible, so the first
12+
* frames show the layer without its content. An entrance that fades in from
13+
* this floor draws its start frame. The floor is a quarter of one step of an
14+
* 8-bit channel, so it changes no pixel.
15+
*/
16+
17+
/** The lowest opacity a compositor entrance fades in from. */
18+
export const ENTRANCE_OPACITY_FLOOR = 0.001;

0 commit comments

Comments
 (0)