question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unmountComponentAtNode warns about another copy of React

See original GitHub issue

Hello, 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
capricorn86commented, Jan 12, 2022

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

1reaction
capricorn86commented, Apr 28, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found