Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Fix the Snackbar auto-dismissal timers #58604

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/components/src/snackbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function UnforwardedSnackbar(

useSpokenMessage( spokenMessage, politeness );

// Only set up the timeout dismiss if we're not explicitly dismissing.
useEffect( () => {
// Only set up the timeout dismiss if we're not explicitly dismissing.
const timeoutHandle = setTimeout( () => {
if ( ! explicitDismiss ) {
onDismiss?.();
Expand All @@ -98,7 +98,10 @@ function UnforwardedSnackbar(
}, NOTICE_TIMEOUT );

return () => clearTimeout( timeoutHandle );
}, [ onDismiss, onRemove, explicitDismiss ] );
// The `onDismiss/onRemove` can have unstable references,
// trigger side-effect cleanup, and reset timers.
// eslint-disable-next-line react-hooks/exhaustive-deps
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
}, [ explicitDismiss ] );

const classes = classnames( className, 'components-snackbar', {
'components-snackbar-explicit-dismiss': !! explicitDismiss,
Expand Down
Loading