Repository navigation
fix: own the color scheme union, so the package compiles on react-native 0.81 - #429
YevheniiKotyrlo wants to merge 1 commit into
Conversation
|
Outdated: this compared the August heads of #415 and #429. #415 is now re-written onto The original noteCross-referencing #415 and #429 — they merge with zero conflicts and the result does not compile. Flagging it now, because nothing will warn whoever lands the second one.
The two halves are each correct alone:
On the merge, #429's wider union reaches a call react-native 0.81 types as Neither PR can pre-empt this, which is why it is a note rather than a fix on one of them. #415 cannot import The resolution is one line at merge time: route the native setter through the same seam the web one already uses, rather than calling // src/native/api.tsx
import { setAppearanceColorScheme } from "../color-scheme";
…
setAppearanceColorScheme(value); // instead of Appearance.setColorScheme(value)Measured: that takes the merged tree from one error to zero. The seam exists precisely because the one member the supported react-native range declares incompatibly is the "follow the system" write, so this is what it was built for. Worth pairing with a compile-level guard, since the failure is a type error rather than a behaviour: the merged tree must typecheck. A runtime twin already exists on #429 at |
…tarts at These comments say 0.86 in four places. Measured across every react-native in the Yarn cache, the break starts at 0.82.0 — four minor versions earlier: 0.81.2 / 0.81.4 / 0.81.5 ColorSchemeName = 'light' | 'dark' | null | undefined 0.82.0 … 0.86.0 ColorSchemeName = 'light' | 'dark' | 'unspecified' The runtime moves in the same release. 0.81.5 coerces the nullish request — `NativeAppearance.setColorScheme(colorScheme ?? 'unspecified')` — and 0.82.0 passes the argument through verbatim. nativewind#429 already names 0.82 on its own surface, so left alone the two branches would land in one tree disagreeing about one boundary. The cache-write sentence gets rewritten rather than renumbered, because the range has three states and not two: before 0.82 the cache is a read-back of the native module, from 0.82 it is the requested value, and later in the range `"unspecified"` is resolved against the OS before being stored. Scoping the sentence to a RESOLVED scheme collapses the last two — the only value they disagree about is `"unspecified"`, which is exactly the value the guard below declines to announce — and it keeps the comment from naming a boundary this measurement cannot place: the cache holds 0.84.1 and 0.85.3 but not 0.85.0 through 0.85.2, so the second transition is bounded only to (0.84.1, 0.85.3]. Comments only; no behaviour changes. `reactivity.ts:229` is left alone — "the request 0.81 spells `null`" is a statement about 0.81 and is correct.
|
Outdated: this compared the August heads of #415 and #429. #415 is now re-written onto The original noteFollowing up on the cross-reference above with two measured additions, one of which is a trap worth naming explicitly. An inline cast at the call site compiles, and is the wrong resolutionThe obvious shortcut for the merge break is to widen the argument in place rather than route through the seam: Appearance.setColorScheme(value as Parameters<typeof Appearance.setColorScheme>[0]);That does take the merged tree to zero type errors, on both react-native ends of the peer range. It is still wrong, because it silences both arms of a union that disagrees for a reason: Up to 0.81.5 a nullish request is coerced to That is the failure #415's own comment forbids in the same function: "Announcing it would put a value in Appearance's cache that no reader can render." The boundary is 0.82.0, not 0.86Measured across every react-native in the Yarn cache, by extracting The type narrowing and the loss of the One nuance worth recording for whoever touches this next, because it is easy to collapse into the same number: there is a third state later in the range, where A latent one, for #415#415's three new colour-scheme test files do not type-check against ≥0.82 — |
…ive 0.81 react-native changes ColorSchemeName inside the peer range: 0.81 declares "light" | "dark" | null | undefined, and 0.82 and later "light" | "dark" | "unspecified". The jest helper and the web colorScheme pass "unspecified" to Appearance.setColorScheme, which 0.81's declaration rejects. The package owns its ColorSchemeName union, and setAppearanceColorScheme writes light and dark as every version declares them and restates the declaration for "unspecified", which every version hands to the native module.
8189bb6 to
4e1bcc4
Compare
Problem
peerDependenciessaysreact-native: ">=0.81", but the package does not compile on 0.81.src/jest/index.tscallsAppearance.setColorScheme("unspecified")and the webcolorScheme.setpassesname ?? "unspecified", while react-native 0.81 declaressetColorScheme(scheme: ColorSchemeName | null | undefined)withColorSchemeName = 'light' | 'dark' | null | undefined(0.81.4'sAppearance.d.ts):0.82 and later declare
'light' | 'dark' | 'unspecified'and rejectnull, so no one literal for "follow the system" type-checks on both. At runtime every version hands"unspecified"to the native module for that state, since 0.81 mapsnullto it.Solution
src/runtime.types.tsownsColorSchemeName,"light" | "dark" | "unspecified" | null | undefined, rather than re-exporting react-native's, whose meaning changes inside the peer range.colorSchemeandsrc/native/reactivity.tsuse it.setAppearanceColorScheme(src/color-scheme.ts) writeslightanddarkas every version declares them, and restates the declaration for"unspecified"alone. The jest helper and the webcolorScheme.setcall it.Tests
src/__tests__/native/color-scheme.test.tsx: each oflight,dark,unspecified,nullandundefinedreaches the native module as the scheme every version expects, andprefers-color-schemefollows the scheme and releases on"unspecified".Verification
On Windows with Node 26:
yarn typecheckclean against the repository's react-native; against react-native 0.81.4'sAppearancedeclaration,main's call fails as above andsetAppearanceColorSchemecompiles;yarn lintclean on the changed files;yarn test1347 passed.