Skip to content

[docs] Refactor toast creation to use ref for count tracking instead of state - #5761

Merged
sai6855 merged 1 commit into
mui:masterfrom
sai6855:toast-unwanted-state
Sep 21, 2026
Merged

sai6855 merged 1 commit into
mui:masterfrom
sai6855:toast-unwanted-state

Conversation

@sai6855

@sai6855 sai6855 commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

This is 2nd PR in the react-doctor series. 1st being #5760

This PR replaces the handler-only toast counter state with a ref to avoid unnecessary rerenders and reliably generate incrementing toast titles in toast demos

@sai6855

sai6855 commented Sep 19, 2026

Copy link
Copy Markdown
Member Author

@claude review low

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

PR review

No merge-blocking issues. The five toast demos swap a useState counter for a useRef counter; since the count is never rendered, the ref is the correct tool and the change also removes a latent numbering glitch — the old code read the stale closure value (count + 1) while queuing setCount, so two clicks landing in the same batch (or a click before the re-render commits) could both title a toast Toast 1 created. The ref increments before use, so numbering is now monotonic.

No findings.

Residual notes: all five affected ToastButton components were converted consistently and no other toast demo still uses the old pattern; varying-heights has only a CSS Modules variant, so the absence of a Tailwind edit there is expected, not an omission. Docs demos have no test coverage, so this was verified by reading only — the demo output was not rendered.

Verdict

Approve - a behavior-preserving docs-demo refactor that also removes a stale-closure numbering edge case, with no correctness risk found.


🤖 Review generated with Claude Code · Opus 5 (High) · low review depth · 12 turns · 47s · $0.39 · run

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5761
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5761
    

commit: a395292

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

Total duration: 824.79 ms -12.70 ms(-1.5%) | Renders: 76 (+0) | Paint: 1,357.37 ms -30.99 ms(-2.2%)

No significant changes — details


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

@netlify

netlify Bot commented Sep 19, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a395292
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6aae2a7991c0cf0008e05f80
😎 Deploy Preview https://deploy-preview-5761--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.

@sai6855 sai6855 changed the title [docs] Refactor toast creation to use ref for count tracking instead … [docs] Refactor toast creation to use ref for count tracking instead of state Sep 19, 2026

function ToastButton() {
const toastManager = Toast.useToastManager();
const [count, setCount] = React.useState(0);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Replace the handler-only toast counter state with a ref to avoid unnecessary rerenders and reliably generate incrementing toast titles.

@sai6855
sai6855 marked this pull request as ready for review September 19, 2026 06:35
Copilot AI lite review requested due to automatic review settings September 19, 2026 06:35
@sai6855 sai6855 added docs Improvements or additions to the documentation. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Sep 19, 2026

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Refactors toast demo counters from state to refs, preserving sequential titles while avoiding unnecessary rerenders.

Changes:

  • Replaced counter state with refs.
  • Updated toast titles to use ref values.
File Description
docs/​src/​app/​(docs)/​react/​components/​toast/​demos/​varying-heights/​css-modules/​index.tsx Uses a ref for toast numbering.
docs/​src/​app/​(docs)/​react/​components/​toast/​demos/​position/​tailwind/​index.tsx Uses a ref for toast numbering.
docs/​src/​app/​(docs)/​react/​components/​toast/​demos/​position/​css-modules/​index.tsx Uses a ref for toast numbering.
docs/​src/​app/​(docs)/​react/​components/​toast/​demos/​hero/​tailwind/​index.tsx Uses a ref for toast numbering.
docs/​src/​app/​(docs)/​react/​components/​toast/​demos/​hero/​css-modules/​index.tsx Uses a ref for toast numbering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sai6855
sai6855 merged commit 345ddb1 into mui:master Sep 21, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants