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
Refactor logic to prevent breaking changes in useToastState #6270
Conversation
Build successful! 🎉 |
Build successful! 🎉 |
Never mind, I fixed it.
|
Build successful! 🎉 |
Build successful! 🎉 |
remove(key: string) { | ||
let index = this.queue.findIndex(t => t.key === key); | ||
this.visibleToasts = this.visibleToasts.filter(t => t.key !== key); | ||
this.updateVisibleToasts(index); | ||
this.queue = this.queue.filter(t => t.key !== key); | ||
this.updateVisibleToasts('remove'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure about whether or not to have this.queue = this.queue.filter(t => t.key !== key);
in here or not. The code works without it assuming the user calls close
and then remove
and would allow us to remove the key
input argument. However, if the user calls just remove
then we need the aforementioned line to make sure the queue is properly updated and thus visibleToasts
gets updated as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it does work, the remove() is just doing some cleanup to the dom by removing the object from the dom.
The close button not closing until you move the mouse was related to close() not remove(), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably good to keep it to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the extra update to the queue in the remove
call is to ensure the queue as our source of truth is still up to date in case the user only calls remove
.
The close button not closing until you move the mouse was related to close() not remove(), right?
yeah it previous happened to use since we weren't always making an update to visibleToast
that would cause a state change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got rid of the extra update to queue in the remove
call since this was prematurely removing toasts that get pushed out of visibility by higher priority toasts. In RSP the flow that happens when a toast is pushed out of visibility is as follows:
new toast add
animates in -> toast that is no longer visible gets close
called by its onAnimationEnd
Build successful! 🎉 |
@@ -159,30 +155,27 @@ export class ToastQueue<T> { | |||
if (index >= 0) { | |||
this.queue[index].onClose?.(); | |||
this.queue.splice(index, 1); | |||
let closedToast = this.visibleToasts.find(t => t.key === key); | |||
if (closedToast) { | |||
closedToast.animation = 'exiting'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if there will be problems due to mutating the toast, which is passed into props of a component...
this.visibleToasts = toasts; | ||
if (action === 'close' && this.hasExitAnimation) { | ||
// Cause a rerender to happen for exit animation | ||
this.visibleToasts = this.visibleToasts.map(t => t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One change in logic here is that previously, if the number of visible toasts exceeded the maxVisibleToasts
setting, the toasts that got pushed off the end would animate out. Now they won't. Only toasts that are explicitly closed by clicking the X button will animate. Is that expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh didn't realize that was a case here. Will revisit how we apply the .animation
then and see if we can move it back into here somehow
…he visibleToast list due to a higher priority toast being added
Build successful! 🎉 |
… from the queue this mimics the exitAnimation call to close that RSP toast does
Build successful! 🎉 |
You can test the behavior of the toasts with priority in the toast story here on this branch as well: #6290 |
Build successful! 🎉 |
} else { | ||
this.queue.unshift(toast); | ||
} | ||
this.queue.splice(low, 0, toast); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a breaking change or was this.queue.unshift(toast);
a bug we hadn't found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts the logic to what is currently released
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I just remembered that and was coming back to delete it, but you responded.
Build successful! 🎉 |
Build successful! 🎉 |
735fcab
Build successful! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for this release but we are planning to refactor this more later
Build successful! 🎉 |
## API Changes
unknown top level export { type: 'any' } |
Closes #4244
✅ Pull Request Checklist:
📝 Test Instructions:
Test toast stories. Behavior should still be that new toasts are inserted at the bottom of the stack. Toast exit animations should still work
🧢 Your Project:
RSP