feat(card): fit displayName by length across live card + Satori render#75
Open
rgarciar1931 wants to merge 1 commit into
Open
feat(card): fit displayName by length across live card + Satori render#75rgarciar1931 wants to merge 1 commit into
rgarciar1931 wants to merge 1 commit into
Conversation
Long GitHub display names (e.g. unbroken uppercase tokens like "ABCDEFGHIJKLMNOPQRS", 19+ chars) overflowed the FUT card's visible band at the previous fixed 13cqw font-size. Add a pure length-aware getFitFontSize(displayName) step function in lib/text.ts (cqw: 13 → 11.5 → 10 → 9 → 8.2 → 7.5, keyed on the already-uppercased display-name length). Replace the PlayerCard name wrapper's left:50% + translateX(-50%) layout with a width:100% + text-align:center outer div carrying an inner display:inline-block span that reads the helper, and consume the same helper from the Satori OG render in lib/og/renderCard.tsx so the export and OG image are visually identical to the screen without DOM measurement on the server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a length-aware font-size step so long GitHub display names stay inside the FUT card's visible name band, and keep the Satori OG render visually identical to the live card.
Problem
Long GitHub display names — unbroken uppercase tokens like
VERY-LONG-USERNAME, all-caps surnames with no separator, or single-token logins >16 chars — overflowed the FUT card's centered name slot at the previous fixed13cqwfont-size. They bled past the under-name separator (H_LINES[2]) on either side and clipped off the card's edge.What changed
lib/text.ts— addedgetFitFontSize(displayName: string): number, a pure step function keyed on the already-uppercased display-name length:≤10 chars → 13 cqw≤13 → 11.5 cqw≤16 → 10 cqw≤19 → 9 cqw≤22 → 8.2 cqw>22 → 7.5 cqwCo-located next to
cardDisplayNameso the helper is shared between the React tree and Satori.components/PlayerCard.tsx— name wrapper swapped fromleft: 50% + translateX(-50%)(single text node) toleft: 0; width: 100%; text-align: center(block wrapper containing an innerdisplay: inline-block; white-space: nowrapspan that reads the helper). Visual position is identical; the text now scales with length bracket.lib/og/renderCard.tsx— samecqw(getFitFontSize(displayName))inside the existing flex-centered outer div so the Satori OG image matches the live card byte-for-byte without DOM measurement on the server.tests/text.test.ts(new) — boundary cases (≤10/≤13/≤16/≤19/≤22/>22) plus a monotonicity check, and a regression forcardDisplayName.Why a step function (not
ResizeObserver+scrollWidthmeasurement)Two reasons collide:
displayNameand produces the same font-size on every render path.useLayoutEffectmeasure-and-fit would change the rendered font-size between SSR and CSR (the SSR HTML would have the un-measured size until the effect runs), triggering React's hydration mismatch warning on the card's displayName text node. The step function gives identical output on both sides.Visual comparison
13cqw): bleeds past the under-name separator on either side, clipping the edge of the card.Validation
npm run lint— clean (12 warnings, 0 errors — same baseline asmaster).npm test— all tests pass onfeat/fit-card-namestipd16a548.Example