From 27f60e0b7784603c6fb300bd8dce64515eb98962 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 1 Jan 2024 12:56:52 +0530 Subject: [PATCH] fix: invalidate module cache for subsequent builds (#3398) --- src/client/app/index.ts | 6 +++++- src/node/build/build.ts | 4 +++- src/node/build/render.ts | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 023b93ae62a4..a7db0c232a4e 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -135,7 +135,11 @@ function newRouter(): Router { pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') } - pageModule = import(/*@vite-ignore*/ pageFilePath) + if (import.meta.env.SSR) { + pageModule = import(/*@vite-ignore*/ pageFilePath + '?t=' + Date.now()) + } else { + pageModule = import(/*@vite-ignore*/ pageFilePath) + } } if (inBrowser) { diff --git a/src/node/build/build.ts b/src/node/build/build.ts index 7dca478a67aa..d6177864ebc0 100644 --- a/src/node/build/build.ts +++ b/src/node/build/build.ts @@ -52,7 +52,9 @@ export async function build( } const entryPath = path.join(siteConfig.tempDir, 'app.js') - const { render } = await import(pathToFileURL(entryPath).toString()) + const { render } = await import( + pathToFileURL(entryPath).toString() + '?t=' + Date.now() + ) await task('rendering pages', async () => { const appChunk = diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 8818a5e14d03..9276818562f7 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -52,7 +52,11 @@ export async function renderPage( try { // resolve page data so we can render head tags const { __pageData } = await import( - pathToFileURL(path.join(config.tempDir, pageServerJsFileName)).toString() + pathToFileURL( + path.join(config.tempDir, pageServerJsFileName) + ).toString() + + '?t=' + + Date.now() ) pageData = __pageData } catch (e) {