From 74a79c53b2286c91739d1473945012b5d206eddf Mon Sep 17 00:00:00 2001 From: patak <583075+patak-dev@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:04:40 +0200 Subject: [PATCH] fix: backport #17997, ensure req.url matches moduleByEtag URL to avoid incorrect 304 (#18078) Co-authored-by: coderwei <65948611+coderwei99@users.noreply.github.com> --- packages/vite/src/node/server/middlewares/transform.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 12a440d4c10774..6df8ae25091c6d 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -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.