Skip to content

fix(ui): BibleCard, VerseOfTheDay - keep SDK components from shifting while they load - #515

Open
cameronapak wants to merge 12 commits into
mainfrom
fix/ui-layout-shift
Open

cameronapak wants to merge 12 commits into
mainfrom
fix/ui-layout-shift

Conversation

@cameronapak

@cameronapak cameronapak commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Jira: YPE-6878

New here? Start here

What's this? Several SDK UI components change size after they first appear on screen, which pushes everything below them around while a page loads. VerseOfTheDay (VOTD) and BibleCard grow from a small spinner to the full verse, BibleCard's version button widens when its abbreviation arrives, the Bible Reader's title line grows when book data arrives, and text reflows when the web fonts (Inter and Untitled Serif) replace the fallback font. This PR makes each of them reserve about their final size before the content arrives. It also makes BibleCard and VOTD hold up with long text, zoom, touch, and reduced motion.

Why does it matter? Content that jumps while it loads is hard to read and easy to mis-tap, because buttons move under the user's finger. On a throttled phone, the Reader's text jumped about 26px down and back up as fonts loaded, and VOTD pushed the content below it down by up to 177px.

Who does it affect? People using any app that renders these components, most noticeably on phones and slow connections. Integrators don't need to change anything: there are no API or prop changes.

What happens if we leave this as-is? The jumps continue. Host apps such as the web sample (#514) keep a stopgap that reserves a fixed height around these components.

Before / after

Measured in examples/vite-react with the live API: Slow 4G, cache disabled, and 4× CPU throttling at 390px. Each component renders by itself with a gray block below it. Before is main (919a8a4), after is this branch. Red boxes mark elements the browser reported as shifted.

VOTD, typical verse (James 1:19, 107 characters), 390px: before, both cards grow from a spinner and push the gray block down in steps. After, the cards open at their loaded height and nothing moves. (MP4)

VOTD loading at 390px, before (left) and after (right)

BibleCard (John 3:16), 390px: before, the card grows from a spinner and the version button widens. After, the card opens at about its loaded height and the button keeps its width. (MP4)

BibleCard loading at 390px, before (left) and after (right)

Bible Reader, 390px: before, the text drops when the book title arrives, then jumps again when the web fonts replace the fallbacks. After, the title line holds its height and paragraphs keep their size through the font swap. (MP4)

Bible Reader loading at 390px, before (left) and after (right)

Cumulative layout shift (CLS) while loading, where lower is better and 0 means nothing moved:

Component Width Before (main) After
VOTD, typical verse (day 208, James 1:19) 390px / 1440px 0.096 / 0.010 0 / 0
VOTD, long verse (day 37, Hebrews 12:1, 198 characters) 390px / 1440px 0.220 / 0.025 0.108 / 0.010
VOTD, short verse (today, Philippians 1:21, 49 characters) 390px / 1440px 0.046 / 0.006 0.043 / 0.009
BibleCard, John 3:16 390px / 1440px 0.019 / 0.001 0.004 / <0.001
Bible Reader, John 1 390px / 1440px 0.365 / 0.156 0.020 / 0.005

The loading state reserves the space of a median-length verse, so verses much shorter or longer than that still move a little when they arrive. The short-verse row shrinks instead of growing, which is why it barely changes.

BibleCard with worst-case data, 320px: before, a long reference squeezes beside the version button, and a copyright with a bare URL pushes the Bible App logo out of the card ("Bible A"). After, the version button wraps under the reference, words stay whole, and long copyrights span the card with the logo underneath.

BibleCard with long references and copyrights at 320px, before (left) and after (right)

BibleCard with long copyrights, 1440px: a copyright longer than about four lines beside the logo now spans the card with the logo underneath. A 4-line copyright keeps the logo beside it.

BibleCard copyrights at 1440px, before (left) and after (right)

VOTD at 200% zoom, 390px phone: before, the eyebrow is clipped to "VERSE OF THE…" and the share button is pushed out of the card. After, the sun icon and share button share the top row, and the eyebrow and reference take the full width below with words kept whole.

VOTD at 200% zoom, before (left) and after (right)

What changed

Loading without layout shift

  • Cards reserve a typical verse. New internal BibleTextPlaceholder renders about 100 characters of invisible text, the median VOTD length (40 days sampled: p25 80, median 104, p75 145 characters). It uses the passage's own font, size, line height, and .p paragraph margin, with the spinner centered over it. It wraps at the card's real width, so it reserves the right height on phones and desktops. BibleCard and VOTD use it in place of the bare spinner.
  • VOTD keeps the reference and copyright lines while loading. Both lines hold their place with an empty line, so the card doesn't grow when they arrive.
  • BibleCard header and footer. The header spinner sits in a box as tall as the reference. The version button's label sits in a min-w-[3ch] box, the pattern the Reader toolbar already uses, so the button keeps about its loaded width. The 8px copyright now uses leading-[1.2] instead of inheriting 24px lines, so a two-line copyright no longer makes the footer taller than the logo.
  • Reader book title. The loading spinner sits inline in the title's line instead of as a 24px block, so the line keeps its height when the title arrives.
  • Metric-matched font fallbacks. yv-fonts.tsx declares YV Inter Fallback (local Arial or Liberation Sans) and YV Untitled Serif Fallback (local Times New Roman or Liberation Serif). Their size-adjust and ascent and descent overrides were generated from the real font files with Capsize, for each weight the SDK renders (400, 500, 700). So text takes the same space before and after the web font arrives. No font files are added; these rules only resize fonts already on the device.
    • The faces are installed in the owning document through the existing font helpers, because shadow roots ignore @font-face.
    • The Untitled Serif fallback is declared only when the gated brand font is requested. If its stylesheet or font fails, the fallback is removed so Source Serif 4 renders, as ADR 0004 documents.
    • --yv-font-sans and --yv-font-serif (core theme.css, ui global.css, chrome.css) and the Reader's rendered font stack include the fallbacks. Persisted Reader font values are unchanged.

Worst-case data and zoom

  • BibleCard header. The reference and version button wrap onto two lines when the reference's longest word doesn't fit beside the button. Only a word wider than the whole card breaks. The reference and abbreviation share one <bdi>, so in right-to-left Scripture the abbreviation follows the reference.
  • BibleCard footer. The copyright's flex basis is about the width it needs for four lines (length × 0.75ch ÷ 4; an average copyright character measured 0.75ch). When that and the logo don't fit side by side, the logo wraps underneath. This is plain CSS, so it renders the same on the server and doesn't shift. Copyrights can break inside a bare URL, so the logo stays in the card. We considered pretext for exact line counts. It adds about 39 KB gzipped, and it doesn't model the text-wrap: balance the copyright uses.
  • VOTD header. The eyebrow wraps instead of clipping, and the share button can't shrink or leave the card. In a narrow card (content under 13rem, such as 200% zoom on a phone), a container query moves the eyebrow and reference to a full-width row below the icon and share button. The reference breaks only a word wider than the whole card.
  • AnimatedHeight clips only vertically, so horizontal overflow such as focus rings isn't cut off.

Touch and motion

  • Scripture in cards can be selected and long-pressed (user-select: text, default touch callout). The Reader keeps its own selection behavior.
  • Buttons use touch-manipulation, which removes the double-tap zoom delay. The cards' share and version buttons press down to scale(0.97) on touch.
  • Button transitions only color, background, border, shadow, opacity, scale, and transform, not all, over 150ms on cubic-bezier(0.23, 1, 0.32, 1). The press effect runs only under motion-safe.
  • AnimatedHeight runs 200ms on the same curve. Popovers open in 150ms and close in 100ms. With reduced motion they only fade, with no zoom or slide. The search popover now does the same instead of dropping its animation entirely.
  • packages/ui/AGENTS.md documents the motion guidance: prefer transform and opacity, allow short height reveals such as AnimatedHeight that turn off under reduced motion, and keep fades under reduced motion. On Slow 4G with 4× CPU, AnimatedHeight scored lower CLS than an instant snap in every case measured.

Known limits

  • Verses much longer or shorter than the median still move when they load (see the table). Reserving the exact height would need the verse's length before it arrives.
  • In the Reader, words still re-wrap inside paragraphs during the font swap, but paragraphs keep their size. The chapter digit still changes by about 2px, because Inter's tabular figures are wider than Arial's.
  • Tap delay, long-press selection, and the touch callout were checked through computed styles in desktop Chromium, not on a real phone.

Verification

  • Unit tests (pnpm --filter @youversion/platform-react-ui exec vitest run --project unit): 687 passed. New: the Untitled Serif fallback is removed when the gated stylesheet fails, and later mounts don't reinstall it.
  • Storybook browser tests (--project storybook): 136 passed.
    • New BibleCard story LoadingReservesTypicalHeight holds a typical passage (Isaiah 40:31) while it measures the loading card at 358px and 700px. It checks that the loaded card is within one passage line of the loading card. It fails when the placeholder is shortened (71px off) or loses its paragraph margin (29px off).
    • LoadsSavedPreferencesFromLocalStorage now expects the rendered stack with the fallback, while the persisted value stays UNTITLED_SERIF_FONT.
  • oxlint, Prettier, tsc, size-limit, and the UI build's style verification pass.
  • Layout shift was measured with a throttled Playwright script in the sample app (table above). Worst-case data was rendered at 320px, 390px, 200% zoom, and 1440px, with no overflow out of the cards. The VOTD stories also pass in WebKit.
  • Changeset: steady-loading-layout.md, patch for @youversion/platform-core and @youversion/platform-react-ui.

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge; the previous font cleanup issue is fixed.

Summary

This PR reserves loading space for Bible cards and improves font fallbacks, narrow layouts, touch behavior, and reduced motion.

  • Loading cards and the Reader title hold their space more steadily.
  • Long references and copyrights stay inside BibleCard and Verse of the Day.
  • Text keeps closer to its size as Inter and Untitled Serif load.
  • Buttons and popovers respond to touch and reduced-motion settings.

Reviews (4) · Last reviewed commit: "fix(ui): keep base fonts when the brand ..." · Reviewed by Greptile

Comment thread packages/ui/src/lib/yv-fonts.tsx Resolved
@cameronapak
cameronapak marked this pull request as draft December 3, 2026 17:20
BibleCard and VerseOfTheDay reserve the height of a typical verse while the
passage loads, BibleCard's version button and the Reader's book title keep
their loaded size, and Inter and Untitled Serif get metric-matched local
fallbacks generated from the real font files, so the font swap does not move
text.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
@changeset-bot

changeset-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c69d034

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

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-core Patch
@youversion/platform-react-ui Patch
@youversion/platform-react-hooks Patch
vite-react 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

Found with break-ui using real versions: a copyright with a bare URL pushed
BibleCard's logo out of the card at 320px; at 200% zoom the version button
and VOTD share button left their cards; the VOTD eyebrow clamped to "VER…";
right-to-left references put the abbreviation first; and AnimatedHeight
clipped glyph overhang horizontally.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
The copyright line added in #518 appeared at full height when the verse
arrived, outside AnimatedHeight, so content below jumped 24px at once
(CLS 0.049 at 390px on Slow 4G). Keeping one empty line in its place while
loading brings that to 0.014, the remaining difference being the verse's
own length versus the typical-verse reservation.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
From mobile-native: Scripture in cards (data-selectable=false) was
user-select: none with the touch callout disabled, so readers could not
long-press to copy a verse; the Reader, where taps select verses, keeps
that behavior. SDK buttons and the footnote marker get
touch-action: manipulation so taps fire without the double-tap delay, and
the card share and version buttons press down on touch.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
From review-animations:
- Button transitioned `all` on the default ease; it now transitions only
  color, background, border, shadow, opacity, scale, and transform over
  150ms on a strong ease-out. Tailwind v4 scale utilities set `scale`,
  so the card press feedback now actually animates.
- Press feedback is motion-safe only.
- AnimatedHeight drops from 300ms ease-out to 200ms on the same strong
  curve; with the loading reservation it only covers the remaining
  difference.
- Popovers keep their trigger origin and 150ms, on the strong curve; with
  reduced motion they fade without zooming or sliding.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
From emil-design-eng: the version picker popover opened and closed in
150ms. Closing is the system responding, so it now takes 100ms; opening
keeps 150ms. Also updates the changeset for this PR's later fixes.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
The metric-matched Times fallback sits before Source Serif 4 in the serif
stack, so a failed gated stylesheet or font left readers on Times. Remove
the fallback when the brand font fails and keep later mounts from
reinstalling it.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
…yrights

The loading placeholder now sits in a .p paragraph like the passage, so it
gets the same indent and bottom margin, and the copyright uses a 1.2 line
height instead of inheriting 24px lines. A new story holds the passage
request and checks that a typical verse loads within one line of the
reserved height at phone and desktop widths.

A copyright longer than about four lines beside the logo now takes the full
width with the logo underneath, so it is not squeezed into a narrow column.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
…ce words

overflow-wrap:anywhere let the reference shrink below its longest word, so
at 320px the version button stayed beside it and words split mid-word
(THESSALONIAN/ME). The reference now keeps its longest word's width, capped
at the row, so the button wraps underneath; only a word wider than the
whole card breaks.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
At 200% zoom on a phone, the reference had about 80px between the sun icon
and the share button, so overflow-wrap:anywhere split words mid-word. When
the card content is under 13rem, the icon and share button now share the
top row and the eyebrow and reference take the full width below. The
reference breaks only words wider than the whole card.
@cameronapak
cameronapak marked this pull request as ready for review December 4, 2026 12:51
@cameronapak cameronapak self-assigned this Dec 4, 2026
Comment thread packages/ui/src/lib/yv-fonts.tsx Resolved
The search popover dropped its animation entirely under reduced motion, so
it popped in and out. The shared popover already removes zoom and slide
under reduced motion and keeps the fade, so the override is removed.

Document the motion guidance in packages/ui/AGENTS.md: prefer transform and
opacity, allow short height reveals such as AnimatedHeight that turn off
under reduced motion, and keep fades under reduced motion. Measured on Slow
4G with 4x CPU, AnimatedHeight scored lower CLS than an instant snap in
every case.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
React merges style resources that share a precedence into one tag. The
server-rendered Untitled Serif fallback shared yv-sdk-fonts with the base
fonts, so when the brand font failed, removeBrandFontFallback deleted the
merged tag, including the Google Fonts import and the Inter fallback. Give
the brand fallback its own precedence so only its rules are removed.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23831-2d77-77fd-9e5e-e91ef59406bf
@cameronapak cameronapak changed the title fix(ui): keep SDK components from shifting while they load fix(ui): BibleCard, VerseOfTheDay - keep SDK components from shifting while they load Dec 4, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants