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 and patak-dev committed Sep 11, 2024
1 parent ccbfc1a commit 7f72e81
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 @@ -52,7 +52,10 @@ export function cachedTransformMiddleware(
const ifNoneMatch = req.headers['if-none-match']
if (ifNoneMatch) {
const moduleByEtag = server.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 7f72e81

Please sign in to comment.