Skip to content

perf(ContextMenu): load the touch sheet's action list only for the sheet presentation - #11616

Merged
cixzhang merged 4 commits into
mainfrom
perf/contextmenu-lazy-sheet
Nov 15, 2026
Merged

cixzhang merged 4 commits into
mainfrom
perf/contextmenu-lazy-sheet

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

A pointer ContextMenu, which is the default and is every Table cell menu, no longer loads the touch bottom sheet's action list. ContextMenu imported that list statically: List, ListItem, the checkbox row, Field, Divider and List's layout-animation engine. Every page with a context menu carried it, though only the bottom-sheet presentation renders it. DropdownMenu already loads the same code through its lazy sheet module; ContextMenu now reuses that module. This is a performance change with no behavior change, which none of the narrower templates covers.

User or maintainer impact

  • People loading a page with a Table that has cell actions, or with a ContextMenu: about 57 KB less JavaScript before first paint (about 20 KB gzip).
  • A sheet menu (presentation="bottom-sheet", or adaptive on a compact touch screen): unchanged. It loads its sheet frame and action list after mount, as its frame already did and as DropdownMenu does. The list preloads at rest, so the first open shows its rows at once.
  • No load moves to first open or to intent: pointer menus never need the sheet, and sheet menus load it with the page.
  • No public API change.

Problem and solution fit

  • ContextMenu imports MenuBottomSheet, MenuBottomSheetActionList and preloadMenuBottomSheetActionList from the existing DropdownMenu/lazyMenuBottomSheet, and drops its own lazy sheet frame and its static action-list import.
  • A data-driven sheet menu preloads the action list at mount. The Effect names what it syncs (the sheet's action list with the presentation).
  • Nothing new is shared: the module's header now says it serves both menus.
  • Kept static on purpose: the sheet's back Button. Pages almost always render a Button anyway, so deferring it saves nothing at the app level.

Authority

  • component:ContextMenu PR1: a sentence states that the sheet's code loads after mount and only while the menu resolves to the sheet. verified_by and the FR10/PR1 verification row cite the new test.
  • architecture:component-import-boundaries DEC-1 and the owner's 11-10 "load with the page" answer are untouched: no load moves to first open or to intent.
  • No allowlist effect: Table/tableContextMenu → ContextMenu still crosses; its CI cost drops. Removing that row is a separate decision.

Change and evidence

Page-level first-load bytes

Base 90abc74e against this head. Core's src was compiled with its Babel config, with Core's sideEffects. esbuild then built one app bundle per page: minified, ESM, code splitting on, bare imports external. First load is the entry chunk plus its static imports, with gzip at level 9.

Page (components) Base min / gzip Head min / gzip Change
Table page (Table, Text, Button) 357,825 / 124,632 300,854 / 104,334 −56,971 / −20,298
ContextMenu page (ContextMenu, Button, Text, Heading) 304,629 / 105,305 247,709 / 85,557 −56,920 / −19,748
DropdownMenu page (DropdownMenu, Button, Text) 265,041 / 91,209 265,041 / 91,206 0 / −3
Markdown page (Markdown, Text, Heading) 543,134 / 187,671 542,807 / 188,396 −327 / +725
  • Markdown renders List itself, so its List code stays in the first load. The extra chunk boundary costs 0.7 KB of gzip there.
  • The repository's boundary check prints Table's eager gzip as 131.7 → 112.3 KB.

Behavior

  • Red first: ContextMenu.sheetLoading.test.tsx checks that a pointer menu opens without loading the sheet's action list. It fails on main (the list module loads once) and passes here. Its second case checks that a sheet menu opens with its rows, drills into a sub-menu and comes back with the back button. It passes on both.
  • Android emulator, Chrome 133: on a page with a bottom-sheet ContextMenu, built from base and from head, a real long press (adb shell input swipe, 900 ms) opens the sheet with its rows, and a tap on "Move to" drills in. Base and head behave the same; head was taken twice. Retaken after merging main (at 4d81c5e), since main had changed ContextMenu.tsx (the cursor anchor's base box): base was main at that point, and the result is the same. This head (624a831) merges main again; main changed neither ContextMenu.tsx nor DropdownMenu/lazyMenuBottomSheet.ts since, so that take carries.

Scope

Components: ContextMenu (and DropdownMenu's lazy sheet module header)

  • This PR has one primary intent.
  • Independently removable deltas were removed or split.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

Record changed: component:ContextMenu. PR1 gains one sentence: the touch sheet's code (its frame and its data-driven action list) loads after mount, and only while the menu resolves to the sheet presentation, so a pointer menu carries none of it. verified_by and the FR10/PR1 verification row add the new test.

  • R1 narration: none; present tense.
  • R2 research: none.
  • R3 evidence: names a test file only.
  • R4 rejected alternatives: none added.
  • R5 change references: none.
  • R6 open questions: none.

Testing

  • vitest run --project ui packages/core/src/ContextMenu packages/core/src/DropdownMenu packages/core/src/Table/tableContextMenu.test.tsx: 18 files, 471 tests pass.
  • pnpm check:component-import-boundaries --base-ref origin/main: boundaries hold.
  • pnpm -F @astryxdesign/core typecheck, ESLint on changed files, pnpm check:knowledge, shared-identity check: pass.
  • Android emulator long press opens the sheet and drills in: pass on base and head.

…eet presentation

ContextMenu imported the sheet's action list (List, ListItem, the checkbox
row, Field, Divider and List's layout-motion engine) statically, so every
pointer menu, Table's cell menus included, carried it. ContextMenu now uses
DropdownMenu's existing lazy sheet module: the frame and the action list
load after mount, only while the menu resolves to the sheet, and the list
preloads at rest so the first open shows its rows at once.

A new test checks that a pointer menu loads no sheet action list (it fails
on the previous code) and that a sheet menu still opens, drills into a
sub-menu and comes back.
@vercel

vercel Bot commented Nov 13, 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 Nov 14, 2026 10:25am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 13, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 13, 2026
@astracat-bot

astracat-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 15, 2026, 1:34 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec af43da2

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 624a831

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
DropdownMenu 106.1 kB (0) · 18.6 kB CSS (0) — ✗ · ✓ · ✓
DropdownMenuCheckboxItem 28.4 kB (0) · 7.1 kB CSS (0) — ✗ · ✓ · ✓
DropdownMenuDivider 5.3 kB (0) · 548 B CSS (0) — ✗ · ✓ · —
14 more components
Component Size LoC Visual · A11y · RTL
DropdownMenuGroup 6.4 kB (0) · 3.4 kB CSS (0) — ✗ · ✓ · —
DropdownMenuItem 27.6 kB (0) · 6.8 kB CSS (0) — ✗ · ✓ · —
DropdownMenuRadioGroup 6.6 kB (0) · 3.3 kB CSS (0) — ✗ · ✓ · —
DropdownMenuRadioItem 28.5 kB (0) · 7.1 kB CSS (0) — ✗ · ✓ · —
DropdownMenuSubMenu 79.0 kB (0) · 10.3 kB CSS (0) — ✗ · ✓ · ✓
Markdown 201.3 kB (+144 B) · 21.7 kB CSS (0) — — · — · —
MoreMenu 106.4 kB (0) · 18.6 kB CSS (0) — — · — · —
ContextMenuItem 35.1 kB (−1 B) · 6.9 kB CSS (0) — — · — · —
lab/CommentThread 359.9 kB (−418 B) · 2.4 kB CSS (0) — — · — · —
lab/Comments 366.9 kB (−655 B) · 2.5 kB CSS (0) — — · — · —
ContextMenu · Storybook 100.7 kB (−19.0 kB) · 18.4 kB CSS (0) 725 (+1) ✓ · ✓ · ✓
TableHeaderCell 101.6 kB (−19.1 kB) · 18.7 kB CSS (0) — — · — · —
Table 118.8 kB (−19.1 kB) · 19.4 kB CSS (0) — — · — · —
TableCell 101.9 kB (−19.1 kB) · 18.9 kB CSS (0) — — · — · —
Visual changes: 4 snapshots in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
DropdownMenu · Lab Checkbox Items (probe, dark) before frame after frame diff frame
DropdownMenu · Lab Checkbox Items (probe, light) before frame after frame diff frame
DropdownMenu · Lab Checkbox Items (neutral, dark) before frame after frame diff frame
DropdownMenu · Lab Checkbox Items (neutral, light) before frame after frame diff frame

Package size: @astryxdesign/core 7.57 MB packed (+162 B); no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 4130c03

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

Approved pending CI: CI has not run on this head yet, because the pull request is still a draft.

ContextMenu now takes its sheet frame and action list from DropdownMenu's lazy sheet module, so pointer menus and Table cell menus no longer ship the action list in the first load. The new sheet-loading test fails on main and passes here, the import-boundary check holds, and the Table and ContextMenu entries each drop about 19 KB gzip.

One optional cleanup: the two file headers this change edits (ContextMenu.tsx and lazyMenuBottomSheet.ts) run well past the roughly 12-line header guideline, so consider moving their explanatory paragraphs next to the code they describe.

Claims and files checked
  • Claim: a pointer ContextMenu (the default presentation, and every Table cell menu) no longer carries the sheet's action list. Verified: the new pointer test fails on main with one load and passes here; the default presentation is popover and Table's cell menu sets none.
  • Claim: ContextMenu now shares DropdownMenu's sheet module, which loads the sheet only for the sheet presentation. Verified: the new imports and the sheet-only render branch in ContextMenu.tsx, and the preload gated on a data-driven sheet menu.
  • Claim: Table and ContextMenu pages load about 57 KB less JavaScript, about 20 KB gzip. Verified for gzip (about 19 KB on both entry builds); the minified figure matches a build with StyleX compiled.
  • Claim: a sheet menu still loads its sheet after mount and opens as before. Verified: the sheet test passes before and after the change, and the preload runs in an Effect.
  • Claim: DropdownMenu already loads the same code through its lazy sheet module. Verified in DropdownMenu.tsx.
  • Claim: no behavior change and no public API change. Verified: the API report lists no added, changed or removed entries, and 471 tests pass.
  • Claim: no load moves to first open or to intent. Verified: pointer menus never load the list and sheet menus load it at mount.
  • Claim: the sheet's back Button stays a static import. Verified in ContextMenu.tsx.
  • Claim: the ContextMenu record gains one PR1 sentence, and its test list and FR10/PR1 row cite the new test. Verified in the record diff.
  • Claim: the Table to ContextMenu boundary crossing remains and its cost drops. Verified: the check still lists it, at a lower cost.
  • Claim: the boundary check prints Table's eager gzip falling by about 19 KB. Verified within local tolerance.
  • Claim: the page-level size table for Table, ContextMenu, DropdownMenu and Markdown. Verified in direction and size; DropdownMenu is unchanged and Markdown grows by under 1 KB gzip.
  • Claim: the pointer test fails on main and the sheet test passes on both. Verified.
  • Claim: the listed test run passes 18 files and 471 tests. Verified.
  • Claim: typecheck, ESLint on the changed files, the knowledge check and the boundary check pass. Verified.
  • Claim: an Android emulator long press opens the sheet and drills in on both sides. Stated by the author as emulator evidence; not rerun here.
  • File .changeset/contextmenu-pointer-no-sheet-code.md: clear.
  • File docs/specs/components/ContextMenu/ContextMenu.spec.md: clear.
  • File packages/core/src/ContextMenu/ContextMenu.sheetLoading.test.tsx: clear.
  • File packages/core/src/ContextMenu/ContextMenu.tsx: clear, with the optional header suggestion.
  • File packages/core/src/DropdownMenu/lazyMenuBottomSheet.ts: clear, with the optional header suggestion.

Automated review (maintainer link)

* @file ContextMenu.tsx
* @input Uses React, StyleX, useLayer, shared layer dismissal, BottomSheet,
* useListFocus, and the shared menu-presentation resolver
* @input Uses React, StyleX, useLayer, shared layer dismissal, the lazily

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, non-blocking: this file header runs 39 lines (4-42), well past the roughly 12-line header guideline for source comments. Consider keeping @input, @output, @position and the SYNC: list here and moving the explanatory paragraphs beside the code they explain.

* @output Exports MenuBottomSheet and MenuBottomSheetActionList wrappers that
* load the touch sheet on first render
* @position Internal to DropdownMenu
* @position Internal to DropdownMenu and ContextMenu

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, non-blocking: this header runs 23 lines (5-27), past the roughly 12-line header guideline. The hydration paragraph could sit beside the two wrappers it explains, leaving @input, @output and @position here.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 624a831

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

Approved pending CI: test is still running on this head.

ContextMenu now takes its sheet frame and action list from DropdownMenu's lazy sheet module, so pointer menus and Table cell menus no longer ship the action list in the first load. The new sheet-loading test fails on main and passes here, and the menu and table reference pages each drop about 20 KB gzip with no public API change.

Optional cleanups:

  • The two file headers this change edits (ContextMenu.tsx, 39 lines, and lazyMenuBottomSheet.ts, 23 lines) still run past the roughly 12-line header guideline.
  • Miss: the first sentence of the new Effect note (ContextMenu.tsx:394) runs 26 words over two topics; ending it after "presentation" keeps each sentence under the 25-word limit.
Claims and files checked

Review mode: same-head; reason: none

  • Claim: a pointer ContextMenu (the default presentation, and every Table cell menu) no longer carries the sheet's action list. Verified: the new pointer test fails on main with one load and passes here; Table's cell menu sets no presentation, so it takes the popover default.
  • Claim: ContextMenu now shares DropdownMenu's sheet module, which loads the sheet only for the sheet presentation. Verified: the new imports, the sheet-only render branch and the preload gated on a data-driven sheet menu in ContextMenu.tsx.
  • Claim: pages with a Table or a ContextMenu load about 57 KB less JavaScript, about 20 KB gzip. Verified: about 57 KB minified and 20 to 21 KB gzip less on the table, menu and ContextMenu pages.
  • Claim: a sheet menu still loads its sheet after mount and opens as before. Verified: the sheet test passes on main and here, and the preload runs in an Effect.
  • Claim: DropdownMenu already loads the same code through its lazy sheet module. Verified in DropdownMenu.tsx.
  • Claim: no behavior change and no public API change. Verified: the API comparison lists no added, changed or removed entries, CI's API report for this head agrees, and 471 tests pass.
  • Claim: no load moves to first open or to intent, so the import-boundary record's deferred-load rules are untouched. Verified: pointer menus never load the list and sheet menus load it at mount.
  • Claim: the sheet's back Button stays a static import. Verified in ContextMenu.tsx.
  • Claim: the ContextMenu record gains one PR1 sentence, and its test list and FR10/PR1 row cite the new test. Verified in the record diff.
  • Claim: the Table to ContextMenu boundary crossing remains and its cost drops. Verified: the check still lists it, at about 67 KB instead of about 87 KB.
  • Claim: the boundary check prints Table's eager gzip falling by about 19 KB. Verified: about 19.6 KB; the absolute sizes moved with main.
  • Claim: the page-level size table for Table, ContextMenu, DropdownMenu and Markdown. Verified for Table, ContextMenu and DropdownMenu; the Markdown page changes by under 1 KB gzip.
  • Claim: the pointer test fails on main and the sheet test passes on both. Verified.
  • Claim: the listed test run passes 18 files and 471 tests. Verified.
  • Claim: typecheck, ESLint on the changed files, the knowledge check, the shared-identity check and the boundary check pass. Verified, and CI's typecheck and lint pass on this head.
  • Claim: an Android emulator long press opens the sheet and drills in on both sides, and the take carries to this head. Stated by the author; it carries because the latest merge of main changes none of this pull request's files and no Core source file.
  • File .changeset/contextmenu-pointer-no-sheet-code.md: clear.
  • File docs/specs/components/ContextMenu/ContextMenu.spec.md: clear.
  • File packages/core/src/ContextMenu/ContextMenu.sheetLoading.test.tsx: clear.
  • File packages/core/src/ContextMenu/ContextMenu.tsx: clear, with the optional header and comment notes.
  • File packages/core/src/DropdownMenu/lazyMenuBottomSheet.ts: clear, with the optional header note.
  • Rule changed since the last review, the review mode line: checked this comment, no finding.
  • Rule changed since the last review, same-head re-review: checked that this head is the last reviewed head, then the description, labels, approvals and conversation, no finding.
  • Rule changed since the last review, how changed rules are established: checked the earlier and current review rules side by side (three rules changed), no finding.

Automated review (maintainer link)

Comment on lines +394 to +396
// Syncs the touch sheet's action list with the presentation: a data-driven
// sheet menu loads its rows at rest, so its first open shows them at once. A
// pointer menu never loads them.

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, non-blocking (missed in the earlier review): the first sentence here runs 26 words over two topics, past the 25-word limit for source-comment descriptions. Ending it after "presentation" fixes both:

Suggested change
// Syncs the touch sheet's action list with the presentation: a data-driven
// sheet menu loads its rows at rest, so its first open shows them at once. A
// pointer menu never loads them.
// Syncs the touch sheet's action list with the presentation. A data-driven
// sheet menu loads its rows at rest, so its first open shows them at once. A
// pointer menu never loads them.

@cixzhang
cixzhang marked this pull request as draft November 15, 2026 01:15

This branch was successfully deployed

1 active deployment
Preview — 624a8311 Deployed Nov 14, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant