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

Use suspense boundary vnode as parent for subtree re-render #408

Merged
merged 6 commits into from
Jan 12, 2025

Conversation

f0x52
Copy link
Contributor

@f0x52 f0x52 commented Jan 8, 2025

Fixes #406

Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: 2022f10

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-render-to-string Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does look good, we'll need a changeset and a few tests to prevent regressions. You might need to update the types of the renderer as well

@f0x52
Copy link
Contributor Author

f0x52 commented Jan 10, 2025

Would this be a patch changeset?

@f0x52 f0x52 force-pushed the non-async-render-parent branch from c4f90dc to 28d27a5 Compare January 10, 2025 20:48
@f0x52
Copy link
Contributor Author

f0x52 commented Jan 10, 2025

Added changeset, updated types, and added a single test that traverses VNode parents inside the suspense boundary and checks if there is a circular reference.
I couldn't find a good way to add a test that actually tries to use the useId hook, because in case of a regression this will cause the tests to run forever; since the Node.js event loop is continually busy inside the while loop, Mocha's timeout functionality can't stop the test either (mochajs/mocha#1609)

@f0x52 f0x52 marked this pull request as ready for review January 10, 2025 20:58
@JoviDeCroock
Copy link
Member

You should do the useId test and leverage the abortController to abort after i.e 1 second and fail

@f0x52
Copy link
Contributor Author

f0x52 commented Jan 10, 2025

I don't think that's possible either? The synchronous while loop inside the useId hook completely blocks the Node.js event loop, so as far as I know there is no way to abort the abortController while it's in the loop; timeouts/intervals won't even be called. Tripwire as mentioned in the mocha issue uses a native extension to be able to interrupt unbreakable loops, but including a native extension + build step doesn't seem ideal either.

Perhaps it would be good to add a check in while loops that could otherwise run forever on erroneous node trees; so far I found this in useId, and the _catchError handler, though that's probably a performance tradeoff

@JoviDeCroock
Copy link
Member

I mean, it works now so we should not care about a test loop.... we should write a test, i can write it if you prefer.

@f0x52
Copy link
Contributor Author

f0x52 commented Jan 10, 2025

This test also expects the current behavior where useId's are scoped to the rendering root/boundary, resulting in id P0-0 for the first element outside the suspense boundary, and P0-0 for the first element inside as well.

@JoviDeCroock JoviDeCroock merged commit 8e8e8ac into preactjs:main Jan 12, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useId stuck in infinite loop with streaming render
2 participants