-
-
Notifications
You must be signed in to change notification settings - Fork 47
Re-rendering on HMR fails if the initial rendering of a component in a portal fails #568
Description
I'm getting this error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
if I modify a file that has a component rendered inside a portal and that threw an exception on initial render. The property in question is _children on VNode.
It looks like vnodesForComponent isn't cleared in catchError, and it seems _children isn't initialized if initial rendering fails. Not sure if this is a Preact or Prefresh issue, but since the component is unmounted on error, Prefresh shouldn't try to re-render it.
I can only seem to trigger this when the component in question is in a portal, though I haven't been able to figure out why that's special.
When I first tried to make a StackBlitz repro, this didn't trigger. After upgrading to the latest versions of Vite, Preact and preact-vite, the issue started showing.
Repro
https://stackblitz.com/edit/create-preact-starter-ttn2e8qn?file=src%2Fresource.jsx
- Load the StackBlitz.
- The "Error: Intended" will show in the console.
- Make a change in resoure.jsx and wait a bit for HMR.
- The "TypeError: Cannot read properties of undefined (reading 'length')" will show in the console.