-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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(ssr): Render to stream #1197
Conversation
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.
Great work! I think the implementation looks good.
Obviously we should try to reduce the redundancy by reusing some of the duplicated logic - I can do that but it will have to wait until I finish other priorities. Would you be interested in working on that in the meanwhile?
stream: Readable | ||
): Promise<void> { | ||
try { | ||
for await (const item of buffer) { |
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.
I think it's better to only await
when the item is a Promise - this would save a microtask tick on sync buffer entries.
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.
Should be fine now I think
Sure, I'll mention you when it's ready. |
@yyx990803 there's one problem remaining still that I'm not sure which way is exactly the best to tackle it. SSR compiler would produce optimized code only for |
@CyberAP I'm not quite sure what you mean by
Do you have an example? |
@yyx990803 there are two kinds of buffer right now: one for Another solution I can think of is to always use a buffer that returns an array and await on deep promises at unroll stage, the same way it's done in |
I think that is better - if both use the same buffer implementation then there's also no need to create bound versions of the render methods. |
Great, I'll be able to refactor that on Monday then. |
…ers at unroll stage
33e79d3
to
c5c4046
Compare
Great job! |
Provide a
renderToStream
API for a quicker SSR rendering. It would allow to start streaming as soon as the first synchronous render happens, awaiting on all the next async renders upon encounter. All async operations still execute in parallel, so it works exactly likerenderToString
but streams as soon as possible, whilerenderToString
always awaits for all the promises to return a result.Right now it doesn't resolve teleports and I don't know if it even should.
All the tests are a direct copy of those of
renderToString
withrenderToStream
converted into Promise for simplicity.You could notice there's a code duplication for helper functions, I thought I should leave it up to maintainers for restructuring.