forked from vitejs/vite
-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: HEAD request Content-Type for JS files in transform middleware #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
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
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 finished work on behalf of
sapphi-red
July 18, 2025 03:47
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>
Copilot finished work on behalf of
sapphi-red
July 18, 2025 03:55
sapphi-red
requested changes
Jul 18, 2025
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot finished work on behalf of
sapphi-red
July 18, 2025 04:17
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>
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:
|
Copilot finished work on behalf of
sapphi-red
July 18, 2025 04:30
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
=> vitejs#20421 |
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/html
instead 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/html
content 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
send
function 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.