diff --git a/Website/instrumentation.ts b/Website/instrumentation.ts new file mode 100644 index 00000000..cd0b14da --- /dev/null +++ b/Website/instrumentation.ts @@ -0,0 +1,6 @@ +export async function register() { + if (process.env.NEXT_RUNTIME === 'nodejs') { + const { removeStaleRouteCache } = await import('./lib/removeStaleRouteCache'); + await removeStaleRouteCache(); + } +} diff --git a/Website/lib/removeStaleRouteCache.ts b/Website/lib/removeStaleRouteCache.ts new file mode 100644 index 00000000..f655bfd9 --- /dev/null +++ b/Website/lib/removeStaleRouteCache.ts @@ -0,0 +1,8 @@ +import { rm } from 'fs/promises'; +import path from 'path'; + +// Pages cached on disk by an earlier deployment take precedence over the current build +// and reference static chunks that no longer exist. Remove them before serving requests. +export async function removeStaleRouteCache() { + await rm(path.join(process.cwd(), '.next', 'server', 'route-cache'), { recursive: true, force: true }); +} diff --git a/Website/next.config.ts b/Website/next.config.ts index 4cda9348..b4094e3e 100644 --- a/Website/next.config.ts +++ b/Website/next.config.ts @@ -7,6 +7,11 @@ const nextConfig = { turbopack: { root: path.join(__dirname, '..'), }, + experimental: { + // Deployments overwrite the build in place. Pages cached on disk at runtime + // would survive the next deployment and reference static chunks that no longer exist. + isrFlushToDisk: false, + }, async headers() { return [ {