Skip to content

Commit 7f72e81

Browse files
coderwei99patak-dev
authored andcommitted
fix: ensure req.url matches moduleByEtag URL to avoid incorrect 304 (#17997)
1 parent ccbfc1a commit 7f72e81

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/vite/src/node/server/middlewares/transform.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export function cachedTransformMiddleware(
5252
const ifNoneMatch = req.headers['if-none-match']
5353
if (ifNoneMatch) {
5454
const moduleByEtag = server.moduleGraph.getModuleByEtag(ifNoneMatch)
55-
if (moduleByEtag?.transformResult?.etag === ifNoneMatch) {
55+
if (
56+
moduleByEtag?.transformResult?.etag === ifNoneMatch &&
57+
moduleByEtag?.url === req.url
58+
) {
5659
// For CSS requests, if the same CSS file is imported in a module,
5760
// the browser sends the request for the direct CSS request with the etag
5861
// from the imported CSS module. We ignore the etag in this case.

0 commit comments

Comments
 (0)