Repository navigation
perf(Layer): LayerProvider loads no Toast; Toast registers its viewport - #10012
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| 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
There was a problem hiding this comment.
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.tsxlines 125-134), which breakscomponent:ToastFR3, so call the entry'sonHideonce when it is dropped and add that case totoastHost.lateRegistration.test.tsx. - The outlet's capture-and-queue (
HostContextCaptureandwaitingRefintoastHost.tsx) repeats the fallback proxy inToast/useToast.tsx, and the two already treat an early dismissal differently, so move it into one shared helper that both use. component:LayerProviderFR1, its Behavior row and its Root provider state still say the root provider mounts one toast viewport aroundchildren, so amend that record in this pull request alongsidearchitecture:layer-runtime.
[Automated review]
| removeToast: (id, reason) => { | ||
| const host = hostContextRef.current; | ||
| if (host == null) { | ||
| waitingRef.current = waitingRef.current.filter( | ||
| entry => entry.id !== id, | ||
| ); | ||
| } else { | ||
| host.removeToast(id, reason); | ||
| } | ||
| }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| onContext: (context: ToastContextValue | null) => void; | ||
| }) { | ||
| const context = use(ToastContext); | ||
| // Synchronizes the outlet with the toast context of the viewport it renders. |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Taken in e54fde1, on the Effect in ToastQueueConnector.
0cac166 to
e54fde1
Compare
There was a problem hiding this comment.
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.tsxlines 110-123), althoughcomponent:ToastFR3 says a toast replaced throughuniqueIDreports noonHide, so skiponHidein those two cases and add both totoastHost.lateRegistration.test.tsx. docs/specs/components/Toast/Toast.spec.mdFR3 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 linktoastHost.test.tsxfrom the record.
The three items from the previous review are fixed.
[Automated review]
| 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); | ||
| }, |
There was a problem hiding this comment.
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'`. |
There was a problem hiding this comment.
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.
e54fde1 to
21145dc
Compare
|
/approve-spec 21145dc |
There was a problem hiding this comment.
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
uniqueIDnamesake has replaced, or an ignored namesake, reportsonHide('manual')when it is dismissed before the viewport connects (packages/core/src/Layer/toastHost.tsxlines 110-123), althoughcomponent:ToastFR3 and FR8 say such a toast reports noonHideand main reports none, so skiponHidein those two cases and test both intoastHost.lateRegistration.test.tsx. docs/specs/components/Toast/Toast.spec.mdFR3 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 linktoastHost.test.tsxfrom 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); |
There was a problem hiding this comment.
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'`. |
There was a problem hiding this comment.
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.
21145dc to
899aacc
Compare
There was a problem hiding this comment.
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.tsxlines 162-167) disconnects the queue in its Effect cleanup whenever the viewport's context changes, so underLayerProvidera toast'sdismiss()called from an effect in the commit that changestoast.maxVisibleis dropped (the toast stays andonHidenever runs) althoughcomponent:ToastFR3 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 totoastHost.test.tsx.
CI has not run on this head yet; a maintainer adds the ci:run label so it runs.
[Automated review]
| useEffect(() => { | ||
| queue.connect(viewport); | ||
| return () => { | ||
| queue.connect(null); |
There was a problem hiding this comment.
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.
899aacc to
2cac4d1
Compare
|
/approve-spec 2cac4d1 |
There was a problem hiding this comment.
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 namesLayerProvider,ToastContext,useToastandToastViewportas the owners of notification state; namingLayer/toastHost.tsx, which now owns the context, the registration and the shared queue, keeps that list in step with INV10.
[Automated review]
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.
2cac4d1 to
c6337eb
Compare
There was a problem hiding this comment.
This pull request is reviewed as part of its stack; see the review on #8047.
|
/approve-spec c6337eb |
…nchanged; touch-support list keeps both entries)
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.
…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.
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.
* 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]>
Stack: #10012 → #8047
Primary intent
Every app with a
LayerProviderloads Toast's code, because the provider rendersToastViewport. This moves that cost to apps that import Toast.User or maintainer impact
LayerProviderfrom@astryxdesign/core/Layer; one that shows toasts loads 0.3 KB more.Problem and solution fit
LayerProviderloads.Layer owns the toast context and an outlet (
Layer/toastHost.tsx);ToastViewport.tsxregisters itself as it loads. The outlet always provides the context, so the app never remounts. The outlet anduseToast's fallback root share one queue, which holds early toasts and reportsonHidefor one dismissed while waiting. No public API changes.Authority
architecture:layer-runtimeINV10 and its current-surfaces paragraph now say: "LayerProvider alone renders no empty viewport; Toast registers its viewport when imported."component:LayerProviderFR1 and its summary rows say the same, andcomponent:ToastFR3 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:
LayerProviderfrom/LayerLayerProviderfrom the root/LayerLayerProvider+useToastfrom the root/ToastWriting 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
The fallback
[fix]stays: the review asked for one shared queue, which brings the dismiss rule there.Testing
Confirmed at
c6337eb803, one commit onmainbfc1dccfc0:toastHost.lateRegistration.test.tsx) or in the app's first effect (toastHost.test.tsx), it renders exactly one row.onHideonce 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 changestoast.maxVisiblestill reportsonHide, and under StrictMode a toast shows once. An emptyuniqueIDnames no toast in the queue, as in the viewport: one helper decides for both. Red arms: 4d0f9b0 (noonHidecall) fails the outlet case; 0b38124 (main'suseToast.tsx) fails the fallback case; 5132fa8 (no uniqueID rules while waiting) fails both namesake cases; 6770e73 (a connector that disconnects on every change) fails themaxVisiblecase; b00d900 (the queue's own copy of the rule) fails the empty-uniqueIDcase.renderToStringgives<p>App</p>,hydrateRootreports 0 recoverable errors, and the viewport mounts after hydration.ToastViewport.tsxdrops the toasts on screen, on main too. An edit toLayer/toastHost.tsxremounts the app, as an edit toToast/ToastContext.tsdoes on main, because Fast Refresh cannot refresh a module that exports a context. An edit toToast.tsxkeeps the toasts on both.LayerProvider.tsx,ToastViewport.tsx,ToastContext.tsanduseToast.tsx, with these tests) fails its three Layer cases, and the server-render case.useToastGesture.tsis inuseToast's static closure, not behind animport()(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 isimport-hint-correctness.test.mjs"builds its fixture", a 30 s timeout under load: a known load red onmain, with its own fix in progress. The other,integration-check.test.mjs, passes alone at this head and onmain.2cac4d1cbbfailed one test-ui case,Breadcrumbs.test.tsx"preserves outside focus after a browser light dismiss". It ismain'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 atmainand 0 of 10 at this head; alone, 0 of 10 on both.LayerProvider.test.tsx6/6; its inset cases importToastViewport, as an app that shows toasts does.Toast/ToastContext.tsre-exports the context, soastryx component ToastContextstill 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.tsxkeeps main's two warnings.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.