baseweb
baseweb copied to clipboard
ToasterContainer sets toasterRef on constructor(), not on mount
Current Behavior
- Any time ToasterContainer is constructed, it overwrites the static
toasterRef. This isn't very Reacty(tm), especially moving into Suspense, since component instantiation doesn't always mean it will be mounted (and therefore shouldn't be the new handler fortoaster.show()calls) - In our fairly complex next.js based application, we find ToasterContainer's constructor is fired on (pushState) page navigation, but its
componentWillMountfunction is not fired. - This means when the latest ToasterConstructor instance's
.show(children)method callsthis.setState, the setState callback does not fire (as it's not mounted)
Expected Behavior
toaster.show()should call the latest mountedToasterContainer.show, ideally the closest one in the component tree.- If the latest ToasterContainer is not mounted,
toaster.showshould show the same error as if no ToasterContainer was mounted at all.
Your Environment
| Tech | Version |
|---|---|
| Base UI | 9.79.0 |
| React | 16.13.1 |
| next | 9.4.0 |
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Thank you for the report @grrowl. Can you include a reproduction case displaying the navigation change bug that we can test against?