Skip to content

Flush a piped destination that buffers - #499

Merged
JoviDeCroock merged 1 commit into
mainfrom
fix/stream-node-flush
Nov 19, 2026
Merged

JoviDeCroock merged 1 commit into
mainfrom
fix/stream-node-flush

Conversation

@JoviDeCroock

Copy link
Copy Markdown
Member

Behind Express's compression() middleware, renderToPipeableStream doesn't stream: compression buffers until it's told to flush, and nothing tells it, so the shell and every boundary arrive together when the render ends. React calls flush() on the destination when it has one.

pipe() now does the same, once per tick of writes and after they reached the destination, and stops once the destination ended or was destroyed. With compression() the shell now arrives right away and each boundary when it resolves.

Two smaller fixes in pipe():

  • It returns the destination, as React's does.
  • When the shell fails and onShellError answers with its own response, the destination is no longer destroyed after the fact. That reset the connection for the next keep-alive request.

This PR was authored by Opus 5.5.

Compression middleware holds everything back until it is told to flush,
so behind Express's compression() the whole document arrived at the end.
pipe() now calls the destination's flush() once per tick of writes, like
React does, and returns the destination.

A response that onShellError already ended is no longer destroyed when
the render stream closes, which reset keep-alive connections.
@changeset-bot

changeset-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a52f799

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-render-to-string Patch

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

@JoviDeCroock
JoviDeCroock marked this pull request as ready for review November 19, 2026 15:58
@JoviDeCroock
JoviDeCroock merged commit 73f9c5f into main Nov 19, 2026
1 check passed
@JoviDeCroock
JoviDeCroock deleted the fix/stream-node-flush branch November 19, 2026 15:58
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant