diff --git a/library/i18n/index.js b/library/i18n/index.js index d1a79813d..20e4131e8 100644 --- a/library/i18n/index.js +++ b/library/i18n/index.js @@ -123,12 +123,18 @@ export function loadLocale(i18n, code) { return okEarlier }) } + // ★ NO PIN, NO FETCH (studio). The hash map is written by the build ONLY for locales it actually + // emitted, so its presence is the one reliable statement that a file is there to fetch. Without + // this guard the flag-OFF build still reaches the network: a bundle with no areas inlines nothing, + // so messages[c] is empty and the preload requests locales/.json on every non-English page — + // a 404 per reader, and fetched with no integrity because there was no hash to pass. Keying on the + // pin makes the flag-off build inert and the flag-on build fail closed to English. + if (!LOCALE_SRI[c]) return Promise.resolve(!!messages[c]) const run = (async () => { try { if (!LOCALE_BASE) return false // base unknown: stay on English const url = new URL(`locales/${c}.json`, LOCALE_BASE).href - const init = LOCALE_SRI[c] ? { integrity: LOCALE_SRI[c] } : {} - const res = await fetch(url, init) + const res = await fetch(url, { integrity: LOCALE_SRI[c] }) if (!res.ok) return false const tree = await res.json() if (!tree || typeof tree !== 'object') return false