Skip to content

Commit

Permalink
fix: ensure req.url matches moduleByEtag URL to avoid incorrect 304 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderwei99 authored Sep 10, 2024
1 parent 6f60adc commit abf04c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export function cachedTransformMiddleware(
const ifNoneMatch = req.headers['if-none-match']
if (ifNoneMatch) {
const moduleByEtag = environment.moduleGraph.getModuleByEtag(ifNoneMatch)
if (moduleByEtag?.transformResult?.etag === ifNoneMatch) {
if (
moduleByEtag?.transformResult?.etag === ifNoneMatch &&
moduleByEtag?.url === req.url
) {
// For CSS requests, if the same CSS file is imported in a module,
// the browser sends the request for the direct CSS request with the etag
// from the imported CSS module. We ignore the etag in this case.
Expand Down

0 comments on commit abf04c3

Please sign in to comment.