-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
useId stuck in infinite loop with streaming render #406
Comments
I am going to move this issue to the proper repository (preact-render-to-string) |
With
Interesting difference is that ComponentOne/Two don't get re-rendered at all, which would also circumvent getting stuck in the loop. |
Think I chased it down to the following code: preact-render-to-string/src/index.js Lines 483 to 493 in 2da38a7
The error handler walks up to find the Suspense boundary vnode preact-render-to-string/src/lib/chunked.js Lines 54 to 60 in 2da38a7
And when the promise resolves, renderChild re-renders the Suspense boundary children (vnode.props.children )
Rendering them with the parent set to the vnode that originally threw, which is guaranteed to be one of the children of the vnode.props.children , so this will always cause infinite recursion when the useId hook attempts to walk up the tree.
I think the correct approach would be rendering |
The reason this wasn't an issue for #407 nor the Suspense/lazy example in the docs is because they throw while rendering the direct children of the Suspense element, which means the Suspense component is the |
Describe the bug
I encountered an infinite loop in the
useId
hook, when trying to debug a different issue relating to useId/Suspense.With this component tree, where
ComponentOne
andComponentTwo
both load alazy()
component, as soon as rendering resumes on the first Suspense boundary, theuseId
hook insideComponentOne
loops infinitely.To Reproduce
https://codesandbox.io/p/devbox/preact-useid-infinite-loop-4clmdc?workspaceId=ws_Hyb2mUcrQ6TVf2LBce8QH7
Launching the run/debug configuration 'Run program' will try to do a server-side streaming render with two Suspense boundaries, both of which have a component that logs the output of the
useId
hook, and then loads alazy()
wrapped component.As debug output you will see:
After which the process freezes (and Codesandbox pops up a 'CPU usage 100%' in the top bar). If you pause the debug, you can see it's stuck in an infinite while loop in useHook, because
root._parent
is a circular reference.https://github.com/preactjs/preact/blob/1226aae23826e0d703b520cb764749e04f571043/hooks/src/index.js#L431-L433
Expected behavior
Render finished, expected output
The text was updated successfully, but these errors were encountered: