From b0e22900ceaddc4a41d60877d39182acdf894086 Mon Sep 17 00:00:00 2001 From: Rune Johansen Date: Mon, 6 Jul 2026 12:38:10 +0200 Subject: [PATCH 1/2] chore: replace build date with app version for cache busting in HTML and config files --- packages/pxweb2/index.html | 4 ++-- .../pxweb2/src/app/util/content/localeContent.ts | 2 +- .../pxweb2/src/app/util/hooks/useTopicIcons.tsx | 2 +- packages/pxweb2/src/i18n/config.ts | 2 +- packages/pxweb2/src/vite-env.d.ts | 1 + packages/pxweb2/vite.config.ts | 13 ++++++++----- 6 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 packages/pxweb2/src/vite-env.d.ts diff --git a/packages/pxweb2/index.html b/packages/pxweb2/index.html index a5508f3f6..d72dd1876 100644 --- a/packages/pxweb2/index.html +++ b/packages/pxweb2/index.html @@ -13,7 +13,7 @@ href="./images/favicon-darkmode.svg" /> - + - +
diff --git a/packages/pxweb2/src/app/util/content/localeContent.ts b/packages/pxweb2/src/app/util/content/localeContent.ts index 5e308868b..3b4620e93 100644 --- a/packages/pxweb2/src/app/util/content/localeContent.ts +++ b/packages/pxweb2/src/app/util/content/localeContent.ts @@ -24,7 +24,7 @@ export async function fetchLocaleContent( const fetchPromise = (async () => { try { const res = await fetch( - `./content/${key}/content.json?v=${__BUILD_DATE__}`, + `./content/${key}/content.json?v=${__APP_VERSION__}`, { cache: 'no-store', }, diff --git a/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx b/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx index ea3334c41..0d2a13d8b 100644 --- a/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx +++ b/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; -const ICON_MAP_URL = `./icons/topicIconMap.json?v=${__BUILD_DATE__}`; +const ICON_MAP_URL = `./icons/topicIconMap.json?v=${__APP_VERSION__}`; const ICON_BASE_PATH = './icons/topic'; export type TopicIconComponents = { diff --git a/packages/pxweb2/src/i18n/config.ts b/packages/pxweb2/src/i18n/config.ts index 20bc98052..cc856a7a7 100644 --- a/packages/pxweb2/src/i18n/config.ts +++ b/packages/pxweb2/src/i18n/config.ts @@ -32,7 +32,7 @@ const initPromise = i18n .use(languageDetector) .init({ backend: { - loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json?v=${__BUILD_DATE__}`, + loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json?v=${__APP_VERSION__}`, }, fallbackLng: config.language.fallbackLanguage, defaultNS, diff --git a/packages/pxweb2/src/vite-env.d.ts b/packages/pxweb2/src/vite-env.d.ts new file mode 100644 index 000000000..41fad5b54 --- /dev/null +++ b/packages/pxweb2/src/vite-env.d.ts @@ -0,0 +1 @@ +declare const __APP_VERSION__: string; diff --git a/packages/pxweb2/vite.config.ts b/packages/pxweb2/vite.config.ts index 57066a49e..d497fad20 100644 --- a/packages/pxweb2/vite.config.ts +++ b/packages/pxweb2/vite.config.ts @@ -3,6 +3,10 @@ import react, { reactCompilerPreset } from '@vitejs/plugin-react'; import babel from '@rolldown/plugin-babel'; import path from 'path'; import { virtualModulePlugin } from './vite-plugin-virtual-module'; +import pkg from '../../package.json'; + +const buildNumber = + process.env.BUILD_NUMBER ?? process.env.GITHUB_RUN_NUMBER ?? 'local'; // Custom plugin to handle theme CSS injection const themeInjectorPlugin = (): Plugin => ({ @@ -10,16 +14,16 @@ const themeInjectorPlugin = (): Plugin => ({ transformIndexHtml(html) { // Remove the theme CSS link from the original HTML html = html.replace( - '', + '', '', ); // Inject it at the end of head to ensure it loads last html = html.replace( '', - '', + '', ); // Replace cache busting build date placeholder - return html.replace(/__BUILD_DATE__/g, new Date().toISOString()); + return html.replace(/__APP_VERSION__/g, `${pkg.version}+${buildNumber}`); }, }); @@ -57,7 +61,6 @@ export default defineConfig({ // Used for cache busting of configuration files. // Since we don't update pkg.version on release yet, we use build date instead. // import pkg from './package.json'; - // __BUILD_VERSION__: JSON.stringify(pkg.version), - __BUILD_DATE__: JSON.stringify(new Date().toISOString()), + __APP_VERSION__: JSON.stringify(`${pkg.version}+${buildNumber}`), }, }); From c94e8a74579437d5c7ec1bf71d4f4e483bff3d0b Mon Sep 17 00:00:00 2001 From: Rune Johansen Date: Mon, 6 Jul 2026 12:57:41 +0200 Subject: [PATCH 2/2] chore: remove outdated comment regarding package version in vite.config.ts --- packages/pxweb2/vite.config.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/pxweb2/vite.config.ts b/packages/pxweb2/vite.config.ts index d497fad20..663ae10be 100644 --- a/packages/pxweb2/vite.config.ts +++ b/packages/pxweb2/vite.config.ts @@ -59,8 +59,6 @@ export default defineConfig({ }, define: { // Used for cache busting of configuration files. - // Since we don't update pkg.version on release yet, we use build date instead. - // import pkg from './package.json'; __APP_VERSION__: JSON.stringify(`${pkg.version}+${buildNumber}`), }, });