Skip to content

Commit

Permalink
fix: backport #17997, ensure req.url matches moduleByEtag URL to avoi…
Browse files Browse the repository at this point in the history
…d incorrect 304 (#18078)

Co-authored-by: coderwei <[email protected]>
  • Loading branch information
patak-dev and coderwei99 committed Sep 11, 2024
1 parent d90ba40 commit 74a79c5
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 74a79c5

Please sign in to comment.