Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/table-cell-lazy-context-menu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[perf] TableCell and TableHeaderCell load their right-click context menu only when the cell has `contextMenuActions`. A table without context menus no longer ships ContextMenu, DropdownMenu's menu code and the touch sheet: `import {Table} from '@astryxdesign/core/Table'` drops from about 358 KB to about 138 KB minified (124 KB to 48 KB gzip). A cell with actions renders its content at once and starts loading its menu on its first client render; the content keeps its DOM node, focus and state when the menu attaches. A right-click, Shift+F10 or long press that arrives before then is held and opens the cell's menu when it loads, unless another press or key comes first, so the browser's own menu does not appear. If the menu code fails to load, the table stays and the browser's own menu returns; a later mount, or a later right-click or touch on that cell, asks the module loader again. A test that expects the menu synchronously right after render has to wait for it to load. `resolveContextActions` keeps its export and no longer pulls the menu in.

@rhagigi @cixzhang
12 changes: 5 additions & 7 deletions docs/architecture/component-import-boundaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ one allowlist row. A module that an `import()` targets is a surface module.

Some modules in a surface or capability folder are base code: the trigger
contract a surface folder keeps for base imports
(`Tooltip/tooltipPresentInterest`, `Layer/layerScopedContext`), and a
(`Tooltip/tooltipPresentInterest`, `Layer/layerScopedContext`,
`ContextMenu/ContextMenuTrigger`, and `Layer/gestureCounter`, which a trigger
reads to drop a held intent at a later press or key), and a
capability's own import (a Table plugin's folder index and the modules it
re-exports, and `SnapPaging/SnapPaging`). INV7's wiring lives in base code:
the component's own modules or the capability's own import. A wiring module
Expand Down Expand Up @@ -182,15 +184,14 @@ one pending load per module, caches a success, and resets after a failure.
| `Text/TruncationTooltip` → `Layer/useTouchTrigger` | Text, Heading, Button, IconButton, Link, Table | 4.6 KB (Text, Heading) | INV1, INV8 | the truncation tooltip's eager code carries no touch tap recognizer |
| `Button/Button` → `Tooltip/useTooltip` | Button, IconButton | 15.5 KB | INV1 | Button's tooltip layer code is lazy |
| `Link/Link` → `Tooltip` | Link | 17.6 KB | INV1 | Link's tooltip layer code is lazy |
| `Table/tableContextMenu` → `ContextMenu` | Table | 78.2 KB | INV1 | cells without actions reach no menu module |
| `Table/BaseTable` → `Table/plugins/virtualization/useTableWindow` | Table | 3.0 KB | INV7 | a Table that never windows reaches neither the controller nor its engine |

Costs are the check's own printout in CI: each crossing's removal from the
entry with every other crossing kept, in the entry build above. A local run
on another platform or Node version can print gzip sizes a few tenths of a KB
apart. Rows share modules, so they do not add up. The truncation tooltip's touch code costs Button,
IconButton, Link, and Table nothing on its own, because another of their
crossings brings the same module. Table carries 123.5 KB eager.
IconButton, and Link nothing on its own, because another of their crossings
brings the same module. Table carries 123.5 KB eager.

## Current-state impact

Expand All @@ -210,9 +211,6 @@ crossings brings the same module. Table carries 123.5 KB eager.
not surfaces carry 17–24 KB of tooltip code, and 52 carry at least 1 KB.
- INV1 gap: Link's import reaches the Tooltip component and the layer
runtime, 17.6 KB gzip, with or without a `tooltip` prop.
- INV1 gap: Table's import reaches the cell context menu, 78.2 KB gzip, for
cells with no actions, while `component:TableCell` PR1 loads a menu only
when actions are given.
- INV7 gap: Table's import reaches the window controller and the shared
windowing module, 3.0 KB gzip, for a Table that never windows.
- INV3 gap: no record says how a tooltip's description reaches assistive
Expand Down
15 changes: 13 additions & 2 deletions docs/specs/components/ContextMenu/ContextMenu.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ Consumer migration instructions belong in consumer docs and release notes.
`context-menu` target.
- Cursor-anchor placement across the two presentation paths, and open state
(FR10).
- `ContextMenuTrigger`, the internal module that renders the Trigger area's
wrapper and its cursor anchor. ContextMenu renders it, and a table cell
renders it before its menu code loads, so the cell's content keeps its node
when the menu attaches. It imports no menu code, so a base import can carry
it (`architecture:component-import-boundaries` INV1).
- `ContextMenuForTrigger`, the internal mode that opens the same menu around a
trigger the caller already renders (a table cell), since `ContextMenu`
renders its own trigger. No public entry exports either module.

**Does not own / non-goals**

Expand Down Expand Up @@ -111,7 +119,7 @@ Consumer props, content modes, and presentation policy remain documented in
| FR7 | Sub-menu rows follow `component:DropdownMenu` FR11 inside the pointer menu: ContextMenu mounts the same drill-in view stack, named after its `label`, so a sub-menu drills in on a phone here too. A sub-menu with a header or footer shows its rows alone here (`component:DropdownMenu` FR20). | `component:DropdownMenu/DEC-4` |
| FR8 | In the pointer menu ArrowDown on the last row wraps to the first and ArrowUp on the first to the last; PageDown and PageUp page as in `component:DropdownMenu` FR12; a held key's auto-repeat does not activate; typeahead matches the row's label element alone. A disabled row is reached by these keys and by typeahead and stays inert, as `component:DropdownMenu` FR17 states. | Current source and tests |
| FR9 | While the Pointer menu surface is open, it participates in `family:overlay-dismissal` through the shared stack and provides descendant depth. One Escape press affects only the top-most present nested surface; ContextMenu closes only when it is that surface. | `family:overlay-dismissal` FR1–FR6; `ContextMenu.test.tsx` nested-layer case |
| FR10 | ContextMenu MUST be built on the public headless context menu (`spec:AST-107` FR8), with its invocation, open state, and cleanup the factory's and no behavior of its own beside the factory's. Implementation gap: no headless context menu ships; ContextMenu owns its invocation, open state, outside-press listener, and cleanup itself. | `spec:AST-107` FR8 |
| FR10 | ContextMenu MUST be built on the public headless context menu (`spec:AST-107` FR8), with its invocation, open state, and cleanup the factory's and no behavior of its own beside the factory's. Implementation gap: no headless context menu ships; ContextMenu owns its invocation, open state, outside-press listener, and cleanup itself. Table cells open the same menu through the internal `ContextMenuForTrigger` mode, around a trigger the cell renders. The cell holds an invocation that arrives before the menu loads. | `spec:AST-107` FR8 |
| FR11 | Tab or Shift+Tab on a row of the pointer menu, its own or an open sub-menu flyout's at any depth, closes every open level and the menu and calls `onOpenChange(false)` once, as `component:DropdownMenu` FR23 states for its menu. | WAI-ARIA Menu Button pattern; current tests |

### Allowed variation
Expand Down Expand Up @@ -267,7 +275,10 @@ anchor is positioning infrastructure rather than consumer anatomy.

- **No headless factory (FR10).** No headless context menu ships, so ContextMenu
owns its invocation, open state, and outside-press listener itself, against
`spec:AST-107` FR8.
`spec:AST-107` FR8. Table cells open the same menu through the internal
`ContextMenuForTrigger` mode, around a trigger the cell renders, and the cell
holds an invocation that arrives before the menu loads. Both are part of
this gap.
- **Touch grow, pan dismissal, handoff, and lift (FR5).** A touch-opened
menu keeps the layer's own entrance and exit instead of growing from the
finger, a scroll that starts outside leaves it open, the held finger that
Expand Down
Loading