-
Notifications
You must be signed in to change notification settings - Fork 39
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
Toast is not shown during first trigger #1005
Comments
We talked offline and this seems to be because of react 18 (and 17) batching updates. Wrapping I thought about maybe adding If we get more users who face this issue in the future, we can revisit this. |
I think we also had this issue in our project, but solution added was to call |
that's really strange. it might have something to do with the async nature of (async () => {
await toaster.closeAll();
await toaster.positive();
await toaster.informational();
})(); |
@igneqas I've created a PR #1025 which will allow you to do this: const toastSuccess = async (message: string) => {
await toaster.closeAll();
toaster.positive(message, { type: "temporary" });
}; But I have no way to test this because I can't reproduce your issue. Can you test in your app by changing the code inside your node_modules? I can also make a snapshot release if that's easier for you. @veekeys Would be nice if you could also test, but no worries if not. |
@mayank99 Give me a day or so as its busy week, I will try to test it in the code we have faced this issue! |
@mayank99 Hey, it would be great if you could create a snapshot for me, thanks. |
Released it in the
|
I tested the new changes and it didn't change anything. The problem is still there. |
That's unfortunate. well, i can't repro and least there's two workarounds now, so i'll close this issue. I expect that at some point we will refactor the toaster anyway. |
fyi, all async behavior has been removed in #1351 which will be released in 3.0. this snippet now works without hacks: const toaster = useToaster();
<Button onClick={() => toaster.positive('hello')}>Show</Button>
<Button
onClick={() => {
toaster.closeAll();
toaster.positive('hello');
}}
>
Close all
</Button> Screen.Recording.2023-06-13.at.4.50.19.PM.mov |
Describe the bug (actual behavior)
After upgrading to iTwinUI v2, toasts do not show up the first time they are triggered but it works fine from the second time (only in our project). I tried recreating the problem in a new project but it works correctly there.
Expected behavior
Toast should be visible the first time it is triggered.
Reproduction
Could not be reproduced on a new project.
Additional information
iTwinUI - 2.2.0
React - 18
We did not modify our code for toasts after upgrading to v2. Also, the code is executed and toast is being created during the first trigger but it just doesn't show up. Our code is simple:
I guess this is some kind of timing issue, because, for example, if I add a 2 second sleep function between toaster.closeAll() and toaster.positive() it does show up during the first trigger (or calling toaster.closeAll() during the first render of the app).
The text was updated successfully, but these errors were encountered: