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

Streaming renderer #259

Closed
wants to merge 21 commits into from
Closed

Streaming renderer #259

wants to merge 21 commits into from

Conversation

marvinhagemeister
Copy link
Member

This PR that adds a streaming renderer. Main difference to preact-ssr-prepass is that it only awaits suspense boundaries and keeps everything else synchronous. This avoids a flooding the event loop with microtasks.

Tried a custom element approach to attach lazy hydrated subtrees, but the more I think about it the more I'm leaning towards using comments as folks sent me more and more use cases where introducing an arbitrary element breaks CSS styling (even with display: contents) or where the semantic HTML structure falls apart (ul > li).

Marking as draft until it's ready and we might need to make modifications to core too.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2022

⚠️ No Changeset found

Latest commit: 27dbdce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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
src/index.js Outdated
if (renderer !== undefined && error.then) {
/** @type {import('./internal').Component} */
let component;
let susVNode = vnode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Much sus, very amogus 😂

@Lucasvo1
Copy link

Any updates on this?

It's a blocker for using Preact with Nextjs.

@osdiab
Copy link

osdiab commented Jan 18, 2023

Also a blocker for Remix, too.

@graysonhicks
Copy link

👋 This is also a blocker for gatsby-plugin-preact users trying to upgrade to Gatsby v5, which requires React 18.

developit and others added 2 commits February 2, 2023 10:57
… 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>
@developit developit marked this pull request as ready for review February 3, 2023 02:56
@juliannehalversen
Copy link

Any updates here? As stated above this is a big issue for users trying to upgrade to Gatsby v5.

@developit
Copy link
Member

developit commented Feb 3, 2023

Landing this PR doesn't make Preact support React's streaming renderer API, that would need to be plumbed through to preact/compat/server.

The reason we have not yet merged this PR is that it may require changes in Preact to handle client-side hydration for subtrees that are streamed out-of-order. Currently, it's likely that there is a race condition in if any suspense boundaries encountered during hydration manage to resolve and resume hydration prior to their corresponding out-of-order subtrees having been moved into place. This would cause tearing or duplicated DOM.

In order to move forward, we need an end-to-end demo that recreates this scenario so that we can find the best mechanism for deferring hydration that does not rely on streaming knowledge in Preact core.

@seo-burkedecor
Copy link

Hi, thank you so much for this fantastic project!

Do you guys have any update about what @developit explained?

@FleetAdmiralJakob

This comment was marked as off-topic.

1 similar comment
@xand3r40r93

This comment was marked as off-topic.

@AnderUstarroz
Copy link

Almost end of 2023 and there is no updates on this? Latest NextJS and Gatsby apps really depend on this to be able to use Preact instead of React 18.2.0. 😭 😭

@JoviDeCroock
Copy link
Member

@AnderUstarroz you could help us test it #296 is the updated Pr and there's a linked Preact PR

@AnderUstarroz
Copy link

@AnderUstarroz you could help us test it #296 is the updated Pr and there's a linked Preact PR

No problem @JoviDeCroock , just tell me which versions of preact and preact-render-to-string should I use to replace my current package.json dependencies:

  "dependencies": {
      "gatsby": "^5.12.4",
       "react": "^18.2.0",
       "react-dom": "^18.2.0",

      ...

@rschristian
Copy link
Member

@AnderUstarroz you could help us test it #296 is the updated Pr and there's a linked Preact PR

No problem @JoviDeCroock , just tell me which versions of preact and preact-render-to-string should I use to replace my current package.json dependencies:

As Jovi mentioned, there's two open PRs. You'd have to build preact & rts from source.

@PavelAstapov
Copy link

Any updates? It is still a problem for Gatsby 5+ users

@Inviz
Copy link

Inviz commented Apr 16, 2024

Bummer that this isn't generally available yet. Looking forward

@JoviDeCroock
Copy link
Member

Superseded by #296 and released in 6.5.0

@JoviDeCroock JoviDeCroock deleted the streaming-render branch May 22, 2024 06:53
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.

None yet