Repository navigation
fix(core): pages with many CJK characters fetch fonts in several requests - #7823
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 81 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 78be1e4645ece5958cc9c74bcdef316a6ee53cb2.
The tested oversized CJK case stays in bounded text= requests, and the existing fetch implementation, cache and retry deadline are reused. One rendering regression blocks this head.
Important — preserve shaping across subsets (packages/core/src/fonts/deterministicFonts.ts:1657, 1703–1705). The chunks partition the page's unique characters, then assign disjoint unicode-ranges. Characters that need to shape together can therefore select different font faces. This changes glyphs and layout, even with every request succeeding.
I reproduced this through injectDeterministicFontFaces with a real DejaVu Sans woff2 and Chromium: an early lam, 600 distinct CJK characters, then visible Arabic لا. Lam lands in chunk 1 and alef in chunk 4. The same 100px text measures 57.03125px on the base, but 60.9375px at this head, matching a deliberately split-face control. All relevant font faces loaded. Font responses were mocked with real font bytes; this is a browser/shaping check, not a live Google Fonts test.
Please keep shaping-connected characters in the same font subset, including joins across grapheme boundaries; merely splitting on graphemes will not preserve Arabic joining. A full-font fallback for affected complex scripts is another option if it preserves the intended request/deadline limits. Add a real-font regression that preserves the joined result while retaining the bounded CJK requests.
Validation: full bun run build passed; the 26 committed font suites passed 294 tests. Both new textChunks tests fail with the production change reverted and pass after restoration. An additional 503 probe confirmed that a later transient failure rejects a fail-closed compile. A later permanent 400 can retain earlier chunks, consistent with the existing skip-missing-face policy; that is separate from the shaping blocker.
Scope notes: distributed chunks consume the same compiled, hashed plan artifact rather than independently choosing fonts. The default/authored/fallback requests all still use the existing font fetch seam; this PR adds no transport or proxy bypass, but I did not validate the deployed capture proxy/CIDR enforcement. Each generated text payload is capped at 1,700 encoded characters; the 600-CJK fixture makes four requests, but total count remains input-dependent, not capped by a small constant. The existing fail-closed wall-clock budget remains. This changes output for consumers of the shared core font resolver.
Nit: Consider an explicit chunk-count ceiling with a typed failure, so very large character inventories has an explicit request-count bound in addition to the time budget.
Need: yes · Size: ok · Reuse: existing font fetch/cache/retry helpers · Simpler: preserve shaping groups or use a complex-script fallback · Structure: fine (checked authoredGoogleFonts and existing family resolution; no extraction needed)
Risk: medium — shared font resolution changes rendered glyphs and layout.
Verdict: REQUEST CHANGES
Reasoning: The oversized CJK request test passes, but arbitrary character partitions introduce a reproduced Arabic shaping regression.
— Rames / cutroom-review
|
Fixed at Shaping. Only Han, Hiragana, Katakana and precomposed Hangul syllables are now spread across requests. Each of those is a single glyph that does not shape against its neighbours. Everything else stays in the first request: Latin, Arabic and other joining scripts, marks and variation selectors. So does any ideograph or syllable followed by a mark or selector. Your lam-alef case is now one face. If the characters that must stay together overflow one request, the family is fetched whole, as on main. Regression tests in
Each rule has a mutant that turns its own test red: splitting every character turns the lam-alef and Cyrillic tests red, and dropping the attached-mark rule turns the selector test red. The test checks face ownership, not a browser measurement. Same face means the same font file, and that is the invariant shaping depends on. I did not add a Chromium real-font test to core. Chunk-count ceiling (nit): not added. Only standalone characters are spread, so the count is about distinct ideographs ÷ 188. The fail-closed wall-clock budget already bounds it. A second limit would be a second owner for the same decision. Live Google Fonts at this head, 600-ideograph Noto Serif SC page: 4 requests, all with |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 2994281965334cf89336314158bc8cb9c86b7d66; re-reviewed the delta from 78be1e46 against my change request 5910019218.
Arabic is fixed: the real DejaVu Sans woff2/Chromium probe now renders lam-alef at 57.03125px, with pixels identical to the full-face control. Thai and Devanagari mark probes also match. The shaping contract still fails for other compositions.
Important — keep composed sequences and their normalized forms together (packages/core/src/fonts/deterministicFonts.ts:1937–1941, 1956–1973, 1683).
- Hangul
각(U+AC00 + U+11A8) composes to각. The syllable is classified as loose, while trailing Jamo is not a mark and stays in the first run. With 600 earlier CJK characters, they select different faces. With real Noto Sans KR, the same 100px text measures 91.999908px on the base/full face, 183.999817px at this head. - Latin
a+ U+0301 is assigned to one face, but its generated range omits composed U+00E1. In the real DejaVu probe, the full face/base drawsá; this head draws only the acute accent. The advance width happens to remain equal, so a width-only test misses it. Full-width and half-width kana/dakuten probes also differ in pixels from their full-face controls.
These are actual injectDeterministicFontFaces outputs in Chromium 1208 with loaded real woff2 bytes and mocked network responses. The same fixtures match their full-face controls with the original base production file at ded5e3eec25cd2da405fb30c2751d6406726607d. This continues the existing shaping finding rather than a request to change the intended CJK behavior.
Please include Hangul LV+T/grapheme continuations in the characters that must stay together, and preserve normalization closure in both requested glyphs and emitted unicode-ranges. A conservative whole-family fallback for sequences that cannot safely be partitioned is also acceptable. Add real-font regressions for Hangul composition and the Latin/kana mark cases, checking pixels as well as width.
Validation: gated bun run build passed; bunx vitest run src/fonts --maxWorkers=2 passed 297 tests. Reverting to the previous reviewed production file makes the committed keeps characters that shape together in one face: Arabic lam-alef beside 600 CJK and asks for the whole family, as before, when characters that must share a face overflow one request tests fail (2 failed / 3 passed); restoring this head gives 5 passed. The real-font/browser probes above run separately from those committed tests; no live Google Fonts or cloud render was run.
Nit, still open — request count: there is still no explicit ceiling. The count probe produced 4 / 27 / 54 CSS requests for 600 / 5,000 / 10,000 distinct CJK characters, all payloads at most 1,699 encoded characters. Two fresh lookups produced identical request lists and HTML. The existing shared deadline remains; it is not a request-count cap. This is separate from the shaping blocker. Fetch/cache/retry transport remains unchanged.
Need: yes · Size: ok · Reuse: existing font fetch/cache/retry helpers · Simpler: conservatively retain unsafe shaping groups · Structure: fine (checked authoredGoogleFonts and every PageText caller; no extraction needed)
Risk: medium — shared font resolution can omit or split rendered glyphs.
Verdict: REQUEST CHANGES
Reasoning: Arabic is repaired, but real-font Hangul and combining-mark probes still show rendering regressions against the base.
— Rames / cutroom-review
|
Fixed at Grapheme clusters and normalization closure. Past the limit, every grapheme cluster (
Real-font check, pixels and width. Chromium, fonts live from Google, each case beside 600 CJK at 100px. Control: the same case alone on a page, one
Main's whole-family fetch already splits 가+ᆨ and ガ, because Google's own range slices separate them. This head draws them as the complete font does. Committed tests. In core, these are face-ownership tests: each cluster character and its composed form are owned by one face, and a text-transform page fetches the whole family. Each rule turns its own tests red when mutated: cluster pinning off is 5 red, NFC/NFD closure off is 3 red, transform guard off is 1 red. I kept the Chromium pixel probe out of core's unit suite, because core has no browser or font fixtures today. If you want it committed, say where it should live and I'll add it. Request count (nit). Still not capped. A cap would be a second limit beside the fail-closed deadline, and the deadline already decides when a font fetch has taken too long. A page with 5,000 or more distinct ideographs runs into that deadline and fails typed, rather than hanging. If you'd rather have it fail at a fixed count, I'll add the cap with a |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 78794d377d7302f9e1b6e902e26106c392d22f82; this is one commit ahead of 29942819, with no rebase.
The earlier exact cases are repaired. In Chromium 1208 with real font bytes, lam-alef remains 57.03125px and Hangul LV+T is now 91.999908px rather than doubled. Plain Latin+acute, full/half-width kana+dakuten, Thai and Devanagari also match the full-font controls in pixels.
Important — case-close the newly normalized characters too (packages/core/src/fonts/deterministicFonts.ts:1952, 1987, 2113). addCaseClosure runs on the source codepoints, then composingCharacters adds NFC/NFD forms directly with pinned.add. For source a + U+0301 with text-transform: uppercase, the first face claims á but not Á; uppercase source with lowercase has the inverse omission. This is a remaining instance of the composing-glyph coverage issue.
I checked both DOM screenshots and canvas output. Complete DejaVu Sans woff2 responses lose the base letter. More importantly, using live Google Noto Sans KR CSS and font responses, the uppercase case keeps the letter but renders the acute separately to its right instead of above it. Equal advance widths hide the error. The same-family control explicitly requesting the composed forms draws the accent correctly. Live Noto Sans responses were less severe, so I am not treating every pixel difference as a missing-glyph blocker.
Minimal live fixture: 600 distinct Han characters in an HTML comment, followed by <h1 style="font-family: 'Noto Sans KR'; font-size:100px; text-transform:uppercase">á</h1>. Use Á with lowercase for the reverse case.
Please pass the already-collected locales through to composingCharacters and reuse addCaseClosure for the original/NFC/NFD characters, keeping any case-generated normalization forms in the same face. Add uppercase and lowercase cluster assertions for Á/á. A temporary local implementation of that change makes both new assertions pass and restores the accent above the letter in the live KR probe; it also restores exact DOM/canvas parity in the DejaVu probe. The local change was reverted after verification.
Validation, all gated:
- Full build and the 302 committed font tests pass at this head.
- Restoring
29942819makes 5 of the 10 committed chunk tests fail; restoring78be1e46makes the lam-alef test fail. Restoring this head gives 10 passed. - The two added case-transform assertions fail here (2 failed / 10 passed) and pass with the local helper repair (12 passed).
- Real-font shaping, live subset fetches and DOM screenshots are separate probes; no cloud render was run.
The earlier nonblocking request-count concern is unchanged; it is not the reason for this verdict.
Need: yes · Size: ok · Reuse: existing locale-aware addCaseClosure · Simpler: apply the existing closure to normalized forms · Structure: fine (checked PageText callers and existing character closure; no new abstraction needed)
Risk: medium — composed glyphs can still render incorrectly after CSS case transformation.
Verdict: REQUEST CHANGES
Reasoning: The original lam-alef and Hangul failures are fixed, but case transformation still breaks normalization coverage; the proposed small helper reuse was verified against the failing cases.
— Rames / cutroom-review
|
Fixed at
Two new assertions:
Both fail at Live Google Noto Sans KR in Chromium, beside 600 CJK at 100px, compared against the same case alone in one
The five earlier cases in my probe (가+ᆨ, a+◌́, カ+゙, ガ, 葛+VS17) still match at this head; I did not rerun your lam-alef probe. |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 201211725bf8149594c68fcaff9ff8b915c0324b; the delta from 78794d37 is two files, with no rebase.
The remaining case/normalization blocker is fixed. composingCharacters now uses the existing addCaseClosure for original/NFC/NFD codepoints, with the page's collected locales passed through pageTextRuns (packages/core/src/fonts/deterministicFonts.ts:1946, 1993, 2128). Added variants remain inside the first face and its request-size check; fetch and network-policy paths are unchanged in this delta.
Validation through the shared gate:
- Full build passed; font suite plus the retained reviewer assertions: 316 passed.
- Both original uppercase/lowercase assertions pass. Restoring
78794d37source makes those two and the two new committed cases fail (4 failed / 20 passed); restoring this head passes all 24. - Chromium 1208 with complete DejaVu Sans woff2: both cases match the full-font control exactly in canvas pixels and DOM screenshots.
- Live Google Noto Sans KR: both accents are correctly above their letters, with matching widths. These screenshots exactly match the previously verified temporary repair. The separate single-face control still has minor rasterization differences; I am not claiming live pixel identity.
No cloud render was run. The earlier nonblocking total-request-count concern is unchanged.
Need: yes · Size: ok · Reuse: existing locale-aware addCaseClosure · Simpler: already minimal · Structure: fine (checked character collection, normalization and PageText consumers; no split)
Risk: medium — font partitioning affects rendered glyphs; the previously failing cases now have browser and mutation controls.
Verdict: APPROVE
Reasoning: The reviewed delta closes the missing case variants without changing request routing or the existing fallback boundaries.
— Rames / cutroom-review
What
Pages whose text no longer fits one Google Fonts
text=request now fetch their fonts in several boundedtext=requests. They no longer fetch the whole family.Why
extractGoogleFontsTextdropped the page text once it encoded past 1,700 characters, and the compile then asked Google for the entire family. Each CJK character encodes to 9 bytes, so any page with roughly 190 or more distinct CJK characters hit this. A whole CJK family is hundreds of woff2 files, and they do not download inside the compile's 20 s font budget, so the render failed with a font timeout or "Font fetch budget exhausted".To reproduce: a page using a Google family such as Noto Serif SC, with 600 distinct ideographs. Before this change, its one CSS request carries no
text=.Related work
None.
How
text=request makes exactly the request it does on main.pageTextRunsbuilds several runs, each within the existing 1,700 encoded characters:Intl.Segmenter, as intext/pretext.ts) that has more than one code point or composes under NFC: 가+ᆨ, a+◌́, カ+゙, ガ, 葛+VS17. Its NFC and NFD forms go with it, each case-closed with the page's locales like every other character, so the face's range covers whichever form the browser draws (각, á, ガ, and Á underuppercase).text-transform: full-widthorfull-size-kana(which draw characters the source does not contain), the family is fetched whole, as on main.fetchGoogleFontmakes one request per run, for both the default and the authored-link URLs. With more than one run, each returned face gets aunicode-rangeof exactly its run's codepoints, so same-weight faces do not shadow each other.text=is fetched once, as before.Test plan
deterministicFonts-textChunks.test.ts, 600 distinct CJK characters:text=within 1,700 encoded characters, and together they request every charactertext-transform: full-widthwith 600 CJK fetches the whole family as on main.uppercasekeeps Á in its face; A+◌́ underlowercasekeeps á.googleSubsets(authored link) andaliasSupplementasserted the old drop-to-whole-family behaviour for CJK and now assert the split. ThealiasSupplementtest keeps its subject, collapsing interleaved shared sources, with a short page.src/fonts: 26 files, 304 tests pass; the changed files passed three runs in a row.tsc --noEmit, oxfmt, lint, fallow audit (0 dead code, complexity or duplication) and the comment ratchet all pass.Live Google Fonts, a 600-ideograph Noto Serif SC page,
injectDeterministicFontFaceswith fail-closed font fetch:text=The 12 s was on a fast link; on a slower one, 808 files miss the 20 s budget.
Real-font shaping in Chromium, fonts fetched live from Google. Each case sits beside 600 CJK characters at 100 px. "One face" is the same case alone on a page, one
text=request, drawn from Google's own bytes; widths are also checked against the complete font file.uppercase(Noto Sans KR)78794d37lowercase(Noto Sans KR)78794d37The whole-family fetch on main already splits 가+ᆨ and ガ, because Google's own
unicode-rangeslices put the two halves in different faces.