baseweb icon indicating copy to clipboard operation
baseweb copied to clipboard

ToasterContainer sets toasterRef on constructor(), not on mount

Open grrowl opened this issue 4 years ago • 1 comments

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 for toaster.show() calls)
  • In our fairly complex next.js based application, we find ToasterContainer's constructor is fired on (pushState) page navigation, but its componentWillMount function is not fired.
  • This means when the latest ToasterConstructor instance's .show(children) method calls this.setState, the setState callback does not fire (as it's not mounted)

Expected Behavior

  • toaster.show() should call the latest mounted ToasterContainer.show, ideally the closest one in the component tree.
  • If the latest ToasterContainer is not mounted, toaster.show should 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.

grrowl avatar Jun 11 '20 11:06 grrowl

Thank you for the report @grrowl. Can you include a reproduction case displaying the navigation change bug that we can test against?

chasestarr avatar Jun 11 '20 23:06 chasestarr