Repository navigation
fix(producer): inline a local font only while the page stays within its size limit - #8152
Conversation
…ts size limit Only url() sources inside @font-face rules are replaced, and every inlined copy is charged to the render's expansion budget. Once the budget is spent, the remaining references keep loading the font from its file.
Edit accuracy: accurate 271 (base branch 271), smooth 79 of thoseThe gate passes. Quarantined, measured but not gated (0) |
terencecho
left a comment
There was a problem hiding this comment.
Reviewed 65e337d. Two merge blockers remain:
[P2] Add the lane's required fails without the fix: line naming htmlCompiler.sizeLimit.test.ts / "inlines a font that many rules name only while the page stays within the limit". The current body explains the regression, but does not contain that required line.
[P2] Clear the introduced required CI failures. Detect changes rejects deletion of htmlCompiler.fontEmbed.test.ts; Build, Typecheck and Test then fail because change detection did not succeed. Comments separately fails because compositionSizeLimit.ts raises its comment share from 7.9% to 8.3%. I read both failing-job logs. Preserve/rework the anchoring coverage through the repo's deliberate-deletion workflow and resolve the comment gate, then rerun CI.
No additional code blocker found in this pass. The rewritten matches are scoped to style/font-face blocks, filesystem/private-file checks remain, equivalent absolute paths share encoded data, and each inserted copy is charged before insertion, keeping refused copies file-backed. Full workspace build passed; 21 size-limit tests and 196 compiler tests passed. Removing the tryChargeGenerated refusal makes the new regression produce 55,926,646 characters and fail; restoring it passes. No end-to-end font render performed.
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
Re-reviewed 4a4c185. The earlier blockers are resolved: the body now has the required fails-without-the-fix line, htmlCompiler.fontEmbed.test.ts is retained and exercises the real compileForRender pipeline, and the budget method is renamed without raising comment share. Local deletion/comment gates pass; their CI checks are green too.
The product delta from 65e337d is the method rename and matching call, with its fit-or-skip behavior unchanged. The new anchoring test checks distinct short/suffix/regex-character font paths and preserves the path mentioned in a CSS comment. Full workspace build passed; 22 size-limit/anchoring tests and 196 compiler tests passed (218 total). Deliberately using the first font's data for every path makes the new anchoring test fail; restoring the reviewed source passes. The prior budget-refusal mutation proof still applies to the unchanged budget logic.
No remaining blocker found. CI is still running, with no failed checks at submission. No end-to-end font render performed.
— tai (automated review)
What
A render inlines a project font as a data URI only while the compiled page stays within the render's size limit. Once the limit is reached, the remaining references keep loading the font from its file, as fonts over 5 MiB already do.
Why
Each local font is capped at 5 MiB, but its data URI was written into every
url(path)that named it, anywhere in the page. One 5 MiB font named by a few dozen rules turned into a compiled page of hundreds of megabytes, which every later compile step copies and parses again. With 8 rules the new test's page is 62.9 MB on main.Related work
Builds on #8144 and the
CompositionExpansionBudgetit shares across the compile. No second budget.How
embedLocalFontFacesnow rewrites only theurl()sources inside@font-facerules in<style>blocks (the same rules it reads fonts from), using the existingreplaceMatchesscans. Aurl()in an ordinary rule is left alone.CompositionExpansionBudget.chargeGeneratedIfItFits, which charges only what fits and reports whether it did. A copy that does not fit keeps its file path and the compile logs one warning; the render does not fail.localFontDataUri; the containment, link and private-file checks are unchanged.urlOccurrenceReis removed: replacing the scannedurl()match by its exact path cannot hit a longer path that ends the same way, which is what that regex guarded. Its test file now checks the same hazards throughcompileForRender:img/logo.ttfbesideassets/img/logo.ttf, a path with regex characters, and the path mentioned in a CSS comment each keep their own content.)is still not embedded (the sharedurl()scanner stops there, as on main); it stays file-backed.Test plan
fails without the fix:
htmlCompiler.sizeLimit.test.ts"inlines a font that many rules name only while the page stays within the limit" builds a 62.9 MB page on main from one 5 MiB font named by 8 rules.New test in
htmlCompiler.sizeLimit.test.ts: one 5 MiB font named by 8@font-facerules and one ordinary rule. It fails on main (62.9 MB page against a limit near 32 MiB) and passes here: some copies inline, the rest and the ordinary rule keepurl("big.ttf").Breaking
chargeGeneratedIfItFitsto always accept turns only that test red (55.9 MB page); restored. Handing every source the first font's data URI turns the anchoring test red; restored.htmlCompiler.sizeLimit.test.ts21 passed,htmlCompiler.fontEmbed.test.ts1 passed,htmlCompiler.test.ts196 passed (includes the existing local-font tests: private files, scene dedupe, equivalent paths, ttf/otf, large collections). Producertsc --noEmit, oxfmt, oxlint andfallow auditclean.Unit tests added/updated
Manual testing performed (no end-to-end render)
Documentation updated (if applicable): no docs change
Comments follow CONTRIBUTING.md "Comments"