-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(provider): deep merge theme prop so a partial theme keeps defaults #5047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giaBaoJS
wants to merge
2
commits into
callstack:main
Choose a base branch
from
giaBaoJS:fix/paper-provider-partial-theme-merge-4589
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+285
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling
safeMergeat the theme root can drop all defaults when a custom theme containsdynamic,semanticorresource_pathscurrent sentinel check treats any object containing one of these keys as a native color, while custom theme properties are supported
RN’s actual native-color values have narrower shapes, such as
{ semantic: string[] }or{ dynamic: { light, dark } }(source)so could we validate those shapes before using
safeMergehere & add regression test for customdynamicproperty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — you're right, and this is a real regression introduced by moving
safeMergeto the theme root. Fixed in 25363ae.Reproduced first:
safeMerge(base, { dynamic: true })returned{ dynamic: true }, and<PaperProvider theme={{ dynamic: true }}>made<Text variant="titleLarge">throw again — the exact symptom this PR set out to fix.isPlatformColorSentinelnow validates the value, not just the key name. Checking the shapes React Native actually emits (PlatformColorValueTypes.ios.jsL25-28 and L37-50,PlatformColorValueTypes.android.jsL19-23), a native color value carries exactly one key and nothing else, so the check now accepts only:{ semantic: string[] }— iOSPlatformColor{ resource_paths: string[] }— AndroidPlatformColor{ dynamic: { light, dark, highContrastLight?, highContrastDark? } }—DynamicColorIOS, requiring bothlightanddarkand rejecting any key outside that tupleEverything else — including
{ dynamic: true },{ semantic: 'label' }, and any object that carries a sentinel key alongside siblings such ascolors/fonts— is now an ordinary object and gets deep-merged, so a documented custom theme property calleddynamickeeps every default.Regression tests added, as requested:
PaperProvider.test.tsx: a theme{ dynamic: true, colors: { primary: 'tomato' } }keeps the typescale, palette and shape tokens, plus a user-visible one asserting<Text variant="titleLarge">renders undertheme={{ dynamic: true }}.provider.test.ts: rejection cases for the three key names with wrong-shaped values and with sibling keys.Two of the new tests are deliberately non-vacuous controls that pass both before and after, so the tightening can't quietly degenerate into "nothing is ever a sentinel": one asserts real
PlatformColor('label')andDynamicColorIOS(...)values are still detected, and one asserts a realDynamicColorIOSoverride still passes throughsafeMergeby identity, with nohighContrast*keys inherited from the base sentinel underneath it. With the sentinel change reverted the six new tests fail and those two still pass.Suite: 55 suites / 737 → 745 passed / 1 skipped, 169 snapshots unchanged; lint and typecheck clean.