From e9a6011906edb6d9dc8417e7c560c4ee234d222c Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 18 Jan 2024 18:35:20 +0100 Subject: [PATCH] fix: adding a public file with the same path as a module --- packages/vite/src/node/server/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 38c5c209ad8000..1c507d1ff000fb 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -684,7 +684,17 @@ export async function _createServer( if (publicDir && publicFiles) { if (file.startsWith(publicDir)) { - publicFiles[isUnlink ? 'delete' : 'add'](file.slice(publicDir.length)) + const path = file.slice(publicDir.length) + publicFiles[isUnlink ? 'delete' : 'add'](path) + if (!isUnlink) { + const moduleWithSamePath = await moduleGraph.getModuleByUrl(path) + const etag = moduleWithSamePath?.transformResult?.etag + if (etag) { + // The public file should win on the next request over a module with the + // same path. Prevent the transform etag fast path from serving the module + moduleGraph.etagToModuleMap.delete(etag) + } + } } } await handleFileAddUnlink(file, server, isUnlink)