Skip to content

[toast] Reduce bundle size#5219

Merged
atomiks merged 5 commits into
mui:masterfrom
atomiks:claude/toast-component-simplify-701b67
Jul 13, 2026
Merged

[toast] Reduce bundle size#5219
atomiks merged 5 commits into
mui:masterfrom
atomiks:claude/toast-component-simplify-701b67

Conversation

@atomiks

@atomiks atomiks commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reduces the @base-ui/react/toast bundle 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.

@atomiks atomiks added performance component: toast Changes related to the toast component. labels Jul 13, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown

commit: db97bd5

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-1.62KB(-0.35%) ▼-316B(-0.21%)

Details of bundle changes

Performance

Total duration: 1,290.32 ms +106.81 ms(+9.0%) | Renders: 78 (+0) | Paint: 1,994.85 ms +153.47 ms(+8.3%)

Test Duration Renders
Checkbox mount (500 instances) 96.30 ms 🔺+20.52 ms(+27.1%) 1 (+0)
Mixed surface mount (app-like density) 80.98 ms 🔺+19.57 ms(+31.9%) 5 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Mixed surface mount (app-like density) bench:paint 🔺 +29.64 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit db97bd5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a54ef69bb529f00081fceb7
😎 Deploy Preview https://deploy-preview-5219--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.Description via a shared hook and streamlines several parts to return useRenderElement(...) 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.

Comment thread packages/react/src/toast/root/ToastRoot.tsx
@atomiks
atomiks marked this pull request as ready for review July 13, 2026 10:54
@atomiks
atomiks force-pushed the claude/toast-component-simplify-701b67 branch from da57db6 to db97bd5 Compare July 13, 2026 14:00
@atomiks
atomiks merged commit 1342a27 into mui:master Jul 13, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: toast Changes related to the toast component. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants