Skip to content

fix: honor node streaming backpressure#8557

Merged
wmertens merged 2 commits intobuild/v2from
v2-fix-node-streaming
Apr 22, 2026
Merged

fix: honor node streaming backpressure#8557
wmertens merged 2 commits intobuild/v2from
v2-fix-node-streaming

Conversation

@Varixo
Copy link
Copy Markdown
Member

@Varixo Varixo commented Apr 14, 2026

This PR makes Qwik SSR honor downstream backpressure during Node streaming. The core renderer now waits for pending async flushes before emitting the next chunk, and the Node middleware translates ServerResponse.write() / drain semantics into an awaitable stream signal instead of fire-and-forget writes.

It also adds a regression test in render-api.spec.tsx to ensure a second chunk is not emitted while the first async write is still pending, plus Node middleware regression coverage so handled errors are not rethrown after headers were already sent.

Performance testing shows time drops from ~250ms to ~40ms for response

@Varixo Varixo self-assigned this Apr 14, 2026
@Varixo Varixo added the V2 label Apr 14, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: 8732ef8

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

@maiieul maiieul moved this from Backlog to In progress in Qwik Development Apr 14, 2026
@Varixo Varixo force-pushed the v2-fix-node-streaming branch from e868a54 to 7b2f0b4 Compare April 14, 2026 19:41
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 14, 2026

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8557

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8557

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8557

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8557

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8557

commit: 8732ef8

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 8732ef8

@Varixo Varixo force-pushed the v2-fix-node-streaming branch from 7b2f0b4 to bc527bb Compare April 15, 2026 16:20
@Varixo Varixo marked this pull request as ready for review April 15, 2026 16:55
@Varixo Varixo requested a review from a team as a code owner April 15, 2026 16:55
@maiieul maiieul moved this from In progress to Waiting For Review in Qwik Development Apr 15, 2026
@Varixo Varixo marked this pull request as draft April 15, 2026 16:56
@maiieul maiieul moved this from Waiting For Review to In progress in Qwik Development Apr 15, 2026
@Varixo Varixo force-pushed the v2-fix-node-streaming branch from bc527bb to 3755593 Compare April 15, 2026 20:11
@Varixo Varixo marked this pull request as ready for review April 16, 2026 17:19
@maiieul maiieul moved this from In progress to Waiting For Review in Qwik Development Apr 16, 2026
@Varixo Varixo requested a review from wmertens April 18, 2026 06:47
Comment thread packages/qwik/src/core/shared/serdes/serialization-context.ts
Copy link
Copy Markdown
Member

@wmertens wmertens left a comment

Choose a reason for hiding this comment

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

LGTM! But I'd like to see the comment?


const writePromise = writer.write(new Uint8Array([1, 2, 3]));
await Promise.resolve();
expect(res.listenerCount('drain')).toBe(0);
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.

could you add a comment explaining when the drain listeners are attached?

@wmertens wmertens merged commit cd881bb into build/v2 Apr 22, 2026
28 checks passed
@wmertens wmertens deleted the v2-fix-node-streaming branch April 22, 2026 19:47
@github-project-automation github-project-automation Bot moved this from Waiting For Review to Done in Qwik Development Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants