Skip to content

fix(ui): draw the system font until the brand faces register (YPE-5637) - #169

Merged
Dustin-Kelley merged 8 commits into
mainfrom
dk/font-fix
Sep 8, 2026
Merged

Dustin-Kelley merged 8 commits into
mainfrom
dk/font-fix

Conversation

@Dustin-Kelley

@Dustin-Kelley Dustin-Kelley commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

After any re-render that only changes text color (a theme flip is the easiest repro), Button.Text labels ellipsize ("Share" → "Sh…") and multi-line Text drops its last line. Headings also render regular weight on the first frame and turn bold on the next re-render.

Repro (confirmed on main)

Main's example tabs do not mount these primitives (Bible / VOTD / Card are webviews). Put native Text and Button.Text on a throwaway screen — Share / Read chapter in a card footer is enough — then:

  1. iPhone simulator, Light appearance.
  2. Fully quit the example app. A reload is not enough; Inter is already registered in that process.
  3. Cold launch. The heading looks regular, not bold.
  4. Wait a second so Inter can finish loading. Do not touch anything else.
  5. Toggle Dark with ⌘⇧A (Features → Toggle Appearance).

Labels clip. Flipping back to Light does not re-measure; the ellipsis stays.

Captured on iPhone 17 Pro simulator, 2026-09-04:

1. Light, cold start — labels intact

Light cold start: Share and Read chapter fully visible

2. Dark, after ⌘⇧A — Share → Sh…, Read chapter → Read chap…

Dark after theme flip: button labels ellipsized

3. Light again — ellipsis persists

Light again: ellipsis still present

Root cause

Text and Button.Text set fontFamily to the Inter_* aliases that expo-font registers at runtime, after first paint. iOS resolves an unknown family to the system font. Fabric's text measure cache (TextMeasureCache.h, areTextAttributesEquivalentLayoutWise) ignores color, so a color-only re-render reuses the system-font measurement while the draw path picks up the now-registered, wider Inter.

Fix

  • sansFace(family, weight, ready) in theme/fonts.ts returns { fontWeight } (system font, on purpose) until the faces register, then { fontFamily: fontMapKey(...) }. Changing fontFamily is a layout attribute, so native re-measures.
  • useBrandFonts now returns a "sans registered" boolean; YouVersionProvider publishes it through BrandFontsContext / useBrandFontsReady().
  • Text and Button.Text consume it. No public API change.
  • AGENTS.md gotcha updated so future primitives go through sansFace rather than a hand-written fontFamily / fontWeight.
  • Patch changeset for @youversion/platform-react-native-expo-ui.

Verification

  • pnpm typecheck, pnpm test, pnpm lint green.
  • iPhone 17 Pro simulator: cold light start shows Inter with bold headings and a 4-line verse; after flipping to dark, "Share" / "Read chapter" labels are intact and no verse lines are clipped.
  • Bug confirmed on main with the screenshots above.

Not in this PR

  • Android's measure cache was not traced. The fix is platform-neutral in principle, but it deserves its own device pass.
  • Bundling Inter through a config plugin so the swap never happens is a separate follow-up.

🤖 Generated with Claude Code

Greptile Summary

The PR prevents native text from rendering before bundled Inter faces register, ensuring text measurement and drawing use the same font.

  • Gates YouVersionProvider children on bundled sans-font readiness while loading serif fonts in the background.
  • Centralizes mapped Inter face selection through sansFace for Text and Button.Text.
  • Updates tests, contributor guidance, architecture documentation, and release notes for the new lifecycle.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/ui/src/theme/use-fonts.ts Separates blocking bundled-sans registration from background serif loading and exposes sans readiness to the provider.
packages/ui/src/native/youversion-provider.tsx Holds the native application subtree until bundled Inter registration completes.
packages/ui/src/theme/fonts.ts Adds the shared sansFace helper for selecting registered Inter aliases without fontWeight.
packages/ui/src/components/ui/text.tsx Maps text variants to registered regular and bold Inter faces through sansFace.
packages/ui/src/components/ui/button.tsx Routes button-label typography through the registered medium Inter face.

Sequence Diagram

sequenceDiagram
  participant App as Consumer app
  participant Provider as YouVersionProvider
  participant Fonts as expo-font
  participant UI as Native UI primitives
  Provider->>Fonts: Check bundled Inter faces
  alt Faces already registered
    Provider->>UI: Mount children
  else Faces not registered
    Provider->>Fonts: loadAsync(bundledSans)
    Fonts-->>Provider: Registration completes
    Provider->>UI: Mount children
  end
  UI->>UI: Resolve mapped face with sansFace
Loading

Reviews (5): Last reviewed commit: "fix(ui): keep Text caller style in the s..." | Re-trigger Greptile

Context used (3)

`Text` and `Button.Text` asked for the `Inter_*` faces that expo-font
registers at runtime, after first paint. Native falls back to the system
font for an unknown family, and Fabric's text measure cache compares
attributed strings layout-wise, so a color-only re-render (a theme flip)
kept the system-font measurement while the draw path picked up the wider,
now-registered Inter. Button labels ellipsized and paragraphs lost their
last line.

Draw the system font on purpose via `sansFace(family, weight, ready)`
until `useBrandFonts` reports the bundled sans faces registered, then
switch `fontFamily`, a layout attribute, so native re-measures.
`YouVersionProvider` publishes the flag through `BrandFontsContext`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Dustin-Kelley

Dustin-Kelley commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Tracking in YPE-5637. Assigned to Dustin.

posted by Cursor on behalf of Dustin

@Dustin-Kelley Dustin-Kelley changed the title fix(ui): draw the system font until the brand faces register fix(ui): draw the system font until the brand faces register (YPE-5637) Sep 4, 2026
Dustin-Kelley and others added 2 commits September 4, 2026 11:24
Anti-slop forbids unknown, typeof, and an anonymous return type on the helper.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Dustin-Kelley
Dustin-Kelley marked this pull request as ready for review September 4, 2026 16:29
@Dustin-Kelley Dustin-Kelley self-assigned this Sep 4, 2026
Dustin-Kelley and others added 2 commits September 8, 2026 09:06
The token ADR still told primitives never to use fontWeight. That would put Inter on the first frame again and bring the clip back.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cameronapak cameronapak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

Jira ticket: YPE-5637

Summary

  • Standards must-fix: 0
  • Spec must-fix: 0
  • Worst: none — system font until Inter registers, then family swap forces remeasure

Would approve on criteria. UI PR: no GitHub APPROVE — Cam looks at the repro screenshots (and the fix pass if you re-check on device).

For Agents: pin / CI
  • HEAD: d5578d15b7ca48ea49882d022940449bbc87847f
  • Fix: sansFace + BrandFontsContext / useBrandFontsReady; Text + Button.Text consume; serif load stays non-blocking
  • Tests: holdSansRegistration seam; Text/Button transition asserts
  • Docs: AGENTS gotcha + ADR 0021 amend; patch changeset
  • Out of scope (called out): Android device pass, Inter config-plugin bundling
  • CI: Lint/Typecheck/Build/Test/Locale parity/Locale JSON guard/Greptile Review pass
  • Greptile: 5/5
  • Event: COMMENT only (UI)

By Code Reviewer bot, sent on behalf of Cam.

@cameronapak cameronapak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

YPE-5637

Summary

  • Standards must-fix: 0 (prior pass)
  • Spec must-fix: 0 (prior pass)
  • Direction (Cam): Prefer awaiting Inter in the provider and deleting the ready/system-font path — do not keep two permanent font paths.
For Agents

Prior COMMENT on same HEAD: Spec 0 / Standards 0; UI → no APPROVE.
Cam + Simplifier joint: approach A — hold children until sans Font.loadAsync, then always Inter; delete BrandFontsContext / sansFace(ready=false) / hold-sans-registration.
Not C (ship dual-path). Native preload (B) later only if first-paint hold is unacceptable.
Event: COMMENT with Dustin instructions.

By Code Reviewer bot, sent on behalf of Cam.

@cameronapak

Copy link
Copy Markdown
Collaborator

Hi Dustin! I am an AI agent (even though this looks like Cam). Cam sent me to share research for this PR. I read the React Native source, the expo-font source, and the Expo docs. Each claim below links to its primary source.

Root cause, checked against the React Native source

The text measure cache lives in TextMeasureCache.h. The function areTextAttributesEquivalentLayoutWise compares fontFamily and fontWeight. It does not compare text color, and the source comment calls color a decorative aspect. So color exclusion is an intentional optimization, not the bug.

The bug is the cache key. The key stores the fontFamily string, not the resolved font. iOS measures Inter_500Medium in the system font before the face registers. The cache keeps that measurement under the same key after registration. A color-only re-render then reuses the stale box, and the draw path draws the real, wider Inter. This split matches the PR description.

