Uh oh!
There was an error while loading. Please reload this page.
fix(theme): keep flat font properties in a mixed configureFonts config - #5066
Open
giaBaoJS wants to merge 1 commit into
Open
fix(theme): keep flat font properties in a mixed configureFonts config#5066giaBaoJS wants to merge 1 commit into
giaBaoJS wants to merge 1 commit into
Conversation
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 freeto 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.
The bug
configureFontsConfigclassifies the config as a whole:A config may legitimately contain both shapes at once — a font property that should apply to every variant, plus a tweak to one variant. A single per-variant object flips
isFlatConfigtofalsefor the whole config, and theObject.assignbranch below then spreads every top-level entry as if it were a variant.Repro:
Two things go wrong:
fontFamilyis silently dropped from every variant —bodyLarge.fontFamilyis still"System".No error, no warning. From the app's point of view the custom font just does not apply.
The same shape is also rejected by the type overloads today, so a TS user gets
TS2769: No overload matches this calland has to callconfigureFontstwice or hand-build the object.The fix
Partition
Object.entries(config)into scalar entries (shared font properties) and object entries (per-variant overrides), instead of classifying the config as a whole. Build every variant as{ ...typescale[variant], ...sharedProperties, ...variantOverrides[variant] }.The two previous branches are special cases of this, so the
isFlatConfigearly return and theObject.assignboth go away:variantOverridesis empty → every variant gets the scalars (old flat branch)sharedPropertiesis empty → named variants are merged, others untouched (old per-variant branch)I also added a third overload for the mixed shape:
It is placed after the two existing
Partialoverloads and before theRecord<string, TypescaleStyle>one. Neither existing overload accepts a mixed literal (each rejects the other's keys as excess properties), and the custom-variant overload does not either, so this signature only picks up calls that previously failed to compile — existing call sites keep resolving to the overload they resolved to before. I verified both directions: the mixed literal isTS2769onmainand clean with this change, while the flat-only and per-variant-only literals compile on both.About #4589
I could not reproduce the reporter's
Variant titleLarge was not provided properlyfrom this bug, and I don't think this closes it — the warning there listsregular, medium, light, thin, i.e. an MD2-shapedfontsobject, which is a different path entirely. Listing it as possibly related only, deliberately notFixes.Test plan
Two cases added to
src/theme/__tests__/fonts.test.js:Before the change both fail; the second reports
Received: {"0": "N", "1": "o", "2": "t", "3": "o", "4": "S", "5": "a", "6": "n", "7": "s"}. The four existingconfigureFontstests pass unchanged, before and after.yarn test: 55 suites, 737 passed / 1 skipped, 169 snapshots — no snapshot churn.yarn lintandyarn typecheckclean.