fix: backport #17997, ensure req.url matches moduleByEtag URL to avoid incorrect 304 (#18078)

Co-authored-by: coderwei <65948611+coderwei99@users.noreply.github.com>
This commit is contained in:
patak 2024-09-11 10:04:40 +02:00 committed by GitHub
parent d90ba40474
commit 74a79c53b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.