[toast] Reduce bundle size#5219
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,290.32 ms +106.81 ms(+9.0%) | Renders: 78 (+0) | Paint: 1,994.85 ms +153.47 ms(+8.3%)
12 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR is part of the toast bundle-size minimization effort, refactoring @base-ui/react/toast internals to remove dead/duplicate code paths, inline CSS var enum values (with a new sync test), and simplify store/component logic while aiming for no behavior changes.
Changes:
- Simplifies toast state/store APIs (signature tightening, helper removal, deduped logic) and updates affected call sites/tests.
- Deduplicates
Toast.Title/Toast.Descriptionvia a shared hook and streamlines several parts to returnuseRenderElement(...)directly. - Inlines CSS variable names in toast parts and adds an enum-sync test to keep runtime strings pinned to the documented enums.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/toast/viewport/ToastViewport.tsx | Merges global listener effects, removes enum indirection for CSS var, and simplifies hover/leave logic. |
| packages/react/src/toast/utils/useToastLabelPart.ts | New shared hook to dedupe Title/Description logic and ID registration. |
| packages/react/src/toast/useToastManager.ts | Uses the shared provider context hook instead of direct context access. |
| packages/react/src/toast/title/ToastTitle.tsx | Refactors to use useToastLabelPart and simplifies render flow. |
| packages/react/src/toast/description/ToastDescription.tsx | Refactors to use useToastLabelPart and simplifies render flow. |
| packages/react/src/toast/store.ts | Shrinks store surface area and simplifies several internal flows (timers, updates, focus scan). |
| packages/react/src/toast/store.test.ts | Updates tests to match new store method signatures. |
| packages/react/src/toast/root/ToastRootContext.ts | Removes unused context members to reduce bundle surface. |
| packages/react/src/toast/root/ToastRoot.tsx | Inlines CSS var names, simplifies swipe logic/context memo, and adjusts height recalculation behavior. |
| packages/react/src/toast/provider/ToastProvider.tsx | Updates provider sync call to match new store API. |
| packages/react/src/toast/positioner/ToastPositioner.tsx | Inlines CSS var name and removes unnecessary memoization. |
| packages/react/src/toast/enumSync.test.tsx | New test that pins inlined CSS var strings to the exported enums. |
| packages/react/src/toast/content/ToastContent.tsx | Simplifies to return useRenderElement directly (no behavior change intended). |
| packages/react/src/toast/close/ToastClose.tsx | Simplifies to return useRenderElement directly and relies on root context for expanded. |
| packages/react/src/toast/arrow/ToastArrow.tsx | Simplifies to return useRenderElement directly. |
| packages/react/src/toast/action/ToastAction.tsx | Uses enabled to avoid rendering when not needed, reducing branching. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
da57db6 to
db97bd5
Compare
Reduces the
@base-ui/react/toastbundle size without changing behavior or the public API. The bundle bot is authoritative for the current size impact.This removes dead context members and selectors, deduplicates Title and Description logic, consolidates store and effect logic, and inlines internal CSS-variable enum values. Regression and enum-sync tests cover the retained behavior and strings.