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

feat: streaming rendering with Suspense boundaries as flush trigger #296

Merged
merged 38 commits into from
May 6, 2024

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Mar 30, 2023

Changes

  • Updates against current master
  • Polyfills mask as we stopped setting that explicitly without useId invocations

Preact

I use a build of Preact with comments enabled for the demo preactjs/preact#4128

Notes

While creating this demo I noticed a bug where when we suspend twice from a streaming boundary we end up in an infinite loop, also we can't unset _parent while streaming this would need to happen after everything 😩

Solved it by using _vnodeId to have consistent ids for Suspense boundaries, keep checking for additions to the boundaries with forkSuspended and more fixes.

Demo

The demo basically forces a less than ideal scenario:

  • The first boundary gets flushed which gives us the title and the loading placeholder - hydration pauses
  • On the server we are resolving the data for the second boundary (10 pokemons)
  • The second boundary gets flushed which gives us the list of 10 pokemons - hydration resumes
  • On the client we now hit useQuery which is suspense enabled and throws as it doesn't have the pokemons - hydration pauses
  • On the client the 10 pokemons get fetched - hydration finishes

Normally front-end data-fetching libraries will include the data in a <script> tag that gets flushed to the client so the data-restoration is synchronous. This demo however is meant to show off the resumed hydration.

marvinhagemeister and others added 22 commits October 15, 2022 21:45
feat: use custom element for hydration
feat: add onError to renderToChunks
feat: add renderToPipeableStream
This reduces code and *should* also be more performant than recursive JS iteration.

See: https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator
feat: use comments instead of element as marker
… on #241 (#267)

* use index.module.js when benchmarking, since its the output of `npm run transpile`

* fix bench:v8 output path

* update microbundle and turn off function inlining

* fix JSX entrypoint and tests

* fix type defintion to reflect removed exports and options

* fix root copy of jsx types

* optimize renderToString performance using switch and short-circuiting

* Create bright-ligers-jam.md

* Update bright-ligers-jam.md

* Update bright-ligers-jam.md

* Backport changes from #237 (child/parent properties, simplified Fragment handling)

* ci: update github actions (#266)

* ci: update actions/checkout to v3

* ci: update actions/cache to v3

* merge master

* lockfile version

* update benchmarking reference implmementation to 5.2.6 (6a0bec2)

* fix tests

* fix before diff hook being called on invalid vnodes

* move non-exported files into a lib directory

* update pretty implementation and move typedefs into a d.ts

* Move chunked implementation out of the default entrypoint

* update tests to reflect chunking being moved out of default entrypoint

* fix d8 bench script

---------

Co-authored-by: Abdul Rauf <abdulraufmujahid@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 30, 2023

🦋 Changeset detected

Latest commit: cb505ac

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 Minor

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

src/lib/chunked.js Outdated Show resolved Hide resolved
@JoviDeCroock JoviDeCroock force-pushed the streaming-render-update branch from 8c01d08 to e006bb7 Compare March 30, 2023 06:47
@JoviDeCroock JoviDeCroock force-pushed the streaming-render-update branch from 9af40f9 to 1579648 Compare March 30, 2023 13:14
@JoviDeCroock JoviDeCroock force-pushed the streaming-render-update branch from 2bb7ca2 to cbabc9e Compare March 30, 2023 14:18
@JoviDeCroock JoviDeCroock deleted the streaming-render-update branch June 22, 2023 12:00
@JoviDeCroock JoviDeCroock restored the streaming-render-update branch June 22, 2023 12:00
@JoviDeCroock JoviDeCroock reopened this Jul 19, 2023
@JoviDeCroock JoviDeCroock changed the base branch from streaming-render to main July 19, 2023 08:56
@JoviDeCroock JoviDeCroock force-pushed the streaming-render-update branch from 10f293e to 1f06bbf Compare July 19, 2023 09:03
@JoviDeCroock JoviDeCroock changed the title Streaming render update feat: streaming rendering with Suspense boundaries as flush trigger Jul 19, 2023
@JoviDeCroock JoviDeCroock mentioned this pull request Dec 1, 2023
Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

This is great! Left some minor comments, but I'm good with landing this as early as possible and iterating on it in main 👍

src/stream.js Outdated Show resolved Hide resolved
jsx.d.ts Outdated Show resolved Hide resolved
src/internal.d.ts Outdated Show resolved Hide resolved
src/pretty.js Outdated Show resolved Hide resolved
Comment on lines +44 to +46
Promise.resolve().then(() => {
options.onShellReady && options.onShellReady();
});
Copy link
Member

Choose a reason for hiding this comment

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

Would this fire when the rendering of the shell already errors? Not sure if the expected behavior is to call onShellReady regardless or only in the error case.

Copy link
Member Author

Choose a reason for hiding this comment

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

The render runs synchronously, so after a micro-tick this just tells us that the synchronous shell render is done

@JoviDeCroock JoviDeCroock merged commit 0faec39 into main May 6, 2024
1 check passed
@JoviDeCroock JoviDeCroock deleted the streaming-render-update branch May 6, 2024 16:21
@github-actions github-actions bot mentioned this pull request May 6, 2024
@JoviDeCroock JoviDeCroock mentioned this pull request May 22, 2024
4 tasks
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.

4 participants