React 18 StrictMode causes "AuthUI instance is deleted" error
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- firebase, javascript, react
- Domain
- authentication, frontend
Research direction
Start by locating the wrapper component's componentDidMount and componentWillUnmount implementations, then compare their cleanup behavior with the React 18 StrictMode lifecycle described here. Reproduce the issue in a local React 18 StrictMode app and verify that cleanup leaves the AuthUI instance usable and the UI renders without the deletion error.
Written by the indexing model from the issue text.
Description
When using react-firebaseui in React 18 with Strict Mode enabled and running a local dev server, the UI doesn’t render at all and produces this error in the console:
This is because of a change in behavior in Strict Mode to support concurrent features in React 18. Now components are mounted twice. See:
- https://github.com/reactwg/react-18/discussions/19
- https://github.com/reactwg/react-18/discussions/18
It seems the culprit is the deletion of the AuthUI instance when the component is unmounted. Reading the firebaseui documentation, it seems that this isn’t necessary to do, since the firebaseUiWidget property will either get the existing instance or create a new one.
I’ve ported the existing componentDidMount and componentWillUnmount code to a useEffect and removed the instance deletion, and used the modular v9 version of onAuthStateChanged. This seems to work for me:
useEffect(() => {
let firebaseUiWidget: firebaseui.auth.AuthUI;
let userSignedIn = false;
let unregisterAuthObserver: ReturnType<typeof onAuthStateChanged>;
// Get or Create a firebaseUI instance.
firebaseUiWidget =
firebaseui.auth.AuthUI.getInstance() ||
new firebaseui.auth.AuthUI(firebaseAuth);
if (uiConfig.signInFlow === "popup") firebaseUiWidget.reset();
// We track the auth state to reset firebaseUi if the user signs out.
unregisterAuthObserver = onAuthStateChanged(firebaseAuth, (user) => {
if (!user && userSignedIn) firebaseUiWidget.reset();
userSignedIn = !!user;
});
// Render the firebaseUi Widget.
firebaseUiWidget.start("#" + ELEMENT_ID, uiConfig);
return () => {
unregisterAuthObserver();
firebaseUiWidget.reset();
};
}, [uiConfig]);
Is there something that I’m missing that would require the instance to be deleted entirely?
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 246
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebaseui-web-react
-
This Project Is Dead Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
firebase/firebaseui-web-react#292 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 1/100
firebase/firebaseui-web-react#280 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
firebase/firebaseui-web-react#220 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
firebase/firebaseui-web-react#210 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
firebase/firebaseui-web-react#201 · 1 comment · 1 reaction ·
All issues in firebase/firebaseui-web-react
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
neondatabase/website#5944 ·
-
module: core
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
bigbluebutton/bigbluebutton#25849 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jaegertracing/jaeger-ui#4506 ·