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

TypeError: Cannot set properties of null (setting '__m') with preact 10.19.4 when destroying a component that calls useId #4277

Closed
1 task
acelaya opened this issue Feb 14, 2024 · 0 comments · Fixed by #4278
Labels

Comments

@acelaya
Copy link

acelaya commented Feb 14, 2024

  • Check if updating to the latest Preact version resolves the issue

Describe the bug

We have a helper which renders components via render(<SomeJSX />, container) (where container is an HTMLElement), and then destroys them via render(null, container) to make sure side effect clean-ups are executed.

This worked fine with preact <=10.19.3, but with 10.19.4 it throws an error when render(null, container) is called, only if the rendered component is internally using useId().

To Reproduce

Create a component that calls useId(), then render it and then destroy it

import { render } from 'preact';
import { useId } from 'preact/hooks';

function App() {
  useId();
  return <div>Hello World</div>;
}

const container = document.getElementById('app');
render(<App />, container);
render(null, container);

You can see the error in action here https://stackblitz.com/edit/create-preact-starter-wih6a1?file=src%2Findex.jsx

Basically, as soon as the component has a call to useId(), it crashes when calling render(null, container).

Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/edit/create-preact-starter-wih6a1?file=src%2Findex.jsx
  2. Wait until the component renders. You should see "Hello World" on the right side.
  3. Open the browser console. You'll see an error like this:
    image

If you remove the call to useId() or downgrade to preact 10.19.3, the error will not be reproducible.

Expected behavior

No error is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants