unmountComponentAtNode warns about another copy of React
See original GitHub issueHello, I am just giving happy-dom a try as it’s indeed much faster than jsdom for testing.
One thing I am noticing though, is that whenever trying to unmount a React component through react-dom
, I get the warning below, whether jsdom doesn’t show anything in particular? Any ideas why that is?
Thanks in advance
// with hapy-dom
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { Window } from "happy-dom";
const { window, document } = new Window();
global.window = window;
global.document = document;
const Foo = () => <h1>Hello World</h1>;
document.body.innerHTML = "<div></div>";
render(<Foo />, document.body.firstChild);
unmountComponentAtNode(document.body.firstChild);
// emits
// Warning: unmountComponentAtNode(): The node you're attempting to unmount was rendered by another copy of React.
// with-jsdom
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import "global-jsdom/register"; // on a side note, `happy-dom/register` would be awesome :)
const Foo = () => <h1>Hello World</h1>;
document.body.innerHTML = "<div></div>";
render(<Foo />, document.body.firstChild);
unmountComponentAtNode(document.body.firstChild);
// emits: No Warnings
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does unmountComponentAtNode give me "another copy ...
Warning : unmountComponentAtNode(): The node you're attempting to unmount was rendered by another copy of React. Why am I getting this error?
Read more >Unmount Component Error with React and Jest with Testing ...
Warning : unmountComponentAtNode(): The node you're attempting to unmount was rendered by another copy of React.
Read more >ReactDOM – React
These methods will warn that your app will behave as if it's running React ... render() currently returns a reference to the root...
Read more >Managing DOM components with ReactDOM - LogRocket Blog
Learn to expertly manage DOM components in a React app, including a deep dive into each ReactDOM method, with this comprehensive tutorial.
Read more >ReactDOM.render is no longer supported in React 18
If the warning is still shown after making the changes, make sure to update your @testing-library/* versions as well. shell. Copied! npm install...
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 FreeTop 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
Top GitHub Comments
Hi @zanona! 🙂
It seems like I misinterpreted the original issue. I missed the comment about the warning.
The issue should now be fixed.
You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v2.25.2
Thanks for reporting @zanona! 🙂
I was not able to reproduce the problem in my Jest test environment. I believe the problem for you was that it is not enough to only register window and document globally. There are a lot more properties that React is depended on.
I have added a new package called @happy-dom/global-registrator which does the same thing as “global-jsdom/register”. It should solve the problem for you.
You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v2.16.0