Buffer streamed HTML responses in the service worker#3385
Draft
Buffer streamed HTML responses in the service worker#3385
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Buffers
text/htmlresponse 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.