-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Snackbar] Reopens when message prop is an element #3186
Comments
We plan on removing state from these components entirely so this check will never have to happen 😁 |
The state is here to perform the animation. From my perspective, event if we use react-motion to remove the state, the check will still be needed. |
Hmmm you have a point O.o |
I'm wondering if the best fix for this wouldn't be on the user side. |
Hmm, yeah that does seem like a better solution. I wonder if there should be a warning in the docs that using an element or array type node for the message will require some care in this regard. |
I can't find a way to display such warning 😕. Any idea? |
if I pass a same key prop on the element, it that possible to determine it' same one? |
@oliviertassinari I just added a bit of a warning in the |
@yinickzhou I think the best solution is to actually use the same element if you want the I'm not sure how your code is set up, but an idea is to have the |
@yinickzhou I like this So, what about adding an optional let messageChanged = false;
if (nextProps.messageId) {
if (nextProps.messageId !== this.props.messageId ) {
messageChanged = true;
}
} else if (nextProps.message !== this.props.message) {
messageChanged = true;
} |
@thefivetoes I understand why the same element is important, I just think that's not straightforward for the users. |
@yinickzhou I think you mean to name check @theosherry? |
yes, sorry about that @thefivetoes |
@yinickzhou I agree it's not all that clear when using I prefer the solution of having the user ensure the |
@theosherry @yinickzhou Thanks for the feedbacks. We have merged the PR regarding documenting the behavior. I would say, let's close this issue and see how people react. If this is still an issue, we can reopen it and start looking for better solution. |
I would prefer the messageId solution proposed by @oliviertassinari The use case I'm running into is that I want the snackbar to stay on the screen with a 60 second countdown inside of it. I'm using an interval to count down the seconds, storing it in state, then pulling it into the Snackbar:
Obviously the message is different every time, but I want the snackbar to persist on the screen. Allowing me to pass a messageId would solve my problem, and the more general case of dynamic content in Snackbars. |
@rsteckler That sounds like a valid use case. I'm reopening the issue. |
IMHO, this is an edge use-case, out of spec, and isn't really what the Snackbar is intended for, so @rsteckler should implement a custom component (using |
That's definitly an edge use-case. I think that it would be great to provide a stateless version of the |
That's a good point, although I would still be wary of implementing an additional prop to control that behaviour in the current implementation. What if this functionality was tied to the If that is set, the component is then inherently being used statefully, so the current behaviour for re-animating on message change would apply. If This would satisfy both use cases with no additional props, and minimal additional logic. |
I think the above recommendation works. It basically puts the responsibility for expiring and queuing snackbars in the hands of the developer. I'm wondering, just for clarity, if having a new prop, 'stateless' with a default value of false would help. If stateless == true, then autoHideDuration is ignored. It just seems more explicit from a documentation point of view, rather than having a side effect attached to autoHideDuration even though they're very closely tied. |
That's one way to fix it, but I think that we have a better one. We could create a new @mbrookes @rsteckler What do you think? |
I think #2784 would have |
@mbrookes Since Snackbar doesn't have imperative methods, it's a good place for it 👍 I'll try to make a demo for it. |
For what it's worth, I found a workaround by having the message in an array. The source is using === checks which will check for array reference. As long as you are using the same array reference, no reopens will happen. |
@juneidysoo do you mind providing an example using the array formulation? I still can't quite get it to work. |
@oliviertassinari, I'm a little confused as to how I would memoize @theosherry's example in this comment. Do you mind giving me a short snippet describing how the |
@azaslavsky My solution is almost the same as @oliviertassinari memoization. Unfortunately I cannot easily provide you any example code because I have since moved on to other UI library. P.S. why are you still using this old version? it's 2 years old lol |
This bug happened only when the "message" prop passed as an element(not string)
When the snackbar rendered with same props, it triggers snackbar hide and show..
The reason is the message prop could be an object that never be equal with last one

The text was updated successfully, but these errors were encountered: