Skip to content

perf(Layer): LayerProvider loads no Toast; Toast registers its viewport - #10012

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/layer-toast-host
Nov 5, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/layer-toast-host

Conversation

@vjeux

@vjeux vjeux commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #10012 → #8047

Primary intent

Every app with a LayerProvider loads Toast's code, because the provider renders ToastViewport. This moves that cost to apps that import Toast.

User or maintainer impact

  • An app that never imports Toast loads about 44 KB less JavaScript (gzip) with LayerProvider from @astryxdesign/core/Layer; one that shows toasts loads 0.3 KB more.
  • Toasts behave as before; the swipe code stays a static import of Toast.
  • Without Toast, LayerProvider renders no empty viewport. Server HTML has no viewport; it mounts after hydration.
  • Without a provider, a toast dismissed before the fallback viewport mounts no longer shows; on main it did.

Problem and solution fit

  1. Why does every overlay app load Toast? The provider renders the viewport, so bundlers keep it and everything it imports.
  2. Why does that harm? That code is 43.7 KB of the 64.5 KB LayerProvider loads.
  3. Why does it matter? Every Dialog, Drawer or Popover app has one.

Layer owns the toast context and an outlet (Layer/toastHost.tsx); ToastViewport.tsx registers itself as it loads. The outlet always provides the context, so the app never remounts. The outlet and useToast's fallback root share one queue, which holds early toasts and reports onHide for one dismissed while waiting. No public API changes.

Authority

architecture:layer-runtime INV10 and its current-surfaces paragraph now say: "LayerProvider alone renders no empty viewport; Toast registers its viewport when imported." component:LayerProvider FR1 and its summary rows say the same, and component:Toast FR3 loses its fallback-dismissal gap. The INV10, LayerProvider and Toast verification rows add tests; their "default" wording is main's. The spec owners chose this design over a lazily loaded swipe (#9835).

Change and evidence

Static gzip -9 bytes per import, size-report esbuild options, main bfc1dcc:

Import main this PR
LayerProvider from /Layer 64,537 20,865
LayerProvider from the root 167,173 152,137
All of /Layer 72,375 57,959
LayerProvider + useToast from the root 180,958 181,218
All of /Toast 74,168 74,387

Writing rubric results

Both records: R1 present tense; R2 no research; R3 rows name tests; R4–R6 no rejected alternatives, change references or open questions.

Scope

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

The fallback [fix] stays: the review asked for one shared queue, which brings the dismiss rule there.

Testing

Confirmed at c6337eb803, one commit on main bfc1dccfc0:

  • A toast shown before the outlet mounts waits and shows once: added before Toast loads (toastHost.lateRegistration.test.tsx) or in the app's first effect (toastHost.test.tsx), it renders exactly one row.
  • A toast dismissed while it waits reports onHide once and never shows, through LayerProvider's outlet and through the fallback root. A waiting toast that a namesake replaced, or an ignored namesake, reports none (FR3, FR8). A dismissal in an effect of the commit that changes toast.maxVisible still reports onHide, and under StrictMode a toast shows once. An empty uniqueID names no toast in the queue, as in the viewport: one helper decides for both. Red arms: 4d0f9b0 (no onHide call) fails the outlet case; 0b38124 (main's useToast.tsx) fails the fallback case; 5132fa8 (no uniqueID rules while waiting) fails both namesake cases; 6770e73 (a connector that disconnects on every change) fails the maxVisible case; b00d900 (the queue's own copy of the rule) fails the empty-uniqueID case.
  • Server rendering: renderToString gives <p>App</p>, hydrateRoot reports 0 recoverable errors, and the viewport mounts after hydration.
  • Two React roots each get their own viewport and only their own toast.
  • The fallback root without a provider uses the same queue (the fallback case above).
  • Hot reload, in Storybook's Vite dev server with React Fast Refresh (probe and output: cdf6f02): an edit to ToastViewport.tsx drops the toasts on screen, on main too. An edit to Layer/toastHost.tsx remounts the app, as an edit to Toast/ToastContext.ts does on main, because Fast Refresh cannot refresh a module that exports a context. An edit to Toast.tsx keeps the toasts on both.
  • The bundle-boundary test is red on main: a79d0d3 (main's LayerProvider.tsx, ToastViewport.tsx, ToastContext.ts and useToast.tsx, with these tests) fails its three Layer cases, and the server-render case.
  • The size table above is measured at this head against main bfc1dcc. Dialog, Drawer, Popover and Button do not change.
  • Toast's swipe code loads eagerly: useToastGesture.ts is in useToast's static closure, not behind an import() (layer-toast-bundle.test.mjs; it passes on main too).

Gates:

  • pnpm test:ui: 840 files, 21,109 tests, 0 failed. pnpm test:node: 906 of 908 files pass. One failure is import-hint-correctness.test.mjs "builds its fixture", a 30 s timeout under load: a known load red on main, with its own fix in progress. The other, integration-check.test.mjs, passes alone at this head and on main.
  • CI at 2cac4d1cbb failed one test-ui case, Breadcrumbs.test.tsx "preserves outside focus after a browser light dismiss". It is main's: none of this change's modules load in that test. On one box at one time, under pressure (2 cores, 4 workers, beside the DropdownMenu and ContextMenu suites), it failed 2 of 10 runs at main and 0 of 10 at this head; alone, 0 of 10 on both.
  • LayerProvider.test.tsx 6/6; its inset cases import ToastViewport, as an app that shows toasts does. Toast/ToastContext.ts re-exports the context, so astryx component ToastContext still opens it (resolution-compat.test.mjs).
  • pnpm -F @astryxdesign/core typecheck, pnpm check:repo, pnpm review:pre (0 findings), Prettier, and ESLint in CI mode on the changed files: 0 errors. ToastViewport.tsx keeps main's two warnings.
  • Built Storybook in Chromium: the accessibility contracts routed to Layer and Toast, BottomSheetToastOutlet, and the 24 specs every pull request runs, 146 passed. "Shown On Mount" shows one toast on load at 1280×800 and 390×844, and its button adds another.
  • Prior art: no open pull request moves the toast viewport out of LayerProvider. fix(Toast): a quick flick dismisses a toast of any height #8047 (the swipe's first-move claim) stacks on this change.

@vercel

vercel Bot commented Nov 4, 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 5, 2026 11:02am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 5, 2026, 2:53 PM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 4, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 4, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c6337eb

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
LayerProvider 4.1 kB (−60.5 kB) · 20 B CSS (−9.4 kB) — ✓ · ✓ · ✗
Toast · Storybook 60.7 kB (0) · 9.0 kB CSS (0) 1,543 (−49) ✓ · ✓ · ✓
layer — — — · ✓ · —
1 more component
Component Size LoC Visual · A11y · RTL
Layer — — ✓ · ✓ · —

Package size: @astryxdesign/core 6.57 MB packed (+3.8 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 9 rows, core 4 rows; run pnpm api:report.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | 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.

Approval waits on an engineering owner's decision about the new LayerProvider behaviour, and three fixes are needed whatever they decide.

This pull request intentionally changes architecture:layer-runtime INV10 and its current-surfaces paragraph, so that LayerProvider renders no toast viewport until Toast is imported: none in server HTML, mounted after hydration, earlier toasts queued. Approval needs an engineering owner to update that existing spec for this change by approving or rejecting the new INV10 text; an engineering owner records the decision by commenting /approve-spec <full head SHA> on the pull request, and the author may do so as an engineering owner.

Required changes:

  • A toast dismissed while it waits in the outlet never reports onHide (packages/core/src/Layer/toastHost.tsx lines 125-134), which breaks component:Toast FR3, so call the entry's onHide once when it is dropped and add that case to toastHost.lateRegistration.test.tsx.
  • The outlet's capture-and-queue (HostContextCapture and waitingRef in toastHost.tsx) repeats the fallback proxy in Toast/useToast.tsx, and the two already treat an early dismissal differently, so move it into one shared helper that both use.
  • component:LayerProvider FR1, its Behavior row and its Root provider state still say the root provider mounts one toast viewport around children, so amend that record in this pull request alongside architecture:layer-runtime.

[Automated review]

Comment thread packages/core/src/Layer/toastHost.tsx Outdated
Comment on lines +125 to +134
removeToast: (id, reason) => {
const host = hostContextRef.current;
if (host == null) {
waitingRef.current = waitingRef.current.filter(
entry => entry.id !== id,
);
} else {
host.removeToast(id, reason);
}
},

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.

A waiting entry is dropped here without calling its onHide, so a toast dismissed before the viewport takes it (in the same commit as its first effect, during hydration, or before a lazily loaded Toast registers) never reports onHide('manual'), which component:Toast FR3 requires and the base did through pendingEntriesRef. Call entry.options.onHide?.(reason) once for the removed entry, and add the case to toastHost.lateRegistration.test.tsx.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e54fde1: the queue calls the entry's onHide once when it drops a waiting toast, as the viewport does for a pending entry. The drop case in toastHost.lateRegistration.test.tsx dismisses twice and expects one 'manual' call; it fails on 0afcace, which removes that call.

Comment thread packages/core/src/Layer/toastHost.tsx Outdated
Comment on lines +89 to +103
function HostContextCapture({
onContext,
}: {
onContext: (context: ToastContextValue | null) => void;
}) {
const context = use(ToastContext);
// Synchronizes the outlet with the toast context of the viewport it renders.
useEffect(() => {
onContext(context);
return () => {
onContext(null);
};
}, [context, onContext]);
return null;
}

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.

This capture, together with the waitingRef queue below, repeats FallbackCapture and the pending/proxy queue in Toast/useToast.tsx (lines 91-143), and the two already differ on a dismissal made while waiting. One shared capture-and-queue helper here, used by both the outlet and the fallback root, keeps them from drifting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in e54fde1: createToastQueue() and ToastQueueConnector in Layer/toastHost.tsx serve both the outlet and useToast's fallback root, which drops its own proxy and capture. So the fallback root now also drops a toast dismissed while it waits (its own [fix] changeset). The new fallback case in toastHost.test.tsx fails on dafac51, which restores main's useToast.tsx.

Comment on lines +398 to +403
LayerProvider supplies Toast configuration and an outlet for ToastViewport.
LayerProvider alone renders no empty viewport; Toast registers its viewport when
imported. The outlet then renders the viewport after the app, on the client
only, and a toast shown before that waits in the outlet. It is not a general
portal host for all layers. Without a provider, `useToast` creates a separate
React root under `document.body` and mirrors root theme attributes onto it.

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.

component:LayerProvider owns "Whether a provider mounts the toast viewport", and its FR1, Behavior row and Root provider state still say the root provider mounts one toast viewport around children. Amend that record in this pull request as well, so both current records describe the same provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Amended in e54fde1: FR1, the Behavior and Compatibility rows, the compatibility class, the root provider state and the verification row now say what INV10 says.

Comment thread packages/core/src/Layer/toastHost.tsx Outdated
onContext: (context: ToastContextValue | null) => void;
}) {
const context = use(ToastContext);
// Synchronizes the outlet with the toast context of the viewport it renders.

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.

Non-blocking: say why this runs in an Effect, for example "The viewport's addToast sets its state. Give it the waiting toasts after it commits."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Taken in e54fde1, on the Effect in ToastQueueConnector.

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

Approval waits on an engineering owner's decision about the new LayerProvider behaviour, and two fixes are needed whatever they decide.

This pull request intentionally rewrites architecture:layer-runtime INV10 and its current-surfaces paragraph, and component:LayerProvider FR1, so that the root provider renders no toast viewport until Toast is imported: none in server HTML, mounted after the app, earlier toasts held. Approval needs an engineering owner to approve or reject that spec change by commenting /approve-spec <full head SHA> on the pull request; the author may do so as an engineering owner.

Required changes:

  • A waiting toast that a namesake has replaced, or an ignored namesake, reports onHide('manual') when it is dismissed before the viewport connects (packages/core/src/Layer/toastHost.tsx lines 110-123), although component:Toast FR3 says a toast replaced through uniqueID reports no onHide, so skip onHide in those two cases and add both to toastHost.lateRegistration.test.tsx.
  • docs/specs/components/Toast/Toast.spec.md FR3 and its Current-state impact bullet still say that, without a provider, a dismissal before the fallback viewport mounts does nothing, which this pull request fixes, so remove that gap there and link toastHost.test.tsx from the record.

The three items from the previous review are fixed.

[Automated review]

Comment on lines +110 to +123
removeToast: (id, reason) => {
if (viewport != null) {
viewport.removeToast(id, reason);
return;
}
const entry = waiting.find(candidate => candidate.id === id);
if (entry == null) {
return;
}
waiting = waiting.filter(candidate => candidate !== entry);
// A toast dismissed while it waits still reports its hide, as the
// viewport reports one for a toast that has not rendered yet.
entry.options.onHide?.(reason);
},

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.

A waiting entry that a later waiting namesake has overwritten, or an ignore namesake of an earlier waiting entry, still reaches onHide here. Two namesakes raised in one mount effect, the first dismissed: the base reports no onHide (component:Toast FR3: "A toast replaced through uniqueID is not dismissed and reports no onHide"), this head reports 'manual'. Skip onHide in those two cases and add both to toastHost.lateRegistration.test.tsx.

'@astryxdesign/core': patch
---

[fix] Toast: without a LayerProvider, a toast dismissed before the fallback viewport mounts no longer shows, and its `onHide` runs once with `'manual'`.

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.

This closes the gap docs/specs/components/Toast/Toast.spec.md still lists in FR3 ("a dismissal called before the fallback viewport mounts does nothing, so the toast shows and stays") and in its Current-state impact bullet. Remove it there and add toastHost.test.tsx to that record's verified_by and FR3 verification row.

@vjeux
vjeux force-pushed the perf/layer-toast-host branch from e54fde1 to 21145dc Compare November 5, 2026 06:58
@vjeux
vjeux marked this pull request as ready for review November 5, 2026 06:59
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 21145dc

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

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

Changes requested: the new LayerProvider direction is approved, and two fixes remain before this can merge.

An engineering owner approved the spec change at this head, so a provider that renders the toast viewport only once Toast is imported is settled. Both remaining items were raised in the previous review and are unchanged:

  • A waiting toast that a uniqueID namesake has replaced, or an ignored namesake, reports onHide('manual') when it is dismissed before the viewport connects (packages/core/src/Layer/toastHost.tsx lines 110-123), although component:Toast FR3 and FR8 say such a toast reports no onHide and main reports none, so skip onHide in those two cases and test both in toastHost.lateRegistration.test.tsx.
  • docs/specs/components/Toast/Toast.spec.md FR3 and its Current-state impact bullet still say that, without a provider, a dismissal before the fallback viewport mounts does nothing, which this pull request fixes, so remove that gap there and link toastHost.test.tsx from the record.

CI has not run on this head yet; a maintainer adds the ci:run label so it runs.

[Automated review]

waiting = waiting.filter(candidate => candidate !== entry);
// A toast dismissed while it waits still reports its hide, as the
// viewport reports one for a toast that has not rendered yet.
entry.options.onHide?.(reason);

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.

This reports onHide('manual') for a waiting entry that a later waiting namesake has already replaced, or for an ignore namesake of an earlier waiting entry. component:Toast FR3 says "A toast replaced through uniqueID is not dismissed and reports no onHide", FR8 drops an ignore namesake even when both are raised before the first renders, and main reports nothing in both cases. Skip onHide in those two cases and add both to toastHost.lateRegistration.test.tsx.

'@astryxdesign/core': patch
---

[fix] Toast: without a LayerProvider, a toast dismissed before the fallback viewport mounts no longer shows, and its `onHide` runs once with `'manual'`.

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.

This closes the gap docs/specs/components/Toast/Toast.spec.md still lists in FR3 ("a dismissal called before the fallback viewport mounts does nothing, so the toast shows and stays") and in its Current-state impact bullet. Remove it there and add toastHost.test.tsx to that record's verified_by and FR3 verification row.

@vjeux
vjeux force-pushed the perf/layer-toast-host branch from 21145dc to 899aacc Compare November 5, 2026 07:40
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026
@vjeux
vjeux marked this pull request as draft November 5, 2026 07:54
@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 5, 2026

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

Changes requested: the toast-viewport records are approved at this head, and one fix remains before this can merge.

This head fixes both items from the previous review, and an engineering owner approved architecture:layer-runtime INV10, component:LayerProvider FR1 and the component:Toast FR3 amendment for it, so the provider that renders the viewport only once Toast is imported is settled.

  • Miss: ToastQueueConnector (packages/core/src/Layer/toastHost.tsx lines 162-167) disconnects the queue in its Effect cleanup whenever the viewport's context changes, so under LayerProvider a toast's dismiss() called from an effect in the commit that changes toast.maxVisible is dropped (the toast stays and onHide never runs) although component:Toast FR3 requires it to dismiss with 'manual' and main does; keep the connection across the change, for example by connecting in an Effect without cleanup and disconnecting in a separate unmount-only Effect, and add the case to toastHost.test.tsx.

CI has not run on this head yet; a maintainer adds the ci:run label so it runs.

[Automated review]

Comment thread packages/core/src/Layer/toastHost.tsx Outdated
Comment on lines +162 to +165
useEffect(() => {
queue.connect(viewport);
return () => {
queue.connect(null);

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.

This cleanup runs whenever the viewport's context value changes, and ToastViewport's context changes with maxVisible. React runs the app's effects of that commit before this Effect sets up again, so a dismiss() there finds no viewport and no waiting entry and is dropped: the toast stays and onHide never runs (component:Toast FR3; main dismisses with 'manual'). Keeping the connection across the change fixes it:

useEffect(() => {
  queue.connect(viewport);
}, [queue, viewport]);
useEffect(() => () => queue.connect(null), [queue]);

Please add the case (rerender with a new toast.maxVisible while an effect dismisses a shown toast) to toastHost.test.tsx.

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 2cac4d1

@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 is still running on this head, so this is not ready to merge until the required checks pass.

The toast-viewport records carry an engineering owner's approval for this head, and the earlier requested change is resolved: a dismiss() made in the commit that changes toast.maxVisible now reaches the viewport, with a test that fails without the fix.

  • Optional: docs/architecture/layer-runtime.md (lines 701-704) still names LayerProvider, ToastContext, useToast and ToastViewport as the owners of notification state; naming Layer/toastHost.tsx, which now owns the context, the registration and the shared queue, keeps that list in step with INV10.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 08:54
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 5, 2026
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 08:55
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 08:55
@vjeux
vjeux marked this pull request as draft November 5, 2026 09:17
LayerProvider rendered ToastViewport itself, so an app that renders a
provider loaded Toast's code with it, about 42 KB (gzip) from the Layer
entry. Layer now owns the toast context and an outlet. ToastViewport
registers itself when its module loads, and the outlet then renders it
after the app, on the client only. A toast added before the viewport
mounts waits in a queue that the outlet and useToast's fallback root
share, and a toast dismissed while it waits reports its onHide and never
shows.

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

This pull request is reviewed as part of its stack; see the review on #8047.

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec c6337eb

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 11:19
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 14:36
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 14:36
@cixzhang
cixzhang merged commit af7037b into meta:main Nov 5, 2026
174 of 175 checks passed
cixzhang added a commit to vjeux/astryx that referenced this pull request Nov 5, 2026
…nchanged; touch-support list keeps both entries)
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 5, 2026
The changeset from meta#10012 said about 42 KB. The size report's helper
(.github/scripts/lib/component-size.js, gzip at its default level)
measures `LayerProvider` from @astryxdesign/core/Layer at 69,280 bytes
before meta#10012 and 23,119 bytes after it: 46,161 bytes less, 45.1 KB at
1,024 bytes per KB.
cixzhang pushed a commit that referenced this pull request Nov 5, 2026
…10106)

chore(changeset): LayerProvider without Toast loads about 45 KB less

The changeset from #10012 said about 42 KB. The size report's helper
(.github/scripts/lib/component-size.js, gzip at its default level)
measures `LayerProvider` from @astryxdesign/core/Layer at 69,280 bytes
before #10012 and 23,119 bytes after it: 46,161 bytes less, 45.1 KB at
1,024 bytes per KB.
@vjeux
vjeux deleted the perf/layer-toast-host branch November 5, 2026 21:29
cixzhang pushed a commit that referenced this pull request Nov 5, 2026
docs(layer-runtime): toastHost owns the toast context and queue

Since #10012, `ToastContext` lives in Layer/toastHost.tsx, with Toast's
viewport registration and the queue that holds a toast until a viewport
takes it. The record's owning-code list still named `ToastContext`
beside LayerProvider, useToast and ToastViewport. It now names
toastHost.tsx and what it owns, as INV10 and its verification row
already do.
cixzhang added a commit that referenced this pull request Nov 6, 2026
* perf(Layer): LayerProvider loads no Toast; Toast registers its viewport

LayerProvider rendered ToastViewport itself, so an app that renders a
provider loaded Toast's code with it, about 42 KB (gzip) from the Layer
entry. Layer now owns the toast context and an outlet. ToastViewport
registers itself when its module loads, and the outlet then renders it
after the app, on the client only. A toast added before the viewport
mounts waits in a queue that the outlet and useToast's fallback root
share, and a toast dismissed while it waits reports its onHide and never
shows.

* fix(Toast): a quick flick dismisses a toast of any height

A release toward the edge dismissed past max(40% of the card's height,
48 px), or as a flick only when it had also travelled 48 px. On any toast
up to 120 px tall the two floors are the same distance, so a flick could
never dismiss a one-line toast. The flick now needs no travel of its own
beyond the slop the swipe already passed.

The flick's speed was also timed with Date.now() in the handlers. Browsers
deliver touch and pointer moves on the next frame, so the handlers trail the
finger by up to two frames (measured in Chromium: a 33 ms flick handled over
55 ms), which halved the speed of a short flick. It is now timed by the input
events' own timeStamp.

A bottom toast keeps its 16 px gap above the bottom safe-area inset instead of
sitting on the inset's edge. Under a coarse pointer it clears at least 34 px
plus that gap: Safari reports the inset only with `viewport-fit=cover`, so a
page without it read 0 and left the toast in the home indicator's area. Toast's
record (FR6) states that gutter.

A touch on the card is decided by its first move: toward the edge, the swipe
owns the touch; any other first move leaves the page its scroll (Toast FR4).
The gesture host makes that claim: the card attaches a one-way pan whose new
`firstMoveDecides` option holds a touch from a first move its own way and
fails on any other. Toast's own listeners only draw the swipe, and end it once
the pan leaves the touch to the page.

Importing Toast now brings in the shared gesture host: about 24 KB gzip on
its own, and nothing more where other touch components already load it.
LayerProvider does not import Toast, so a provider alone does not bring it in.

* fix(Toast): an empty viewport has no box, so Safari's toolbar recovers

iOS Safari colors its bottom toolbar from a fixed element at the bottom
edge. A swiped toast leaves through that edge inside the toast viewport,
and Safari kept the toast's color while the empty viewport still had a
box. The viewport now has no box while it holds no toast, and the
toolbar returns to the page color once the last toast leaves.

The Toast record lists the limit that remains: while other toasts
remain, a swiped toast's exit can tint the toolbar until the last toast
leaves.

* docs(Toast): the record names Safari's delay in restoring its toolbar's color

In the iOS Simulator, the toast viewport loses its box one frame after the
last toast's exit transitions end, and Safari restores its bottom toolbar's
color about 0.25 s after that. The Toast record's toolbar gap now says so.

* test(Toast): two browser specs' headers use shorter sentences

The @output lines of ToastEmptyViewport and ToastSwipeScroll each held one
long sentence, of 30 and 45 words. They now say the same in sentences of at
most 22 words.

* refactor(Toast): the swipe's touch handlers ride React's touch events

Toast's four touch listeners became passive once the gesture host took
over the claim, so they no longer need a native attach: React registers
touchstart and touchmove passively. They now come with the card's other
bindings, and the Effect that attached them is gone. The cleanup test now
checks that unmounting a toast leaves no touch listener on its card,
whoever added it.

* Merge main into the Toast swipe after #10012's squash (own diff unchanged; touch-support list keeps both entries)

Co-authored-by: Cindy Zhang <[email protected]>

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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