Repository navigation
fix(DropdownMenu): load the touch bottom sheet only when a menu shows it - #7709
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsMoreMenu (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression40 of 482 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 20 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Requesting changes: the bundle saving holds up (a popover-only DropdownMenu loads about 24 KB less gzipped code) and loaded bottom sheets behave as before, but opening a sheet from the keyboard before its on-demand code arrives now leaves focus on the sheet panel instead of the first action.
- Run the first-row focus when the rows mount instead of once when
isOpenflips, load the sheet and its action list in one request, and add a test that opens the sheet before the lazy modules resolve (thebeforeAllwarm-up hides this path today). - Add your handle on its own line to
.changeset/dropdown-menu-lazy-touch-sheet.md, sincecheck:changesetsfails the Lint workflow. - Replace the import-string test with an assertion on the bundle output, or drop it, because the testing architecture asks tests not to rely solely on import structure.
[Automated review]
| import { | ||
| MenuBottomSheet, | ||
| MenuBottomSheetActionList, | ||
| } from './lazyMenuBottomSheet'; |
There was a problem hiding this comment.
Loading the sheet lazily leaves the keyboard-open focus effect (lines 761-771) racing the import: if Enter lands before MenuBottomSheet resolves, the effect's single animation frame finds no rows, nothing re-runs it when they mount, and focus stays on the sheet panel. Running the first-row focus when the rows mount (and loading both modules in one request) keeps the shipped behavior.
| })), | ||
| ); | ||
|
|
||
| const LazyMenuBottomSheetActionList = lazy(async () => |
There was a problem hiding this comment.
This boundary renders inside the lazily loaded sheet, so its import starts only after the MenuBottomSheet chunk has loaded and rendered: two sequential requests before the rows exist. Starting both imports together, or loading the whole sheet subtree from one module, removes the second wait.
|
|
||
| // The touch sheet is loaded lazily; resolve it once so sheets below render | ||
| // synchronously. | ||
| beforeAll(warmMenuBottomSheet, 20000); |
There was a problem hiding this comment.
With both lazy components resolved here, no test opens the sheet before they load; the steps of 'focuses the first action when a bottom sheet opens from the keyboard' fail on this head without this warm-up. A cold-path case in its own file would cover that partition.
| expect(source).not.toContain("import {Section} from '../Section'"); | ||
| }); | ||
|
|
||
| it('loads the touch sheet only on demand', () => { |
There was a problem hiding this comment.
This asserts import strings, which component-test-sufficiency INV5 asks tests not to rely on when the outcome can be observed directly; a static import of BottomSheet internals from another eager DropdownMenu module would restore the bytes while this still passes. An assertion on the bundle graph of the DropdownMenu entry would prove the promise.
|
|
||
| [fix] DropdownMenu: load the touch bottom sheet only when a menu shows it | ||
|
|
||
| `DropdownMenu` imported its touch sheet (BottomSheet, its gestures, and the touch action list) up front, so every page with a dropdown shipped it, even when the menu only ever opens as an anchored popover. The sheet now loads on demand, the way `ContextMenu` already loads it. A popover-only dropdown's own code drops by about a third (about 23 KB gzipped). Bottom-sheet and adaptive menus behave as before; the sheet mounts with the trigger, so it has loaded before the first tap. |
There was a problem hiding this comment.
check:changesets fails the Lint workflow here: the body needs a contributor handle on its own line, for example @josephfarina.
…beats the sheet load The touch sheet loads on demand, so a keyboard open can commit before its rows exist. Wait for the rows, then focus the first action. Add a test that holds the sheet modules until after Enter, with no warm-up, and credit the changeset.
There was a problem hiding this comment.
Requesting changes: the bundle saving holds (a popover-only DropdownMenu loads about 21 KB less gzipped code), loaded menus look and behave as before, and a keyboard open that beats the sheet load now focuses the first action. Two things still need a change:
- With
renderToString, the first two server renders in each server process send the closed sheet incompletely and hydration reports a recoverable error, which AST-013 FR9 rules out; skipping the lazy sheet whileuseIsHydrating()returnstruekeeps it out of the server and hydrating renders. - The import-string test in
DropdownMenu.test.tsxrelies on source structure, which component-test-sufficiency INV5 rules out, and it still passes when another eager module imports the sheet again, so please drop it or assert on the bundled entry instead.
[Automated review]
| })), | ||
| ); | ||
|
|
||
| export function MenuBottomSheet( |
There was a problem hiding this comment.
This wrapper suspends during a server render and during the hydrating render, because DropdownMenuBottomSheet renders the closed sheet beside the trigger. With renderToString, the first two renders in each server process send no sheet and then no rows, and each hydrates with "Switched to client rendering because the server rendering aborted…", which AST-013 FR9 rules out. Skipping the lazy sheet while useIsHydrating() returns true keeps it out of both renders, and the sheet still starts loading right after hydration.
| it('loads the touch sheet only on demand', () => { | ||
| const source = readFileSync( | ||
| 'packages/core/src/DropdownMenu/DropdownMenu.tsx', | ||
| 'utf8', | ||
| ); | ||
| const loader = readFileSync( | ||
| 'packages/core/src/DropdownMenu/lazyMenuBottomSheet.ts', | ||
| 'utf8', | ||
| ); | ||
|
|
||
| // Pointer-only pages must not pull the touch sheet into their bundle. | ||
| expect(source).toContain("from './lazyMenuBottomSheet'"); | ||
| expect(source).not.toMatch(/from '\.\/MenuBottomSheet(ActionList)?'/); | ||
| expect(loader).toContain("import('./MenuBottomSheet')"); | ||
| expect(loader).toContain("import('./MenuBottomSheetActionList')"); | ||
| expect(loader).not.toMatch(/^import \{[^}]*\} from '\.\/MenuBottomSheet/m); | ||
| }); |
There was a problem hiding this comment.
This checks import strings, which component-test-sufficiency INV5 rules out when the outcome can be observed directly, and it misses the regression it is meant to catch: with import './MenuBottomSheet' added to renderDropdownItems.tsx, the sheet's modules return to the eager bundle while this test still passes. Dropping it (INV11 asks for no new test for a private wrapper) or asserting on the bundled entry's static graph would fix that.
…ng renders A lazy sheet that has not loaded yet left server markup incomplete in the first renders of a server process, and hydration then fell back to client rendering. The sheet wrappers render nothing while useIsHydrating() is true; the closed sheet has no visible markup, so it first renders right after hydration. Add an SSR test over fresh module graphs. Replace the source-structure import test with a behavioral one: opening a popover menu never requests either sheet module, and importing the dropdown times out if any module it loads imports the sheet eagerly.
There was a problem hiding this comment.
This looks ready to merge: popover-only DropdownMenu pages now load about 22 KB less gzipped code, menus look and behave the same once the sheet has loaded, and server-rendered bottom-sheet menus hydrate cleanly. The hydration guard and the new cold-path, SSR and module-load tests resolve the earlier blocking feedback, and each of those tests fails when its fix is reverted. Nothing else is needed before merging; as an optional follow-up, starting both sheet imports together would halve the wait when someone opens a sheet before its code has arrived, since the action list's chunk is requested only after the sheet's.
[Automated review]
… cases (#7758) ContextMenu loads its touch sheet with React.lazy. Until #7709 its import resolved at once, because DropdownMenu imported the sheet statically; now nothing in this suite loads it first, so the first case that opens a ContextMenu sheet pays the sheet's cold import inside a 1 s waitFor and fails on a slow machine. The suite now warms the sheet up front with the helper #7709 added for the DropdownMenu and MoreMenu suites.
…er an unhandled rejection (#8478) ## User impact A bottom-sheet DropdownMenu preloads its action list at rest. When that load fails (a dropped or flaky connection), the page gets an unhandled promise rejection in the console. The rejected load also stays cached, so every later open of the menu fails to show its rows until a reload. In this repository's CI, the same unhandled rejection fails the UI test shard that runs `DropdownMenu.ssr.test.tsx` while every test passes, as on #8353, #8229 and #8211. ## Problem and solution fit - Why does it occur? `preloadMenuBottomSheetActionList` starts the load with `void loadActionList()`: nothing handles a rejection, and `actionListLoad ??=` keeps the rejected promise. - Why does it harm the task? An unhandled rejection is reported as an error, and a cached rejection turns one network blip into a menu whose rows never appear. - Why does that matter? The preload only exists to make the first open instant; it must never break the open. In tests, the SSR file can finish while its preload is still importing; the environment tears down mid-import and the rejection fails the run. The fix handles the preload's failure and drops the failed load, so the next preload or open asks the loader again. The SSR test waits for the sheet modules before it ends. ## Expected behavior and authority The sheet loads on demand (#7709) and preloads at rest so the first open shows its actions at once (#8392). A preload is an optimization: its failure surfaces no error and blocks no retry. ## Smallest restoration - `loadActionList` clears its cached load when the import rejects. - `preloadMenuBottomSheetActionList` handles the rejection. - `DropdownMenu.ssr.test.tsx` awaits the two sheet modules after unmounting. No API, rendering or timing change. ## Evidence - Reproduction before the change: on main e9b3f3e, `DropdownMenu.ssr.test.tsx` run alone fails 5 of 6 runs with three `EnvironmentTeardownError`s each, and the new unit test records the unhandled rejection. - Result after the change: the SSR file passes 8 of 8 runs alone, and the unit test passes. - Representative unchanged path: all 10 DropdownMenu test files (312 tests) pass. - Regression test or other mutation-sensitive proof: `lazyMenuBottomSheet.test.ts` fails the list's import once, then checks there is no unhandled rejection and that the next call imports it again. Keeping the rejected load cached fails it ("expected 1 to be 2"). ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - At 3962530: the changeset and comments promise only what holds everywhere (no unhandled rejection, no kept failure); the unit and SSR tests: 2 passed; changeset coverage: passes. - At 8877d94 (adds the Changeset): `node scripts/release/changeset-coverage.mjs pr --base e9b3f3e` fails at 4d8e178 and passes here (`[fix]`, `@astryxdesign/core`); `pnpm check:changesets`: valid. - `pnpm exec vitest run --project ui packages/core/src/DropdownMenu/lazyMenuBottomSheet.test.ts`: fails on main, passes here. - `pnpm exec vitest run --project ui packages/core/src/DropdownMenu/DropdownMenu.ssr.test.tsx`, alone, 8 times: 8 of 8 (main: 1 of 6). - `pnpm exec vitest run packages/core/src/DropdownMenu`: 10 files, 312 tests. - `tsc -p packages/core/tsconfig.json --noEmit`, eslint and prettier on the changed files: clean.
User impact
Every page that renders a
DropdownMenudownloads the touch bottom sheet (BottomSheet, its drag gestures, mobile-keyboard handling, and the touch action list), even when the menu only ever opens as an anchored popover. On desktop that code never runs. In a bundle ofDropdownMenualone, it is about a third of the component's code.Problem and solution fit
DropdownMenu.tsximportedMenuBottomSheetandMenuBottomSheetActionListstatically, so bundlers had to include them wherever the dropdown is imported. The sheet only renders when the resolved presentation isbottom-sheet(explicit, oradaptiveon a compact touch screen). Loading both withReact.lazyinside aSuspenseboundary keeps them out of popover-only pages.ContextMenualready loads the sameMenuBottomSheetthis way.Expected behavior and authority
No visible behavior change: a server-rendered bottom-sheet menu adds its closed (invisible) sheet markup right after hydration instead of in the server HTML. The
DropdownMenucontract (popover and bottom-sheet presentations, adaptive switching, focus rules) is unchanged. The trigger still renders eagerly. The sheet starts loading when the trigger mounts; a keyboard open that arrives before it loads still focuses the first action once the rows mount.Smallest restoration
lazyMenuBottomSheet.ts:MenuBottomSheetandMenuBottomSheetActionListwrappers with the same props, each aReact.lazyload inside<Suspense fallback={null}>.useIsHydrating()), so server markup never holds a half-loaded sheet (AST-013 FR9); the closed sheet has no visible markup.DropdownMenu.tsx: only its import changes, to the wrappers. Its JSX is untouched.beforeAllso later tests render it synchronously (the same pattern theItemswipe tests use).Evidence
DropdownMenuentry from the builtdist, React and StyleX external: popover-only code is 246 KB minified / 78 KB gzipped.Scope
Testing
vitest run --project uion DropdownMenu, ContextMenu, MoreMenu, and the menu a11y suites: 360 passed.pnpm -F @astryxdesign/core buildandtypecheck: clean. eslint and prettier: clean.