Skip to content

fix(native): re-resolve a :root / fallback var() when an ancestor later provides it - #467

Open
huytdps13400 wants to merge 1 commit into
nativewind:mainfrom
huytdps13400:fix/var-guard-root-fallback
Open

huytdps13400 wants to merge 1 commit into
nativewind:mainfrom
huytdps13400:fix/var-guard-root-fallback

Conversation

@huytdps13400

Copy link
Copy Markdown

Fixes #377

Problem

varResolver (src/native/styles/variables.ts) only pushes a ["v", name, …] render guard when the variable is found in the inherited VariableContext. When the variable is absent from context and resolves from :root or from the var() fallback, no guard is recorded. testGuards therefore never notices when an ancestor later starts providing that variable (for example a VariableContextProvider whose 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. testGuards compares inheritedVariables[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 .test element under a VariableContextProvider with an empty value, then rerenders with --my-var provided:

  • :root { --my-var: red } with inlineVariables: false
  • var(--my-var, red) (fallback only)

Before the fix, both tests fail at the post-rerender assertion (color stays "red", expected "blue"). After the fix, both pass.

yarn build, yarn typecheck, yarn lint and yarn test all 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

…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

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

1 participant