Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] Error: Cannot read properties of null (reading 'subtree') #1217

Closed
rothsandro opened this issue Jan 16, 2024 · 3 comments · Fixed by #1236
Closed

[v13] Error: Cannot read properties of null (reading 'subtree') #1217

rothsandro opened this issue Jan 16, 2024 · 3 comments · Fixed by #1236
Labels
bug Something isn't working

Comments

@rothsandro
Copy link

Describe the bug

We use React and DevExtreme components. After updating to happy-dom 13, some of our tests are failing with the following message:

TypeError: Cannot read properties of null (reading 'subtree')
❯ Function.removeChild node_modules/happy-dom/src/nodes/node/NodeUtility.ts:127:26
❯ Function.removeChild node_modules/happy-dom/src/nodes/element/ElementUtility.ts:122:15
❯ HTMLElement.removeChild node_modules/happy-dom/src/nodes/element/Element.ts:507:25
❯ node_modules/devextreme-react/cjs/core/component-base.js:150:183
❯ Popover.ComponentBase.componentWillUnmount node_modules/devextreme-react/cjs/core/component-base.js:150:77
❯ Popover.Component.componentWillUnmount node_modules/devextreme-react/cjs/core/component.js:68:47
❯ callComponentWillUnmountWithTimer node_modules/react-dom/cjs/react-dom.development.js:22857:14
❯ safelyCallComponentWillUnmount node_modules/react-dom/cjs/react-dom.development.js:22873:5
❯ commitDeletionEffectsOnFiber node_modules/react-dom/cjs/react-dom.development.js:24129:13

The problem can be reproduced with the following simple test:

import { Popover } from "devextreme-react/popover";
import { render, screen } from "@testing-library/react";
import { test } from "vitest";

test("popover", async () => {
  render(
    <Popover visible>
      <div>Content</div>
    </Popover>
  );

  await screen.findByText("Content");
});

To Reproduce
Steps to reproduce the behavior:

  1. Clone the repro
  2. Install dependencies: npm i
  3. Run the tests via npm run test
  4. See error

Expected behavior
The tests should run successfully.

Device:

  • OS: macOS
  • Browser: Brave 120

Additional context

This only happens with happy-dom v13 and when Vitest globals are enabled (even if we don't rely on globals but import the functions). It works when downgrading to happy-dom v12 or when disabling Vitest globals.

@rothsandro rothsandro added the bug Something isn't working label Jan 16, 2024
@zachlankton
Copy link
Contributor

Having the same problem myself, working on a fix and PR right now

@zachlankton
Copy link
Contributor

I've published a temporary package for myself, you are welcome to use if you'd like, just remember this is temporary until the fix gets released.

Here's how I'm doing my package.json

"devDependencies": {
    "happy-dom": "npm:zachlankton-happy-dom@13.3.2",
  },

capricorn86 added a commit that referenced this issue Feb 25, 2024
@capricorn86
Copy link
Owner

Thank you again for your contribution @zachlankton! 🌟

I believe the issue is related to code being executed after the Window instance has been closed as options for the MutationObserver are mandatory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants