Skip to content

Fix optimized fallbacks rendering bold and italic text as regular and upright - #18801

Open
astro-factory[bot] wants to merge 2 commits into
mainfrom
factory/fix-18796
Open

astro-factory[bot] wants to merge 2 commits into
mainfrom
factory/fix-18796

Conversation

@astro-factory

@astro-factory astro-factory Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Bold and italic text now renders correctly in the Fonts API's optimized system fallback. Previously, optimizeFallbacks() emitted @font-face rules that declared font-weight: 700 or font-style: italic while pointing src at a regular, upright local font (e.g. local("Courier New")). That declaration suppresses the browser's bold/oblique synthesis, causing the text to render regular and upright until the web font loads — or permanently when web fonts are blocked.
  • Italic fallback faces and bold faces that would only map to a regular system font (e.g. the monospace stack, which has no bold entry) are no longer emitted. Each weight variant for the same system font is now grouped into one shared family rather than separate families, so Arial Bold is reachable for font-weight: 700 text instead of being shadowed by the earlier Arial-only family. The browser synthesizes bold or oblique from the regular local face in cases where no heavier/slanted system font is available.

Testing

  • Updated assertions in packages/astro/test/units/assets/fonts/core.test.ts to cover the corrected face-grouping and face-omission logic, verifying that italic faces and weight-only-matched bold faces pointing to regular fonts are dropped from the generated @font-face output.

Docs

  • No docs update needed; this is a bug fix to internal CSS generation with no API surface changes.

Closes #18796

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0e0e295

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@astro-factory

astro-factory Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

astro-author owns this pull request

Factory's code author persona works on this branch when a maintainer or Factory's reviewer requests changes, or when checks fail: it pushes follow-up commits, replies to review threads, and asks for another review. It never merges. Unassign astro-author to take the pull request back; reassign it to start a fresh budget.

Rounds used: 1 of 5
Status: waiting for feedback.

— astro-author (Factory persona)

@astro-factory
astro-factory Bot removed the request for review from astro-reviewer November 21, 2026 16:11
@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Nov 21, 2026

@astro-factory astro-factory Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: changes requested.

GitHub doesn't let Factory request changes on a pull request it opened, so this verdict is recorded as a comment.

Findings

  • [medium][correctness] packages/astro/src/assets/fonts/core/optimize-fallbacks.ts:76: Bold text still renders regular when a face's declared weight reaches the bold range but maps to a regular local font. Details are in the inline comment.

Merge Requirement Assessment

Status: gaps found

  • Italic/oblique fallback faces are no longer emitted: met. deriveFallbackVariant returns null for non-normal styles, and faces with no local fonts are skipped (line 116). The updated grouping test checks this.
  • Bold faces that would only map to a regular system font are not emitted (e.g. monospace): met for the bold variant only (line 76). The new skips bold faces when the bold variant only has regular local fonts test checks this. Faces in the normal variant whose declared weight is 600 or more, or is a range that reaches 600, still have the same problem. See the finding.
  • Weight variants for the same system font share one family so Arial Bold is reachable for 700 text: met. familyFont takes its name from the normal list at the same index, and fallbacks uses uniqueFamilyFonts. The updated sans-serif assertions check this, and the system-ui lists line up by index.
  • Bold and italic text renders correctly in the optimized fallback (#18796): partly met. Variable-weight and semibold faces still render regular (see the finding).

Review Status

Verdict: changes required
Context: PR #18801 description (I couldn't retrieve linked issue #18796 with the available tools)
Scope: base c302892e to head 2121e0cb, 3 files.
Changeset: present and covers astro (patch).
Limitations: I couldn't read issue #18796 or the PR discussion. My reasoning about browser font-synthesis behaviour comes from the CSS Fonts matching and synthesis rules, not from running anything.
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected (PR metadata and diff only)
Git scope: PR base/head verified

This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.

@codspeed

codspeed Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 6 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 21 untouched benchmarks


Comparing factory/fix-18796 (0e0e295) with main (db5e3ec)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (c302892) during the generation of this report, so db5e3ec was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Faces whose declared weight reaches the bold range (e.g. 600 or "100 900")
but resolve to a regular system font would match bold text and render it
regular. Cap their emitted font-weight at 500 so browsers synthesize bold.
@astro-factory

astro-factory Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Round 1 of 5: applied the requested changes

I fixed the bug where faces mapped to a regular local font could still declare a bold-capable weight. For those faces, the fallback @font-face now caps the emitted font-weight at 500. A 600 face is emitted as 500, a "100 900" or [100, 900] range comes out as 100 500, and keyword weights such as normal are left alone. With the cap in place, font-weight: 700 text no longer matches regular Arial and gets synthetic bold instead. The cap is in a small capWeight helper in optimize-fallbacks.ts. Bold-variant faces are unchanged.

I added a unit test that checks the emitted font-weight for a string range, an array range, a 600 face, and a 300 face, which should not be capped.

Checks:

  • Rebuilt packages/astro.
  • Ran astro-scripts test "test/units/assets/fonts/*.test.ts": 122 pass, 0 fail.
  • Biome format and lint report no issues on both changed files.

One thing to review: the 500 limit is based on my understanding of when Chromium and Firefox synthesize bold (Chromium when the face is below 600, Firefox when it is at most 500, so 500 works for both). I haven't checked this in a browser.

Tradeoff: a 600 face now uses a regular local font and synthesizes bold. The alternative was to move 600 into the bold variant. I chose the cap because it handles single weights and ranges the same way.

Pushed 0e0e295463a3.
Replied to 1 review thread(s), resolved 1.
Asked astro-reviewer to review again.

These changes were made by an LLM. They may be wrong; review them like any other contribution.
— astro-author (Factory persona)

@astro-factory
astro-factory Bot removed the request for review from astro-reviewer November 21, 2026 16:21

@astro-factory astro-factory Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approved. No blocking findings remain.

GitHub doesn't let Factory approve a pull request it opened, so this verdict is recorded as a comment.

Findings

No findings.

Merge Requirement Assessment

Status: satisfied

  • Bold faces shouldn't point at regular local fonts (issue #18796). In optimize-fallbacks.ts, a non-normal variant entry is now dropped when its local font also appears in the provider's normal list. The monospace stack has no bold entry, so a 700 face that would only map to Courier New is no longer emitted. Bold text then falls back to the regular face and the browser synthesizes bold. The test skips bold faces when the bold variant only has regular local fonts covers this.
  • Italic and oblique faces shouldn't be emitted, so the browser can synthesize the slant. deriveFallbackVariant returns null for any style other than normal, and faces with no remaining local fonts are skipped. The test groups bold faces under the normal fallback family and skips italic faces covers this.
  • Weight variants for the same system font should share one family, so Arial Bold is reachable at weight 700. Each local font is paired with the normal-list font at the same position (familyFont), and only one prepended family name is emitted per position. With system-ui, the bold list's Arial Bold (position 4) lands under the Arial family as intended, and fonts the bold list shares with the normal list are filtered out. Updated assertions check both the face name and the src font.
  • Normal faces shouldn't declare bold-capable weights. capWeight caps numeric weights and ranges at 500 for normal-variant faces. This covers ranges like 100 900 and single weights like 600, which would otherwise block bold synthesis. Non-numeric weights and undefined pass through unchanged, and renderFontWeight renders array weights correctly. The test caps the weight of faces backed by regular local fonts… covers the string-range, array-range, numeric and in-range cases.

Review Status

Verdict: ready to merge based on static review
Context: PR #18801 plus its description and linked issue #18796 (as referenced in the PR body)
Scope: PR #18801, base c302892e → head 0e0e2954 (3 files).
Changeset: present and covers astro (patch).
Limitations: Only the provided read-only PR file tools were available. I didn't open issue #18796 itself; I took the requirements from the PR description.
Validation: Static review only. No project code, tests, builds or checks were run.
GitHub context: supplied only
Git scope: PR base/head verified

This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fonts API: optimized fallbacks render bold and italic text regular and upright

1 participant

⌂ 换网址