The current fix removes the split in two steps. sansFace never writes a fontFamily before its face registers. The swap then changes fontFamily, which changes the cache key, which forces a fresh measure.

The readiness shape matches the expo-font source

FontHooks.ts shows the first-party useFonts hook. It sets the initial state with an isLoaded check for each face. It then calls loadAsync and sets its flag on completion. useBrandFonts uses the same shape. One flag per font group is a real difference, because useFonts gives one flag for the whole map.

Related bugs in React Native

  • #45857 is closed as completed. The fix, #45978, is merged. The fix tracks the font scale per node so that the cache dirties correctly.
  • #57512 is open. It reports the same stale-measure mechanism on RN 0.86 after a Dynamic Type change. The report says that Android is not affected.
  • #58176 is open. On RN 0.86.2, a PostScript fontFamily plus an explicit fontWeight resolves to the heaviest face. The cause is a typo in RCTFontUtils.mm.

One detail from #58176 helps this PR. A bare family name plus a weight resolves through a different code path, and that path stays correct. So do not set a PostScript fontFamily together with an explicit fontWeight. sansFace keeps these two style properties apart today.

How the ecosystem normally loads custom fonts

  • (a) Build-time embed. The expo-font config plugin links fonts into the native project. Expo ranks this method as recommended for apps, and the fonts work at app start. The plugin does not work in Expo Go.
  • (b) Runtime load plus a gate. The app loads fonts with useFonts and renders null until the load completes. The Expo docs show this pattern together with SplashScreen.preventAutoHideAsync. A library can apply the same gate at provider scope. The bundled sans faces read from the local bundle, so the gate does not touch the network.
  • (c) Fallback plus swap. The app draws the system font first and swaps fontFamily after registration. This is the native form of the web font-display: swap pattern. The FontDisplay constants of expo-font change web behavior only. On native, this pattern needs the cache discipline above.

All three patterns are standard. Pattern (b) at provider scope gives one font path and no font flash. The first paint of the SDK content then waits for the local sans load. Pattern (c) paints immediately, and it shows a brief system-font flash plus one reflow. The sources above support either direction.

Thanks for the clear problem statement and the repro. I hope these sources help the review talk.

References

@cameronapak

Copy link
Copy Markdown
Collaborator

Question I'm wrestling with... Is this the best way to solve this now?

AI Meat Proxy Response ✨

Yeah, so here's the deal in plain terms.

Dustin's fix works, but it's the complicated version. There are three ways to solve this, from simplest to fanciest:

1. Wait for the font, then show the screen. The app already ships with Inter in the bag. It loads in a blink because it's sitting right there on the phone, no internet needed. So the provider can just hold its content for that blink, then always use Inter. This deletes a ton of code: no font-readiness context, no two-way styling, no extra tests. Just "wait, then draw." It's also what Expo's own docs show as the normal way to do it if (!loaded && !error) { return null; }. The only cost: stuff inside the provider shows up a hair later on first launch. Nobody will notice.

2. Bake the font into the app at build time. This is the "real" fix. The font is there from frame one, so the whole problem disappears. But the app using the SDK has to opt into it and rebuild, and it breaks Expo Go Doesn't work with Expo Go since this method requires creating a development build. That's why it got pushed to a follow-up. Makes sense.

3. What the PR does now: draw with the default font first, swap to Inter when it's ready. It works everywhere with zero setup, which is nice. But it's the most code to maintain, and users see a quick font flash on first launch.

The cool part: option 1 and option 2 team up nicely. If a host app later bakes the font in, the little wait from option 1 just becomes instant, no code thrown away. So: do the simple wait now, bake the font in later if anyone ever complains.

And don't wait on React Native to fix the underlying bug. It's still open on the latest version. Both the wait and the swap dodge it fine. The wait just does it with way less code.

That matches what you already told Dustin on the PR, by the way. Your gut was right.

Dustin-Kelley and others added 3 commits September 8, 2026 12:38
Drop the system-font swap so native text always draws Inter after the provider opens.

Co-authored-by: Cursor <cursoragent@cursor.com>
Card titles read that slot for color; folding Inter into the variant layer restores it.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cameronapak cameronapak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks a lot simpler. If this works as you think, I approve!

@Dustin-Kelley
Dustin-Kelley merged commit 233dc86 into main Sep 8, 2026
8 checks passed
@Dustin-Kelley
Dustin-Kelley deleted the dk/font-fix branch September 8, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants