mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 06:40:50 +00:00
The service worker serves the locale catalog's boot script cache-first,
and its URL carried the package version. Every build of one release
therefore shared one URL: an instance updated within a release (a beta,
a redeploy) kept the catalog of its first build, and every message added
since read as its raw key ("timeline.zoom.range", "timeline.selection.week")
or fell back to English.
next.config.ts now hashes the message catalogs at build time and the
layout keys the script by that hash, so a changed catalog is a new URL.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
|
* The locale catalog's boot script is cached by its URL: the service worker
|
|
* serves `/i18n/<locale>.js?v=…` cache-first. Keyed by the package version,
|
|
* every build of one release shared one URL, so a beta updated within a
|
|
* release kept its first catalog and every key added since read as its raw
|
|
* name ("timeline.zoom.range"). The key is the catalogs' content hash now.
|
|
*/
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const read = (rel: string) => readFileSync(join(process.cwd(), rel), "utf8");
|
|
|
|
describe("the locale catalog's cache key", () => {
|
|
it("moves with the catalogs, not with the release", () => {
|
|
const layout = read("src/app/layout.tsx");
|
|
const src =
|
|
/src=\{`\/i18n\/\$\{initialLocale\}\.js\?v=\$\{([^}]*)\}`\}/.exec(layout);
|
|
expect(src?.[1]).toContain("NEXT_PUBLIC_I18N_CATALOG_VERSION");
|
|
expect(src?.[1]).not.toContain("NEXT_PUBLIC_APP_VERSION");
|
|
});
|
|
|
|
it("is computed from the message catalogs at build time", () => {
|
|
const config = read("next.config.ts");
|
|
expect(config).toMatch(
|
|
/NEXT_PUBLIC_I18N_CATALOG_VERSION:\s*catalogVersion\(\)/,
|
|
);
|
|
expect(config).toMatch(/join\(process\.cwd\(\), "messages"\)/);
|
|
});
|
|
});
|