Repository navigation
fix(DropdownMenu): a menu's sheet renders nothing at rest and drops two wrappers - #8392
Conversation
…wo wrappers An adaptive or bottom-sheet DropdownMenu, MoreMenu or ContextMenu kept its whole closed BottomSheet mounted at rest, every item included, so a phone rendered 7 to 9 more elements than a desktop with the menu closed (architecture:component-style-authoring INV7). Now: - MenuBottomSheet renders nothing while closed. It mounts as it opens and, after it closes, stays only until its dialog has closed, so the exit plays out and focus returns to the trigger. - The Section wrapper between the sheet and the menu's content is gone: the sheet has no content padding and the menu's own content element carries the same 16px / 4px inset and container variables. - The root view's heading stands alone; the header row wraps it only beside a sub-menu's back button. Opening the sheet still renders more than the anchored popover because of BottomSheet's own anatomy; that remainder is tracked separately.
|
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 ComponentsContextMenu (@astryxdesign/core) · View in Storybook
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: No accessibility violations detected. Visual Regression48 of 502 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 28 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Requesting changes: unmounting the closed menu sheet works as described (fewer elements at rest, the exit still plays, focus returns to the trigger), but compound-mode ContextMenu sheets (menuContent with presentation="bottom-sheet", or "adaptive" on touch) lose their inset, so the first row slides under the grab handle. Please give the compound sheet branch in ContextMenu.tsx the same menuBottomSheetStyles.content and styles.sheetMenuInset, and replace the source-text padding test with a rendered assertion on a data and a compound sheet. Two smaller follow-ups are noted inline: naming the native dialog in the set-state-in-effect disable reason, and adding a regression for the new --container-padding-* publication.
[Automated review]
| stylex.props(styles.sheetMenu, xstyle), | ||
| stylex.props( | ||
| styles.sheetMenu, | ||
| menuBottomSheetStyles.content, |
There was a problem hiding this comment.
Only this data-mode element gets the sheet inset. In compound mode (menuContent) the sheet renders renderedMenu, whose sheet branch (line 716) applies only styles.sheetMenu. With padding={0} on the sheet and no Section, the inset above the first row drops from 20px to 4px (the row slides under the grab handle) and the side inset from 8px to 4px. Applying menuBottomSheetStyles.content and styles.sheetMenuInset in that branch too would restore the previous layout.
| expect(source).toContain("paddingBlockStart: spacingVars['--spacing-4']"); | ||
| expect(source).toContain('paddingBlockEnd: 0'); |
There was a problem hiding this comment.
This checks the style module's source text, so it still passes while the compound sheet has no inset. Opening a data sheet and a compound sheet and asserting the menu element's padding would catch that.
| } | ||
| const dialog = panelRef.current?.closest('dialog'); | ||
| if (dialog == null || !dialog.open) { | ||
| // eslint-disable-next-line @eslint-react/set-state-in-effect -- the closed sheet's exit is already over: unmount it |
There was a problem hiding this comment.
Could the reason name the external system it reacts to, for example that the native dialog is already closed so its exit is over? The Effect reads dialog.open and listens for close.
| sheetMenuInset: { | ||
| paddingBlockStart: `calc(${spacingVars['--spacing-4']} + ${spacingVars['--spacing-1']})`, | ||
| paddingBlockEnd: spacingVars['--spacing-1'], | ||
| paddingInline: `calc(${spacingVars['--spacing-1']} + ${spacingVars['--spacing-1']})`, | ||
| }, |
There was a problem hiding this comment.
This applies 20px / 8px / 4px while menuBottomSheetStyles.content publishes 16px / 4px / 0px in --container-padding-*. Nothing in the data path reads those variables today, but a bleed child would compensate against them. Either publish the applied inset here or note why the Section's values are kept.
The compound (`menuContent`) branch of ContextMenu's sheet never received the inset that replaced the Section wrapper, so the first row lost 16px and slid under the sheet's grab handle. It now takes the same menuBottomSheetStyles.content and sheetMenuInset as the `items` branch. Tests: the source-text padding check becomes a rendered assertion on both an `items` and a compound sheet: no Section above the menu element, the inset on the element itself, and the container padding it publishes to bleeding rows. The compound case fails on the previous head. The set-state-in-effect reason names the native dialog.
There was a problem hiding this comment.
Requesting changes: unmounting the closed sheet works as described (fewer elements at rest, the exit still plays, focus returns to the trigger, and the compound ContextMenu inset is back), but the first open of a DropdownMenu or MoreMenu sheet now shows only its heading for about 300 ms before the rows appear, because the lazily loaded action list first renders when the sheet mounts. Please make the rows resolve at rest again, for example by loading the action list with the sheet host, and add a cold first-open test that does not call warmMenuBottomSheet. Please also make ContextMenu's published --container-padding-* match the 20px / 8px inset sheetMenuInset applies, or stop publishing on that element.
[Automated review]
| return () => dialog.removeEventListener('close', handleClose); | ||
| }, [isMounted, isOpen]); | ||
|
|
||
| if (!isMounted) { |
There was a problem hiding this comment.
Returning null here keeps DropdownMenu's lazy MenuBottomSheetActionList from rendering until the sheet opens, so it first resolves in the opening commit. In Chromium the first open shows a 101px sheet with only the heading and the rows arrive about 300 ms later (also in CI's production Storybook, with no request after the tap); the base rendered the rows at rest. Could the action list resolve at rest again, for example by loading it in the same lazy module as the sheet host?
| sheetMenuInset: { | ||
| paddingBlockStart: `calc(${spacingVars['--spacing-4']} + ${spacingVars['--spacing-1']})`, | ||
| paddingBlockEnd: spacingVars['--spacing-1'], | ||
| paddingInline: `calc(${spacingVars['--spacing-1']} + ${spacingVars['--spacing-1']})`, | ||
| }, |
There was a problem hiding this comment.
This applies 20px / 8px / 4px, but menuBottomSheetStyles.content publishes 16px / 4px / 0 in --container-padding-* on the same element. The container-padding host rule asks published values to match the applied padding; overriding the four variables here with the applied inset (or not publishing on this element) would conform, with the test updated to match.
| }); | ||
|
|
||
| it('renders nothing of the sheet at rest and keeps it through its exit', async () => { | ||
| await warmMenuBottomSheet(); |
There was a problem hiding this comment.
Warming resolves both lazy modules, so no suite sees a cold first open, which is where the header-only sheet appears. A test with the modules released at rest (like DropdownMenuLazySheet.test.tsx) that asserts the rows exist in the opening commit would cover it.
…ntextMenu publishes the inset it applies - A closed menu sheet renders nothing, so its lazily loaded action list first rendered on the first open: it suspended there, and React held the rows back for about 300ms, leaving a heading-only sheet. A sheet menu now preloads the action list at rest, and a list mounted after the load renders directly instead of through lazy(), so the rows commit with the opening. The choice is made once per mount, so a load that lands while a list is mounted never remounts it. - ContextMenu's sheet published the 16px / 4px inset while applying 20px / 8px; it now publishes the padding it applies. Tests: a cold bottom-sheet DropdownMenu (no warm-up) loads the sheet and rows at rest and renders the actions in the same commit as the opening; it fails without the preload and without the direct render. The ContextMenu sheet assertions expect the published 20px / 8px.
There was a problem hiding this comment.
Recommending approval: a closed DropdownMenu, MoreMenu or ContextMenu bottom sheet no longer mounts (an adaptive MoreMenu on touch drops from 149 to 117 elements at rest), while the open sheet keeps its layout, shows its rows on the first open, plays its exit and returns focus to the trigger. The compound ContextMenu inset and the published container padding now match what is applied, and the new tests cover the at-rest absence, the exit, the inset and a cold first open. No further changes are needed here; the open sheet's remaining excess over the popover comes from BottomSheet's own anatomy, which the description already leaves to a follow-up.
[Automated review]
Main's menu sheet renders nothing at rest and drops two wrappers (meta#8392): a sub-menu level's heading now sits in a row with its back button and the root's stands alone. This branch keeps its level regions on that structure: the opened level is still read from the current items, and its own header and footer, keyed by level, replace the menu's. ContextMenu's suite keeps this branch's plain-row case beside main's sheet-inset cases, which replace the old padding check.
…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
On a phone, a DropdownMenu, MoreMenu or ContextMenu presented as a bottom sheet (
presentation="adaptive"on a compact touch screen, orpresentation="bottom-sheet") kept its closed sheet, with every item, mounted while the menu was closed. A page with a few adaptive menus carried a whole sheet per menu at rest. On touch, the menu rendered 7 to 9 more elements than the same menu on a desktop, whicharchitecture:component-style-authoringINV7 does not allow (no more elements under a coarse pointer than under a fine one).Problem and solution fit
Expected behavior and authority
architecture:component-style-authoringINV7 (current): components are built from minimal DOM, and a layer under a coarse pointer has at most as many elements as under a fine pointer.Smallest restoration
menuBottomSheet.stylex.ts) carries the inset that the Section used to.Evidence
Element count,
document.body.querySelectorAll('*').length, in headless Chromium against Storybook builds of main and this change. Desktop is 1280px with a fine pointer; touch is 390px with a coarse pointer. Stories that render their sheet already open show the open state as "rest".closeevent, then removes it. The content element carries the inset itself, with no Section above it and the root heading directly inside it. Both fail on main.Scope
Testing
pnpm vitest run packages/core/src/DropdownMenu packages/core/src/ContextMenu packages/core/src/MoreMenu packages/core/src/BottomSheet: 680+ pass.tsc, ESLint (strict) and Prettier are clean.