Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/flush-before-component-promise.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make this a lot less verbose, just fix: .... This is for the changelog, people don't want to read the fine technical details of a bug here.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@qwik.dev/core': patch
---

Fix SSR in-order streaming not flushing before awaiting a component-body promise.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { component$ } from '@qwik.dev/core';

export function delay(time: number) {
return new Promise<void>((resolve) => {
setTimeout(() => resolve(), time);
});
}

export const AsyncCmp = component$(async () => {
await delay(5000);
return <span id="async-result">Async done</span>;
});

export const StreamingFlush = component$(() => {
return (
<div>
<h1 id="prefix">Prefix content</h1>
<AsyncCmp />
</div>
);
});
2 changes: 2 additions & 0 deletions e2e/qwik-e2e/apps/e2e/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import NakedObjectStoreReactivityIssue5001 from './components/signals/NakedObjec
import { Signals } from './components/signals/signals';
import { SlotParent } from './components/slot/slot';
import { StreamingRoot } from './components/streaming/streaming';
import { StreamingFlush } from './components/streaming/streaming-flush';
import { Styles } from './components/styles/styles';
import { SyncQRL } from './components/sync-qrl/sync-qrl';
import { Toggle } from './components/toggle/toggle';
Expand Down Expand Up @@ -66,6 +67,7 @@ const tests: Record<string, FunctionComponent> = {
'/e2e/resource-fn': () => <ResourceFn />,
'/e2e/treeshaking': () => <TreeshakingApp />,
'/e2e/streaming': () => <StreamingRoot />,
'/e2e/streaming-flush': () => <StreamingFlush />,
'/e2e/mount': () => <MountRoot />,
'/e2e/ref': () => <RefRoot />,
'/e2e/signals': () => <Signals />,
Expand Down
22 changes: 22 additions & 0 deletions e2e/qwik-e2e/tests/streaming.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ test.describe('streaming', () => {
await expect(count).toHaveText('Rerender: 2');
});
});

test.describe('streaming flush', () => {
test('should flush prefix before awaiting slow async component', async ({ page }) => {
await page.goto('/e2e/streaming-flush', {
waitUntil: 'commit',
});

// Prefix content must be visible quickly — the flush sends it
// before blocking on the 5s async component.
await expect(page.locator('#prefix')).toHaveText('Prefix content', {
timeout: 3000,
});

// Async content must NOT exist yet (still blocked on the delay).
await expect(page.locator('#async-result')).toHaveCount(0);

// After the async component resolves, the content appears.
await expect(page.locator('#async-result')).toHaveText('Async done', {
timeout: 8000,
});
});
});
Comment thread
wmertens marked this conversation as resolved.
1 change: 1 addition & 0 deletions packages/qwik/src/core/ssr/ssr-render-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ function processJSXNode(
if (isPromise(jsxOutput)) {
// Defer reading QScopedStyle until after the promise resolves
enqueue(async () => {
await ssr.streamHandler.flush();
const resolvedOutput = await jsxOutput;
const compStyleComponentId = addComponentStylePrefix(host.getProp(QScopedStyle));

Expand Down
Loading