feat: out of order streaming for Suspense#8611
Conversation
🦋 Changeset detectedLatest commit: 91119b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
@qwik.dev/core
@qwik.dev/router
eslint-plugin-qwik
create-qwik
@qwik.dev/optimizer
commit: |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
e63fe47 to
915e9ba
Compare
915e9ba to
303b6d1
Compare
a9b29e0 to
d72b9f7
Compare
ac0875f to
91119b6
Compare
|
|
||
| ## Out-of-order Streaming | ||
|
|
||
| Out-of-order streaming is an optional server rendering mode for `<Suspense>`. |
There was a problem hiding this comment.
I think it should be the default when the experimental is enabled.
| Out-of-order streaming is an optional server rendering mode for `<Suspense>`. | ||
|
|
||
| Server rendering means Qwik creates HTML on the server and sends it to the browser. Streaming means | ||
| the browser can receive that HTML in chunks instead of waiting for one complete HTML string. |
There was a problem hiding this comment.
...HTML string (but still within the same HTTP connection).
| ...opts, | ||
| streaming: { | ||
| ...opts.streaming, | ||
| outOfOrder: { strategy: 'suspense' }, |
There was a problem hiding this comment.
do we plan other strategies? Why not a simple boolean and if we want to tweak things later we can optionally accept an object?
|
|
||
| ### Fallbacks | ||
|
|
||
| The fallback is real UI. Choose markup that is useful while the user waits: |
There was a problem hiding this comment.
Is the fallback always added to the stream? Worth explaining either way.
| waiting. If your fallback has buttons or other event handlers, they can also resume while the | ||
| fallback is visible, after the root page state has loaded in the browser. | ||
|
|
||
| When the real content arrives, Qwik removes the fallback and inserts the resolved content. The |
There was a problem hiding this comment.
Qwik hides the fallback, right? Not removes?
| while the server is still rendering. | ||
|
|
||
| For static site generation, the HTML file is created ahead of time. The user receives the finished | ||
| file later, so there is no live server stream to reveal a fallback first. |
There was a problem hiding this comment.
Ah and during SSG, OoOS should be disabled of course.
| let lastIdx = this.$forwardRefs$.length - 1; | ||
| while (lastIdx >= 0 && this.$forwardRefs$[lastIdx] === -1) { | ||
| lastIdx--; | ||
| private getForwardRefsPayload(): Array<number | string | number[]> | null { |
There was a problem hiding this comment.
If I'm reading this right, if there is a slow promise first and a faster one later, ooos could send only the faster one and the slow will never be sent?
wmertens
left a comment
There was a problem hiding this comment.
I'm worried about forwardRefs, can you write a test with Suspense and a Promise that only resolves after the first chunk, followed by a Promise that resolves before the first chunk?
| export const getSegmentVNodeId = (segmentId: string, localIndex: number): number => { | ||
| const segmentIndex = parseInt(segmentId, 10) - 1; | ||
| const diagonal = segmentIndex + localIndex; | ||
| return -((diagonal * (diagonal + 1)) / 2 + localIndex + 1); |
There was a problem hiding this comment.
I don't understand how this works, can you add a comment?
97ec911 to
91119b6
Compare
8e52f54 to
91119b6
Compare
No description provided.