-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
- 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:
- Go to https://stackblitz.com/edit/create-preact-starter-wih6a1?file=src%2Findex.jsx
- Wait until the component renders. You should see "Hello World" on the right side.
- Open the browser console. You'll see an error like this:

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.