From aed30103988820432b881cfe50f2cb3f4afc81f5 Mon Sep 17 00:00:00 2001 From: Ivor Zhou Date: Tue, 10 Nov 2026 17:58:23 -0800 Subject: [PATCH] fix(BottomSheet): a move of a touch drag no longer restyles the sheet's content Each move of a touch drag writes the scrim's opacity on the dialog as a custom property. Only the dialog's backdrop reads it, but the property inherited into the sheet, so the browser restyled every element in the sheet on every move. The panel now ends that inheritance: a move restyles the dialog, its backdrop, the panel and the edge tint. --- .changeset/bottom-sheet-drag-restyle.md | 7 ++ .../core/src/BottomSheet/BottomSheet.test.tsx | 25 ++++ .../core/src/BottomSheet/BottomSheetPanel.tsx | 6 + ...eetDragRestyle.interaction.browser.spec.ts | 111 ++++++++++++++++++ .../core/src/theme/derivedVarRegistry.test.ts | 5 + 5 files changed, 154 insertions(+) create mode 100644 .changeset/bottom-sheet-drag-restyle.md create mode 100644 packages/core/src/BottomSheet/__tests__/BottomSheetDragRestyle.interaction.browser.spec.ts diff --git a/.changeset/bottom-sheet-drag-restyle.md b/.changeset/bottom-sheet-drag-restyle.md new file mode 100644 index 0000000000000..140a7e4ffe540 --- /dev/null +++ b/.changeset/bottom-sheet-drag-restyle.md @@ -0,0 +1,7 @@ +--- +'@astryxdesign/core': patch +--- + +[fix] BottomSheet: a move of a touch drag no longer restyles the sheet's content. Each move writes the scrim's opacity on the dialog as a custom property, and the property inherited into the sheet, so the browser restyled every element in the sheet on every move: 51 elements a move in a Tall sheet with a short list, 84 in PowerSearch's Filters sheet with three filters, and more with more content. The sheet's panel now ends that inheritance, and a move restyles the dialog, its backdrop, the panel and the edge tint. The scrim follows the drag as before. This applies to the sheet that owns the scrim: a single BottomSheet, or the first sheet of a stack, such as PowerSearch's Filters sheet and Tokenizer's sheet. + +@imdreamrunner diff --git a/packages/core/src/BottomSheet/BottomSheet.test.tsx b/packages/core/src/BottomSheet/BottomSheet.test.tsx index 36df17e1fdea1..71f9c84dadcad 100644 --- a/packages/core/src/BottomSheet/BottomSheet.test.tsx +++ b/packages/core/src/BottomSheet/BottomSheet.test.tsx @@ -4927,6 +4927,31 @@ describe('BottomSheet', () => { }); }); + describe('scrim property isolation', () => { + // A drag writes the scrim's opacity on the dialog for each move, and only + // the dialog's backdrop reads it. An inherited custom property restyles + // every element under the one it changes on. jsdom reports the declared + // `initial`. A browser computes no value, which the interaction proof + // BottomSheetDragRestyle covers. + it("declares the dialog's scrim properties `initial` on the sheet panel", () => { + render( + {}} label="Filters"> + Content + , + ); + const dialog = screen.getByRole('dialog', {hidden: true}); + dialog.style.setProperty('--_sheet-scrim-opacity', '0.5'); + dialog.style.setProperty('--_sheet-scrim-duration', '120ms'); + const computed = window.getComputedStyle(getSheet()); + expect(computed.getPropertyValue('--_sheet-scrim-opacity')).toBe( + 'initial', + ); + expect(computed.getPropertyValue('--_sheet-scrim-duration')).toBe( + 'initial', + ); + }); + }); + describe('container padding isolation', () => { it('resets container padding custom properties to 0px on the sheet panel element', () => { render( diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsx index 420f94348a98e..e7e4d93e714fb 100644 --- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx +++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx @@ -364,6 +364,12 @@ const styles = stylex.create({ }, transitionTimingFunction: easeVars['--ease-standard'], willChange: 'transform, opacity', + // The dialog writes its scrim's opacity on itself for each move of a drag, + // and only its backdrop reads it. A custom property inherits, so each + // write would restyle every element in the sheet. The panel ends the + // inheritance, so the restyle stops here. + '--_sheet-scrim-opacity': 'initial', + '--_sheet-scrim-duration': 'initial', }, // A sheet present on page load opens where it rests (spec:AST-013 FR13): // the collapse reduced motion uses, so the transition still ends. diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetDragRestyle.interaction.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetDragRestyle.interaction.browser.spec.ts new file mode 100644 index 0000000000000..5d85ff4453d54 --- /dev/null +++ b/packages/core/src/BottomSheet/__tests__/BottomSheetDragRestyle.interaction.browser.spec.ts @@ -0,0 +1,111 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +/** + * @file BottomSheetDragRestyle.interaction.browser.spec.ts + * @input The built "Tall sheet" BottomSheet story, real touch input (Chromium + * CDP) and the interaction harness's rendering trace + * @output A proof of the style work a touch drag does. A move restyles the + * dialog and the panel, never the sheet's content. + * @position An interaction proof beside + * BottomSheetDetent.interaction.browser.spec.ts, on the same harness. + */ + +import { + expect, + test, + type Locator, + type Page, +} from '@astryxdesign/a11y-spec/playwright'; +import { + drag, + openStory, + touchDriver, + traceRendering, + waitForRest, + withStorybook, + type TouchDriver, +} from '@astryxdesign/interaction-harness'; + +const storybook = withStorybook(test); + +// The most elements one style recalculation may restyle between two moves. +// A move restyles the dialog, its backdrop, the panel and the edge tint. The +// limit leaves room for an engine's own boxes. A restyle of the sheet's +// content counts every element in it. +const RESTYLED_PER_MOVE = 6; + +interface OpenSheet { + driver: TouchDriver; + sheet: Locator; + handle: {x: number; y: number}; +} + +async function openSheet(page: Page): Promise { + await openStory(page, storybook(), 'core-bottomsheet--tall-sheet'); + const driver = await touchDriver(page); + const trigger = page.getByRole('button', {name: 'Open nearby places'}); + const box = await trigger.boundingBox(); + if (box == null) { + throw new Error('no trigger'); + } + await driver.tap({x: box.x + box.width / 2, y: box.y + box.height / 2}); + const sheet = page + .getByRole('dialog', {name: 'Nearby places'}) + .locator('.astryx-bottom-sheet') + .first(); + await expect(sheet).toBeVisible(); + await waitForRest(sheet); + const rect = await sheet.boundingBox(); + if (rect == null) { + throw new Error('no sheet'); + } + return { + driver, + sheet, + handle: {x: rect.x + rect.width / 2, y: rect.y + 12}, + }; +} + +test("a move of a drag restyles the dialog and the panel, not the sheet's content", async ({ + page, + browserName, +}) => { + test.skip(browserName !== 'chromium', 'rendering traces are Chromium-only'); + const {driver, sheet, handle} = await openSheet(page); + // The proof needs content that a restyle of the whole sheet would count. + const contentElements = await sheet.evaluate( + element => element.querySelectorAll('*').length, + ); + expect(contentElements).toBeGreaterThan(4 * RESTYLED_PER_MOVE); + let steady = {from: 0, to: 0}; + const trace = await traceRendering(page, async () => { + const played = await driver.play( + drag( + handle, + {x: handle.x, y: handle.y + 240}, + {durationMs: 600, hz: 60, restMs: 150}, + ), + ); + const moves = played.filter(event => event.type === 'touchMove'); + // The steady part of the drag: its first moves commit the drag's start, + // and the lift commits its release. + steady = { + from: moves[4].returnedAt, + to: moves[moves.length - 1].dispatchedAt, + }; + await waitForRest(sheet); + }); + const restyled = trace.events + .filter( + event => + event.name === 'UpdateLayoutTree' && + event.t >= steady.from && + event.t <= steady.to, + ) + .map(event => event.elements ?? 0); + // The drag wrote the scrim: a move's recalculation restyles the dialog too. + expect(Math.max(...restyled), JSON.stringify(restyled)).toBeGreaterThan(1); + expect(Math.max(...restyled), JSON.stringify(restyled)).toBeLessThanOrEqual( + RESTYLED_PER_MOVE, + ); +}); diff --git a/packages/core/src/theme/derivedVarRegistry.test.ts b/packages/core/src/theme/derivedVarRegistry.test.ts index 2c4208f5a2d4d..0f23da9cbc451 100644 --- a/packages/core/src/theme/derivedVarRegistry.test.ts +++ b/packages/core/src/theme/derivedVarRegistry.test.ts @@ -137,6 +137,11 @@ const STRUCTURAL_VARS = new Set([ // Also beside it: how far above the viewport's bottom a layer ends while the // keyboard is up. Runtime geometry, never authored by a theme. '--_layer-keyboard-inset-block-end', + // A sheet's scrim opacity and fade time. The sheet writes both on its + // dialog for the backdrop, and its panel resets them so the content does + // not inherit them. Runtime state, never authored by a theme. + '--_sheet-scrim-opacity', + '--_sheet-scrim-duration', ]); /**