Repository navigation
test(ContextMenu): resolve the lazy touch sheet once before the sheet cases - #7758
Conversation
… cases ContextMenu loads its touch sheet with React.lazy. Until meta#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 meta#7709 added for the DropdownMenu and MoreMenu suites.
|
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
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
No changes are needed: the suite-level warm-up keeps every ContextMenu case and assertion as it was, and the slow-first-load reproduction from the description fails the three sheet cases on main and passes on this branch. One optional follow-up: "drills into nested data items inside the BottomSheet" still relies on an earlier sheet case to resolve ContextMenu's own lazy sheet, so it fails when run alone (on main too); awaiting its first row with findByRole would make it order-independent. Separately, ContextMenu imports only types from DropdownMenu.tsx, so the description's note that DropdownMenu preloaded the sheet for this suite before #7709 may be worth rewording.
[Automated review]
| // The touch sheet is loaded lazily; resolve its modules once up front, so | ||
| // ContextMenu's own lazy sheet renders within the cases' waitFor. | ||
| beforeAll(warmMenuBottomSheet, 20000); |
There was a problem hiding this comment.
Optional, and inherited from main: this makes the sheet module's import fast, but ContextMenu's own LazyMenuBottomSheet is still resolved only by a ContextMenu render. drills into nested data items inside the BottomSheet queries the sheet synchronously right after fireEvent.contextMenu (line 276), so it still fails when run alone with -t "drills into". Awaiting the first row there, for example await screen.findByRole('button', {name: 'Move to project'}), would make it independent of case order.
|
A correction to the description and the squash commit message. ContextMenu imports only types from |
…ow (#7761) ## Maintainer impact `ContextMenu.test.tsx`'s "drills into nested data items inside the BottomSheet" fails when it runs alone (`vitest run ContextMenu.test.tsx -t "drills into nested"`), on `main` too. In the full file it passes only because an earlier sheet case has already rendered ContextMenu's sheet. ## Intended invariant Each sheet case passes on its own, whatever ran before it. ContextMenu's touch sheet is `React.lazy`, so its first render suspends once even when the module is already loaded (as #7758's warm-up ensures). A case must wait for the sheet's first row instead of querying it in the same tick as the open. ## Change The case awaits its first row with `findByRole` before clicking it. The case and its assertions are otherwise unchanged. The other two sheet cases already wait for the sheet through `waitFor` and pass alone. Test file only: no source, story or record change, so no changeset. ## Evidence - Failure before the change: 20 isolated copies of `main`'s suite, each running only this case: 20 of 20 fail ("Unable to find an accessible element with the role "button" and name "Move to project""). - Success after the change: the same 20 copies of this branch's suite pass 20 of 20. - Product/runtime behavior verified unchanged: only the test file changes; the ContextMenu, DropdownMenu and MoreMenu suites pass. ## Scope - [x] No intended public API, product behavior, visual direction, or policy change. - [x] Product changes discovered during the work were removed or split. - [x] Public text and artifacts contain no internal Meta context. ## Testing ``` 20 copies, each: pnpm exec vitest run packages/core/src/ContextMenu/ContextMenu.solo<N>.test.tsx -t "drills into nested data items inside the BottomSheet" main (25548b9): 20 files, 20 failed this branch: 20 files, 20 passed Each sheet case alone on main: "opens the real menu content in a BottomSheet when requested" passed "drills into nested data items inside the BottomSheet" failed "uses the BottomSheet for adaptive presentation on compact touch" passed pnpm exec vitest run packages/core/src/ContextMenu packages/core/src/DropdownMenu packages/core/src/MoreMenu Tests 385 passed pnpm -F @astryxdesign/core typecheck, pnpm lint:strict, pnpm check:knowledge, pnpm storybook:build ✓ ```
Maintainer impact
ContextMenu.test.tsx's two bottom-sheet cases ("opens the real menu content in a BottomSheet when requested" and "drills into nested data items inside the BottomSheet") fail whenever the sheet's first import is slow: on a busy machine they fail onmain, and on an idle one they pass. ContextMenu loads its touch sheet withReact.lazy, and nothing in this suite loads the sheet module first: ContextMenu imports only types fromDropdownMenu.tsx, the one module that imported the sheet statically before #7709. So the first case that opens a ContextMenu sheet pays the sheet's cold import insidewaitFor's 1 s, as it did before #7709.Intended invariant
These cases cover what the sheet does once open. The on-demand load itself belongs to
DropdownMenuLazySheet.test.tsx, which holds the sheet modules on purpose; #7709 already warms the sheet in the DropdownMenu and MoreMenu suites for the same reason.Change
beforeAll(warmMenuBottomSheet, 20000)at the top of the suite, with the helper and timeout #7709 uses inMoreMenu.test.tsx. It opens aDropdownMenubottom sheet once, so the sheet's modules are loaded before any case, and ContextMenu's own lazy import then resolves within a tick, insidewaitFor. Test file only: no source, story or record change, so no changeset.Evidence
vi.mockdelay), 20 of 20 isolated copies ofmain's suite fail both sheet cases, and the adaptive sheet case after them.Scope
Testing