[vite-plugin] Surface prerender response-body streaming errors#14326
Open
mikepage wants to merge 2 commits into
Open
[vite-plugin] Surface prerender response-body streaming errors#14326mikepage wants to merge 2 commits into
mikepage wants to merge 2 commits into
Conversation
Add an opt-in `experimental.bufferPreviewResponses` option. When enabled, the preview Worker's entry is wrapped so its response body is fully buffered in-worker. A body stream that errors after headers are committed (e.g. a component throwing mid-render during prerendering) — which workerd otherwise terminates as a silently-truncated 200 — is caught and returned as a 500 carrying an `x-vite-cloudflare-worker-error` marker header. The marker is set on the Worker's own response so it reliably traverses the proxy and preview server back to the caller, and lets consumers (e.g. a framework's prerenderer) distinguish a thrown error from a response the Worker intentionally returned with a non-2xx status. Off by default, since buffering breaks legitimate streaming responses in a normal preview. The wrapper re-exports named exports (Durable Objects, entrypoints, Workflows) and non-fetch handlers, and assumes a plain-object default export. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 280b5ac The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
… Workers Scope `bufferPreviewResponses` to the request dispatch target (the first Worker) so auxiliary/service-bound Workers keep their normal streaming behaviour, rather than wrapping every Worker in the preview. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Adds an opt-in
experimental.bufferPreviewResponsesoption to the Cloudflare Vite plugin that surfaces response-body streaming errors duringvite preview.Problem
When a Worker returns a streaming
Responseand the body stream errors after the200status and headers have been committed (for example a component that throws mid-render during framework prerendering), workerd terminates the chunked response cleanly. The HTTP consumer sees a successful but silently-truncated 200 with no error — soastro build–style prerendering writes truncated HTML and exits0. The underlying runtime behaviour is tracked upstream in cloudflare/workerd#6818; downstream report: withastro/astro#17047.Change
When
experimental.bufferPreviewResponsesis enabled, the preview Worker's entry is wrapped so its response body is fully buffered in-worker (the only place the stream error is catchable). A buffered body error — or any thrown handler error — is returned as a500carrying anx-vite-cloudflare-worker-errormarker header.dispatchFetchwould otherwise be swallowed/reshaped by the proxy and lose custom headers).fetchhandlers; it assumes a plain-object default export.The companion
@astrojs/cloudflarechange (separate repo) enables this option and consumes the marker header.@astrojs/cloudflare) rather than used directly; it can be documented when/if stabilised.