Repository navigation
fix(types): type CSS custom properties against what both platforms honour - #423
Open
YevheniiKotyrlo wants to merge 4 commits into
Open
YevheniiKotyrlo wants to merge 4 commits into
YevheniiKotyrlo wants to merge 4 commits into
Conversation
This was referenced Aug 15, 2026
Contributor
Author
vars() and <VariableContextProvider /> mapped every entry of the record they are given into the runtime's variable record, so an entry whose value is undefined planted a key holding undefined. Variable lookup is presence-keyed, so that key read as "set to nothing" and stopped the cascade before the inherited value, the :root value and the var() fallback. Both channels now build the record through toVariableRecord, which strips the -- prefix and skips an entry with no value, the invariant the compiler already holds. "unset" remains how a variable is deliberately cleared.
…nour vars() and VariableContextProvider were typed Record<string, string | number> on web and Record<string, StyleDescriptor> on native, and a consumer only sees the web declarations, since the root entry's types re-export ./web. A font-family list or an undefined entry was a type error though native takes both, while StyleDescriptor admits var() tuples and null that web cannot serialise: web's vars() threw on undefined and null, and its provider passed raw values into the style. CustomPropertyValue is the set both platforms honour: a string, a number, a boolean, undefined, or an array of those, which is a comma-separated list. Both platforms type vars() and VariableContextProvider with it, and web serialises through one function that leaves an undefined value unset. A type-level fixture holds the three entries to one type, and the README shows the provider by its current name.
YevheniiKotyrlo
force-pushed
the
fix/vars-descriptor-types
branch
from
October 11, 2026 12:35
151b46c to
84c1f23
Compare
This was referenced Oct 11, 2026
The case compiled with the default options, so the compiler inlined the class's --color into the rule reading it and the result never depended on how the runtime treats an undefined entry. It now keeps the variable, so the class's value reaches the element only because an undefined entry plants no key, and writes the colour as a hex with no name, so both paths serialise it alike.
YevheniiKotyrlo
marked this pull request as draft
October 16, 2026 17:50
YevheniiKotyrlo
marked this pull request as ready for review
October 16, 2026 18:10
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.


Problem
vars()and<VariableContextProvider />are typed twice, and neither type is the set of values both implementations honour:Record<string, string | number>.Record<string, StyleDescriptor>.A consumer only ever sees the web types, because the root entry's declarations re-export
./weband nothing selects the native ones.vars({ "--font-stack": ["Inter", "Helvetica"] })andvars({ "--color": undefined })are type errors, though native honours both. Insrc/__tests__/native/vars.test.tsx, jest resolves the native runtime andtscthe web types, so the same file passes under one and fails under the other.StyleDescriptoradmitsundefined,nulland the compiler'svar()tuples. Onmain, web'svars()throws onundefinedandnull, and stringifies a tuple as[object Object],var,y.<div>'s style.Solution
CustomPropertyValueis the set both platforms honour: a string, a number, a boolean,undefined, or an array of those, which is a comma-separated list.vars()andVariableContextProviderwith it.undefinedvalue unset and drops anundefinedlist member.Tests
src/__tests__/_custom-property-value.types.tsis type-level and runs underyarn typecheck:null, an object, avar()tuple and the wholeStyleDescriptorare rejected.src/__tests__/web/variables.test.tsx: web serialisation of lists, booleans andundefined, throughvars()and the provider.src/__tests__/native/vars.test.tsx: a list and anundefinedvalue reach the native runtime as typed. Theundefinedcase keeps its variable (inlineVariables: false), so the class's value reaches the element only because anundefinedentry plants no key.main, 4 of the 5 web cases fail, and the native cases fail undertsc. Each of 4 mutations fails its own cases, and addingnullto the type fails the typecheck.Verification
On Ubuntu with the workflow's steps - build, lint, typecheck,
yarn test,node --test node/__tests__/*.mjs, both library builds, the web export, the unstaged-changes checks and commitlint - everything passes.Device evidence, before and after: #423 (comment)
Merge order
This carries #431, which makes an
undefinedentry plant no key on native — the native half of what this type promises — so #431 lands first.It also shares lines with #412 (
__tests__/native/vars.test.tsx,native-internal/variables.tsx), #443 (__tests__/native/vars.test.tsx), #469 (__tests__/native/vars.test.tsx); whichever lands second rebases.Base
Re-written on
main(a5002c5), where nativevars()declares itsViewStylereturn, which this keeps.