-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: add preact-ssr-prepass #9524
Conversation
🦋 Changeset detectedLatest commit: 87c265a The changes in this PR will be included in the next version bump. 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 |
.changeset/cold-llamas-laugh.md
Outdated
"@astrojs/preact": patch | ||
--- | ||
|
||
Added preact-ssr-prepass library to the server code for rendering lazy components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added preact-ssr-prepass library to the server code for rendering lazy components | |
Allows rendering lazy components |
1047e81
to
cc6a41c
Compare
Can you update to fix the build? Also, instead of adding a new example can you just update the current Preact example to use a lazy component? |
a84842c
to
ed89a22
Compare
I fixed build and now it pass this stage and tests, but |
@aleksandrjet please update your branch with the latest main, it will fix the erroring check |
2c6b96e
to
c48073f
Compare
thanks! all checks have now passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tiny nits, but the code changes lgtm! There's a merge conflict, but should be resolve-able by running pnpm i
while resolving the conflicts. pnpm
is able to resolve the conflicts automatically.
c48073f
to
3e200db
Compare
I got current changes and run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks great
@florian-lefebvre @bluwy could I do anything else with this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarah11918 I'd like your advice on the changeset. Also, do you think it's worth making a PR to the docs?
I found last Sarah's comment in previous MR - #7569 (review). It said that we don't need to update preact docs |
Changes
It is the double of MR#7569
I Added
preact-ssr-prepass
library topreact
integraion. This library allow to use lazy components in preact code. Without this i get unknown error in SSR.While execute SSR
preact-ssr-prepass
will wait to load all dynamic imports so that preact-render-to-string can use they. More details about preact-ssr-prepassTesting
Added
examples/framework-preact-lazy
andpreact-lazy-component.test
with lazy loading of component.Docs
I don't think that it needs documentation, because i expected that Suspense and lazy functions will work.
It does not affect the current api, but it can slow build execution of preact components, because preact-ssr-prepass will add extra pass of tree. This pass will wait for all dynamic imports to be loaded, even if they don't exist in the code.
Reasons for the second attempt
I sent earlier MR#7569 with this fix. But this was declined by next reasons:
Marvin from Preact team said, that this functional will be included in the current library
preact-render-to-string
for server rendering by default. But a lot of time has passed since that answer. A few new versions (and major ones) ofpreact-render-to-string
were realized, but they did not include work with lazy components. Using ofpreact-ssr-prepass
is still recommended in official documentationAlso one of reasons was incorrect work with empty lazy components - Side effect of third argument of preact render #7868. While this was so, adding of
preact-ssr-prepass
would lead to some undocumented problems. But this problem was solved in astro@3. Empty lazy components now work correctly.So, I think this MR has the right to a second try. It's been 6 months since the last discussion and lazy components still can't be rendered on the server.