close
Skip to content

Buffer streamed HTML responses in the service worker#3385

Draft
adamziel wants to merge 4 commits intotrunkfrom
adamziel/buffer-html-responses
Draft

Buffer streamed HTML responses in the service worker#3385
adamziel wants to merge 4 commits intotrunkfrom
adamziel/buffer-html-responses

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Mar 13, 2026

What it does

Buffers text/html response bodies in the service worker before returning them to the browser. Non-HTML responses (JSON, images, file downloads) continue streaming normally.

Rationale

When streaming HTML, Chrome view transitions are animating to the partially streamed state. This makes the UI elements appear one by one in a fast progression and feels weird. Most servers buffer the HTML responses, let's just do the same in Playground. Perhaps, in a follow-up, we could figure how to buffer every PHP response by defaul unless flush() is called.

Before merging, let's confirm this solves the problem.

PR #3361 added streaming response support to the service worker to avoid
postMessage timeouts. However, streaming partially-rendered HTML to the
browser can cause broken markup flashes while PHP is still producing
output. This buffers the full response body when the content-type is
text/html, while leaving all other responses (JSON, images, downloads)
streaming as before.
Reconstruct the body ReadableStream from the MessagePort instead of streaming HTML pages directly.
Removed the streamToUint8Array function from utils.ts.
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