fix: HEAD request Content-Type for JS files in transform middleware#11
Closed
fix: HEAD request Content-Type for JS files in transform middleware#11
Conversation
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] @vitejs/vite/issues/20415 Fix this issue. Make sure to write a test for it. The related line should be @vitejs/vite/files/packages/vite/src/node/server/middlewares/transform.ts
fix: HEAD request Content-Type for JS files in transform middleware
Jul 18, 2025
sapphi-red
reviewed
Jul 18, 2025
packages/vite/src/node/server/middlewares/__tests__/transform-integration.spec.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
sapphi-red
requested changes
Jul 18, 2025
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
sapphi-red
requested changes
Jul 18, 2025
packages/vite/src/node/server/middlewares/__tests__/transform.spec.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
sapphi-red
reviewed
Jul 18, 2025
Copilot stopped work on behalf of
sapphi-red due to an error
July 18, 2025 05:00
This was referenced Jul 18, 2025
Owner
|
=> vitejs#20421 |
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.
Problem
HEAD requests to JavaScript files in the Vite dev server were returning incorrect
Content-Type: text/htmlinstead oftext/javascript. This caused issues in environments where JavaScript file presence is checked via HEAD requests before loading, such as Module Federation setups.Root Cause
The transform middleware only processed GET requests and immediately called
next()for HEAD requests:This meant HEAD requests bypassed the transform middleware entirely and fell back to other middlewares that returned the default
text/htmlcontent type.Solution
1. Allow HEAD requests in transform middleware
Modified the HTTP method check to allow both GET and HEAD requests:
2. Handle HEAD requests properly in send function
Updated the
sendfunction to handle HEAD requests by only sending headers without body content:Verification
Content-Type: text/javascript✅Testing
Added comprehensive tests to verify:
Closes vitejs#20415
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.