diff --git a/packages/producer/src/services/deterministicFonts-textSubset.test.ts b/packages/producer/src/services/deterministicFonts-textSubset.test.ts index e3b0a39cd..ec3552e76 100644 --- a/packages/producer/src/services/deterministicFonts-textSubset.test.ts +++ b/packages/producer/src/services/deterministicFonts-textSubset.test.ts @@ -39,4 +39,47 @@ describe("Google Fonts text subsetting", () => { expect(new URL(requestedUrl).searchParams.get("text")).toContain("旅行"); }); + + it("includes case variants for transformed supplemental alias weights", async () => { + let requestedUrl = ""; + const fetchImpl = (async (input: unknown) => { + requestedUrl = String(input); + return new Response("", { status: 400 }); + }) as unknown as typeof fetch; + + await injectDeterministicFontFaces( + `
${caseChangingCharacters}
`, + { fetchImpl, allowSystemFontCapture: false }, + ); + + expect(new URL(requestedUrl).searchParams.has("text")).toBe(false); + }); }); diff --git a/packages/producer/src/services/deterministicFonts.ts b/packages/producer/src/services/deterministicFonts.ts index 0a20486de..158bc681c 100644 --- a/packages/producer/src/services/deterministicFonts.ts +++ b/packages/producer/src/services/deterministicFonts.ts @@ -1193,18 +1193,26 @@ export interface InjectDeterministicFontFacesOptions { } // Keep the complete CSS request under the broadly supported ~2 KB URL limit. -// Using unique source characters covers static text plus strings authored in -// scripts, while collapsing repeated prose and base64 assets to a tiny set. +// Using unique source/decoded characters plus deterministic case variants covers +// static text, strings authored in scripts, and CSS case transforms while +// collapsing repeated prose and base64 assets to a tiny set. const GOOGLE_FONTS_TEXT_MAX_ENCODED_LENGTH = 1_700; function extractGoogleFontsText(html: string): string | undefined { const { document } = parseHTML(html); const decodedBodyText = document.body?.textContent ?? ""; - const uniqueCharacters = [...new Set([...Array.from(html), ...Array.from(decodedBodyText)])].join( - "", - ); - return encodeURIComponent(uniqueCharacters).length <= GOOGLE_FONTS_TEXT_MAX_ENCODED_LENGTH - ? uniqueCharacters + const characters = [...Array.from(html), ...Array.from(decodedBodyText)]; + const uniqueCharacters = new Set