[URGENT] react-toast is injected to DOM by default causes multiple web app using Style UI 2.x to fail on load
See original GitHub issueBusiness Impact
- An on going issue on all deployed environments (dev, stage, prod)
- Blocking teams from adopting Styled UI 2.x
Problem
Root Cause
react-toast
component is injected to DOM by default when using Styled UI even if web application doesn’t use Toast component.
<html class="ext-strict">
<head>
...
</head>
<body>
<header id="top-header">...</header>
<main id="app" class="app">...</main>
<div id="react-toast" class="Toaster"> <!-- <==== injected to DOM by default when using Styled UI -->
...
</div>
</body>
</html>
- The underlying 3rd party library toast-note used by Toast component has the assumption that Toast component is only used by a single web app with a fixed ID: https://github.com/bmcmahen/toasted-notes/blob/master/src/Alert/Toast.tsx#L27
Effect & Impact
-
This becomes an issue if we dynamically mount and unmount microfrontend web apps (e.g. with single-spa) that uses Styled UI, as single-spa is the container for it.
-
<body>
element in DOM is littered with instance ofreact-toast
element injected from last microfrontend web apps using Styled UI
Reproduced Steps
The reproduced steps are very simple and captured on the internal JIRA, since it’s causing an incident and impacting our production environment, those details are only shared within the JIRA case. Please consult @ultralabed for detail.
Proposed Solutions
Workaround
- Change the default behaviour of Styled UI so it does not inject Toast component by default. However, without the proper fix (as proposed below) the of root cause, the problem will against resurface if multiple web app begin using Toast component.
Proper Fix on the Root Cause
- Fork the 3rd party library toast-note of that toaster component and modify the code to be able to pass in an ID where to inject the toast component. OR
- Find a new (and better) 3rd party component that only adds the notification component to the DOM on demand and removes itself from DOM immediately afterwards.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Toast style is not working correctly · Issue #202 · fkhadra/react ...
I installed last version of react-toastify. When I use simple demo toast: toast.error("TEST", { position: toast.POSITION.
Read more >How to create a custom toast component with React
Learn how to create a customizable toast component that is capable of displaying multiple notifications using the React hooks useState and ...
Read more >React-toastify showing multiple toast - Stack Overflow
The solution according to this thread would be remove all <ToastContainer /> of the components and render it in the app root, which...
Read more >Create A Toast Notification Component With React - YouTube
As it turns out.. creating a decent toast component with React is actually a bit more advanced than it might seem at first...
Read more >What is React Tostify: Types, Features, Installation and more
react toastify: Styling Toast Messages on Your React App ... So, if you're pumped as I am, let's learn React JS online along...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Resolved in https://github.com/trendmicro-frontend/styled-ui/commit/2a90d3f1959a0c5af297d9220797a53beef068d8
It will be available in v0.8 or a later release.
As an update to the previous comment by @joyfulelement, I further extended the exact import to be used for each component and not just
theme
. For instance, an application using multiple components likeBox
,Menu
,MenuList
etc. needs to do exact import for each component:Although, it makes code bit clumsy but it’s a temporary fix for now to avoid injection of Toast element into the DOM.