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

Component: The Snackbar auto-dismissal timeout is reset on every rerender #58594

Closed
Mamaduka opened this issue Feb 2, 2024 · 0 comments · Fixed by #58604
Closed

Component: The Snackbar auto-dismissal timeout is reset on every rerender #58594

Mamaduka opened this issue Feb 2, 2024 · 0 comments · Fixed by #58604
Assignees
Labels
[Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@Mamaduka
Copy link
Member

Mamaduka commented Feb 2, 2024

Currently, the Snackbar auto-dismissal timeout is reset on every rerender. The timers are reset when a notice is added or removed from the SnackbarList. This causes them to be visible a lot longer than expected.

Why

The onRemove callback has a new reference on each rerender, triggers side-effect cleanup, and resets timers.

Possible Solution

Omit onDismiss and onRemove from the side-effect dependencies.

  • I think it is safe to assume that the onDismiss callback snapshot won't change after the action is dispatched.
  • We can't memoize the curried onRemove function. It will always return a new function.

Step-by-step reproduction instructions

  1. Open a post or page.
  2. Insert a block.
  3. Trigger a few snackbar notices. Copying a block can do that.

Expected behavior

Let's assume there is a one-second difference between message triggers.

Message 1 - 10s
Message 2 - 10s + 1s
Message 3 - 10s + 2s

Current behavior

Message 1 - 10s
Message 2 - 20s (10s after first message)
Message 3 - 30s (10s after second message)

cc @WordPress/gutenberg-components

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Feb 2, 2024
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant