Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(frontend): version locale URLs so cached translations pick up new keys (#9098)
Andrew Huangccabc3a3c53d
diff --git a/backend/src/server/plugins/serve-ui.ts b/backend/src/server/plugins/serve-ui.tsindex 3194d8b694..a03c208e5e 100644--- a/backend/src/server/plugins/serve-ui.ts+++ b/backend/src/server/plugins/serve-ui.ts@@ -76,6 +76,7 @@ export const registerServeUI = async (const frontendPath = path.join(dir, frontendName);const indexHtmlPath = path.join(frontendPath, "index.html");+ const localesPath = path.join(frontendPath, "locales", path.sep);let indexHtml = fs.readFileSync(indexHtmlPath, "utf-8");if (cdnHost) {@@ -146,7 +147,12 @@ export const registerServeUI = async (wildcard: false,maxAge: "30d",immutable: true,- index: false+ index: false,+ // Locale files keep fixed paths, so a pod still on the previous release can answer a new+ // build's request for them. Revalidating stops that stale copy from being cached for 30 days.+ setHeaders: (reply, filePath) => {+ if (filePath.startsWith(localesPath)) void reply.header("Cache-Control", "no-cache");+ }});server.route({diff --git a/frontend/src/global.d.ts b/frontend/src/global.d.tsindex 20efc1574e..8c185baec1 100644--- a/frontend/src/global.d.ts+++ b/frontend/src/global.d.ts@@ -1,6 +1,8 @@export {};declare global {+ const INFISICAL_LOCALES_HASH: string;+interface Window {__INFISICAL_RUNTIME_ENV__?: {CAPTCHA_SITE_KEY?: string;diff --git a/frontend/src/translation.tsx b/frontend/src/translation.tsxindex 58d71d3831..bb50ab4fb9 100644--- a/frontend/src/translation.tsx+++ b/frontend/src/translation.tsx@@ -23,6 +23,9 @@ i18n// lookupLocalStorage: "lang"},ns: ["translations"],+ backend: {+ loadPath: `/locales/{{lng}}/{{ns}}.json?v=${INFISICAL_LOCALES_HASH}`+ },interpolation: {escapeValue: false // not needed for react as it escapes by default}diff --git a/frontend/vite.config.ts b/frontend/vite.config.tsindex e38d08c187..4c7102e880 100644--- a/frontend/vite.config.ts+++ b/frontend/vite.config.ts@@ -1,3 +1,6 @@+import { createHash } from "node:crypto";+import { readdirSync, readFileSync } from "node:fs";+import path from "node:path";import { TanStackRouterVite } from "@tanstack/router-plugin/vite";import react from "@vitejs/plugin-react";import { defineConfig, loadEnv, PluginOption } from "vite";@@ -18,6 +21,22 @@ const virtualRouteFileChangeReloadPlugin: PluginOption = {}};+// Locale files keep fixed URLs and are served immutable, so their URL carries a content hash+// or browsers keep translations that predate newly added keys.+const hashLocales = () => {+ const localesDir = path.resolve(__dirname, "public/locales");+ const hash = createHash("sha256");+ readdirSync(localesDir, { recursive: true, withFileTypes: true })+ .filter((entry) => entry.isFile())+ .map((entry) => path.join(entry.parentPath, entry.name))+ .sort()+ .forEach((file) => {+ hash.update(path.relative(localesDir, file));+ hash.update(readFileSync(file));+ });+ return hash.digest("hex").slice(0, 12);+};+// https://vite.dev/config/export default defineConfig(({ mode }) => {const env = loadEnv(mode, process.cwd());@@ -29,6 +48,9 @@ export default defineConfig(({ mode }) => {).replaceAll(".", "-");return {+ define: {+ INFISICAL_LOCALES_HASH: JSON.stringify(hashLocales())+ },server: {allowedHosts,host: true,