Skip to content

fix: prevent Toast auto-dismiss timer from resetting on every parent re-render#605

Open
Rishikapurbey wants to merge 1 commit into
indresh404:mainfrom
Rishikapurbey:fix/toast-oncose-timer-reset
Open

fix: prevent Toast auto-dismiss timer from resetting on every parent re-render#605
Rishikapurbey wants to merge 1 commit into
indresh404:mainfrom
Rishikapurbey:fix/toast-oncose-timer-reset

Conversation

@Rishikapurbey

Copy link
Copy Markdown
Contributor

Fixes #545

Problem:
The useEffect setting Toast's 3-second auto-dismiss timer listed onClose as a dependency. Since call sites (e.g. Profile.jsx) pass onClose as an inline arrow function, it's a new reference on every parent render, causing the effect to re-run and reset the timer. If the parent re-renders before 3 seconds (e.g. due to a Firestore snapshot update), the toast never auto-dismisses.

Fix:
Captured onClose in a ref (onCloseRef) that's kept up to date via a separate effect. The timer-setting effect now has an empty dependency array, so it only runs once on mount and always calls the latest onClose via the ref — the timer is no longer affected by parent re-renders.

Files changed:

  • src/components/ui/Toast.jsx

Testing:

  • Verified a toast auto-dismisses after exactly 3 seconds even when the parent component re-renders multiple times within that window.
  • Verified manual close behavior (if applicable) still works via the latest onClose reference.

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ranker-hub Ready Ready Preview, Comment Jun 19, 2026 8:21am

@github-actions github-actions Bot added backend Backend/Firebase related changes bug Something isn't working enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review labels Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend/Firebase related changes bug Something isn't working enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Toast auto-dismiss timer resets on every parent render due to unstable onClose reference

1 participant