Skip to content

test(ContextMenu): resolve the lazy touch sheet once before the sheet cases - #7758

Merged
imdreamrunner merged 1 commit into
meta:mainfrom
vjeux:context-menu-test-warm-sheet
Oct 20, 2026
Merged

imdreamrunner merged 1 commit into
meta:mainfrom
vjeux:context-menu-test-warm-sheet

Conversation

@vjeux

@vjeux vjeux commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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 on main, and on an idle one they pass. ContextMenu loads its touch sheet with React.lazy, and nothing in this suite loads the sheet module first: ContextMenu imports only types from DropdownMenu.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 inside waitFor'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 in MoreMenu.test.tsx. It opens a DropdownMenu bottom sheet once, so the sheet's modules are loaded before any case, and ContextMenu's own lazy import then resolves within a tick, inside waitFor. Test file only: no source, story or record change, so no changeset.

Evidence

  • Failure before the change: with the sheet module's first load forced to take 5 s (a harness-only vi.mock delay), 20 of 20 isolated copies of main's suite fail both sheet cases, and the adaptive sheet case after them.
  • Success after the change: the same harness over 20 copies of this branch's suite: 20 of 20 pass every case.
  • Product/runtime behavior verified unchanged: only the test file changes; the ContextMenu, DropdownMenu and MoreMenu suites pass.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

Forced slow cold import (evidence harness only, not committed): each copy adds, after its vitest import,
  vi.mock('../DropdownMenu/MenuBottomSheet', async importOriginal => {
    await new Promise(resolve => { setTimeout(resolve, 5000); });
    return importOriginal();
  });
20 copies of main's suite:  pnpm exec vitest run packages/core/src/ContextMenu/ContextMenu.coldBefore --maxWorkers=6
  20/20 files fail; 60 failed, 1120 passed. Each fails "opens the real menu content in a BottomSheet when requested",
  "drills into nested data items inside the BottomSheet" and "uses the BottomSheet for adaptive presentation on compact touch"
20 copies of this branch's suite:  pnpm exec vitest run packages/core/src/ContextMenu/ContextMenu.coldAfter --maxWorkers=6
  20/20 files pass; 1180 passed

Unforced: on a busy machine earlier today, `vitest run ContextMenu.test.tsx -t BottomSheet` failed both cases on main
in two runs; on an idle machine it passes on main and here (4 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   ✓

… 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.
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 20, 2026 7:57pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 20, 2026
@astracat-bot

astracat-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 20, 2026, 8:15 PM UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

ContextMenu (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 630 -
Complexity N/A Very High (79) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Comment on lines +31 to +33
// 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@imdreamrunner
imdreamrunner merged commit 25548b9 into meta:main Oct 20, 2026
51 checks passed
@vjeux
vjeux deleted the context-menu-test-warm-sheet branch October 20, 2026 20:29
@vjeux

vjeux commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

A correction to the description and the squash commit message. ContextMenu imports only types from DropdownMenu.tsx, so this suite never loaded the sheet module ahead of its first sheet case, before #7709 or after. The cold import was always there; it fails only on a loaded machine. #7709 is relevant only because it added this warm-up helper. The description is reworded. The other note, the nested case that still relied on an earlier case to render the sheet, is fixed in #7761.

cixzhang pushed a commit that referenced this pull request Oct 21, 2026
…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   ✓
```

This branch was successfully deployed

1 active deployment
Preview — bcff51cd Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants