Skip to content

perf(Item): load the swipe gesture only when swipeActions is set - #7296

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/item-swipe-opt-in
Oct 11, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/item-swipe-opt-in

Conversation

@vjeux

@vjeux vjeux commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

An Item without swipeActions should ship none of the swipe gesture. Item.tsx imports useSwipeAction unconditionally and calls it on every render, so every row carries the gesture and the panels on first load. A bundler cannot drop a statically imported module a component may render, so paying nothing without swipeActions means loading the gesture on demand. Nothing is broken and no capability is added, so no other template fits.

User or maintainer impact

Every consumer rendering Item without swipeActions (a two-row sidebar surfaced it) loses the gesture and the panels from its initial load. A consumer with swipeActions keeps the same row DOM, props, types and behavior; the gesture arrives in a chunk requested during the row's first render, so on a cold load the row paints at once (the panels show nothing at rest) and becomes swipeable when the chunk lands.

Problem and solution fit

A hook cannot be conditional, so the gesture ran for every row: about 2.7 KB gzip no at-rest row executes, paid everywhere because Item is the row primitive behind lists, menus and navigation.

The gesture and the panels move to Item/ItemSwipeLayer.tsx, reached only through lazy(() => import('./ItemSwipeLayer')) inside <Suspense fallback={null}> and rendered into the root when swipeActions resolve to a served swipe, as today. The root stays Item's: it keeps the swipe root styles and forwards its pointer, click-capture and key events into a bridge the layer publishes, so no element is added and React's event model on the root is unchanged, the way ProgressBar and Timestamp already load an affordance. No public API change.

Authority

spec:AST-057 (current) governs; FR2 and DEC-5 (no element added; the root translates, the panels counter-translate) still hold and are tested. No new policy.

Change and evidence

esbuild, minified, React external, two rows imported from @astryxdesign/core:

rows before after
no swipeActions 34,428 B min / 11,641 B gzip 26,882 B min / 8,963 B gzip (−2,678 B gzip)
with swipeActions 11,671 B gzip, one request 8,993 B gzip + a 3,529 B gzip chunk

useSwipeAction, setPointerCapture and [data-swipe-panel] are absent from the initial load after and present in the chunk.

  • Item.source-build.test.mjs: the compiled Item.tsx reaches the layer only by a dynamic import and the gesture not at all.
  • Item.swipeLayer.test.tsx: rows without swipeActions never render the layer; a row with them renders the panel into the root, no wrapper.
  • The 21 swipe cases in Item.test.tsx are unchanged in substance (one warm-up render makes the layer synchronous); List.test.tsx and the Chromium spec wait for the panel.

Scope

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

Testing

  • pnpm vitest run --maxWorkers=4 packages/core/src/Item packages/core/src/List: 5 files, 146 passed.
  • pnpm vitest run packages/core: 369 files / 10,915 tests passed; the 28 failures are locale cases (Calendar, DateInput, NumberInput parsing, collation) on a Node built with small-icu, unrelated to this change.
  • pnpm -F @astryxdesign/core build, tsc --noEmit (core), pnpm check:repo: clean. ESLint on the touched files: no new warnings.
  • Changeset: [perf], patch.

Item imported useSwipeAction unconditionally and called it on every render,
so every consumer rendering a row without swipeActions shipped the swipe
gesture and the panel markup on its first load.

The gesture and the panels now live in ItemSwipeLayer, which Item reaches
only through a dynamic import, rendered inside the root when swipeActions
resolve to a served swipe. The root keeps the swipe styles and forwards its
pointer, click-capture and key events into a bridge the layer publishes, so a
swipeable row keeps its DOM (no element added) and React's event model on its
root. Item's public props and types are unchanged.

Two at-rest rows importing Item from the package root: initial load
11,641 -> 8,963 B gzip (-2,678 B); the swipe hook, setPointerCapture and the
panel marker are gone from it. The same rows with swipeActions: 8,993 B
initial + a 3,529 B gzip chunk carrying the hook and the panels.

Item.source-build.test.mjs pins the compiled import graph; Item.swipeLayer
.test.tsx proves a row without swipeActions never renders the layer. The
existing swipe suites are unchanged in substance: one warm-up render makes
the lazy layer synchronous for them, and the browser spec waits for the panel
before it drags.
@vercel

vercel Bot commented Oct 10, 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 10, 2026 9:18am UTC

Request Review

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

astracat-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 10, 2026, 9:25 AM UTC

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

Thanks — this looks good to land.

The split does what it promises: the gesture and panels move verbatim into a module Item only reaches through a dynamic import when a row has swipe actions, the root keeps its styles and forwards events into the layer, and the rendered DOM once loaded is the one from before (panel straight into the root, no wrapper). The new tests guard the important part well — the import-graph test means this can't quietly regress to a static import, and the runtime test shows rows without swipeActions never touch the layer. Existing swipe and List suites pass.

The one trade-off is already called out in the changeset and docs: on a cold load a swipe row paints immediately but only becomes swipeable once the chunk arrives, and swipe consumers pick up a small extra request. That's the same shape as the other lazy affordances in core, and since panels show nothing at rest there's no visual change while it loads.

[Automated review]

@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

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

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

24 of 444 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
TableRowExpansion Detail Panel neutral dark 5,129
TableRowExpansion Detail Panel neutral light 4,050
SideNav Resizable in AppShell probe dark 3,208
SideNav Resizable in AppShell probe light 3,208
TableGroupedRows Default neutral light 2,133
TableGroupedRows Default neutral dark 2,116
Markdown Default probe dark 897
Markdown Default probe light 897

and 4 more.


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

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

CodeBunny approved at this head; CI green. Approved.

@cixzhang
cixzhang enabled auto-merge (squash) October 11, 2026 17:14
@cixzhang
cixzhang merged commit 4398c51 into meta:main Oct 11, 2026
43 checks passed
@vjeux
vjeux deleted the perf/item-swipe-opt-in branch October 11, 2026 17:21

This branch was successfully deployed

1 active deployment
Preview — 2fc315ef Deployed Oct 10, 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.

2 participants