Repository navigation
[vite-plugin] Preserve Worker response statusText in dev and preview - #16453
james-elicx wants to merge 1 commit into
Conversation
sendResponse from @remix-run/node-fetch-server calls res.writeHead(status, headers) without a reason phrase, so Node replaced the Worker's statusText with its default (or "unknown" for non-standard codes). Set res.statusMessage before writing the response on HTTP/1.x.
🦋 Changeset detectedLatest commit: b7382af 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 |
|
LGTM! |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| response = new MiniflareResponse(response.body, response); | ||
| // HTTP/2 disallows use of the `transfer-encoding` header | ||
| response.headers.delete("transfer-encoding"); | ||
| } else if (response.statusText) { |
|
✅ Approved — A small, well-scoped fix: The decision is advisory: this comment never approves, blocks or requests changes on the pull request. ✅ All checks passed📋 Code Quality: ✅ LGTMI found no problems in this change.
📝 Documentation: ✅ LGTMThe changeset describes the bug fix clearly, and the code comment explains why Reviewed commit: |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
A Worker response such as
new Response(body, { status: 231, statusText: "global-before" })reached the browser through the Vite plugin as231 unknown.The plugin writes Worker responses to Node with
sendResponsefrom@remix-run/node-fetch-server. That callsres.writeHead(response.status, headers)without a reason phrase, so Node uses its default text for the status code, orunknownfor non-standard codes. Miniflare itself keeps the status text (dispatchFetchreturns231 "global-before"), so the text is lost only at this step.createRequestHandlernow setsres.statusMessage = response.statusTextbefore callingsendResponsewhen the response has a status text. HTTP/2 is skipped because it has no reason phrase, and settingstatusMessageon anHttp2ServerResponseonly produces a warning. All the plugin's dev, preview and trigger-handler middleware go throughcreateRequestHandler, so they all get the fix.This could also be fixed upstream in
@remix-run/node-fetch-serverby passingresponse.statusTexttowriteHead. The fix here doesn't depend on that, and still works if upstream changes.