fix(native): re-resolve a :root / fallback var() when an ancestor later provides it - #467
Open
huytdps13400 wants to merge 1 commit into
Open
huytdps13400 wants to merge 1 commit into
huytdps13400 wants to merge 1 commit into
Conversation
…er provides it varResolver only recorded a render guard when the variable was found in the inherited VariableContext. When it was absent and resolved from :root or the var() fallback, no guard was recorded, so a mounted component kept that value after an ancestor (e.g. VariableContextProvider) started providing the variable. Record an absence guard before the :root / fallback lookups so testGuards re-resolves the styles when the variable appears in context. Fixes nativewind#377 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #377
Problem
varResolver(src/native/styles/variables.ts) only pushes a["v", name, …]render guard when the variable is found in the inheritedVariableContext. When the variable is absent from context and resolves from:rootor from thevar()fallback, no guard is recorded.testGuardstherefore never notices when an ancestor later starts providing that variable (for example aVariableContextProviderwhose value updates), and the mounted component keeps the:root/ fallback value.Change
Push an absence guard (
["v", name, undefined]) just before the:root/ fallback lookups.testGuardscomparesinheritedVariables[name] !== undefined, so it only fires on the absent → present transition. After that re-resolve the variable is in context and the existing guard takes over. The inline and universal-selector paths still return before this point, so they don't change.Verification
Added two tests to
src/__tests__/native/variables.test.tsx. Each one mounts a.testelement under aVariableContextProviderwith an empty value, then rerenders with--my-varprovided::root { --my-var: red }withinlineVariables: falsevar(--my-var, red)(fallback only)Before the fix, both tests fail at the post-rerender assertion (
colorstays"red", expected"blue"). After the fix, both pass.yarn build,yarn typecheck,yarn lintandyarn testall pass (81 suites, 1337 tests).Platforms: native runtime (iOS/Android). The web runtime isn't affected.
This fix was prepared with AI assistance (Claude Code) and verified locally with the tests above.
🤖 Generated with Claude Code