{{ message }}
fix: ensure colorSchemeObservable always updates to preserve manual o…#1776
Open
tonichiga wants to merge 1 commit intonativewind:v4from
Open
fix: ensure colorSchemeObservable always updates to preserve manual o…#1776tonichiga wants to merge 1 commit intonativewind:v4from
tonichiga wants to merge 1 commit intonativewind:v4from
Conversation
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.

fix(appearance): preserve manual colorScheme override in production builds
Summary
Fix
setColorScheme()not persisting after app reload (OTA update) on iOS when usingdarkMode: "class"in NativeWind.Problem
When a React Native app using NativeWind 4.x with
darkMode: "class"receives an OTA update and reloads, the manually set color scheme (e.g."dark") is silently discarded and the app falls back to the system appearance.Preconditions
Observed behavior
App reloads → displays light theme despite user preference being
"dark".Expected behavior
App reloads → displays dark theme as stored in user preferences.
Root Cause
appearance-observables.tsmaintains two separate observables:colorSchemeObservablecolorScheme.set()systemColorSchemeAppearance.addChangeListenerThe
colorScheme.get()method returnscolorSchemeObservable.get() ?? systemColorScheme.get().The bug:
colorScheme.set(value)calledAppearance.setColorScheme(value)(native side) but only updatedcolorSchemeObservableinside aNODE_ENV === "test"guard — meaning in production builds,colorSchemeObservablewas never set and always remainedundefined.The
get()fallback then always resolved tosystemColorScheme, which during OTA reload is briefly reset to the system value by theAppState "active"listener:Result:
colorSchemeObservable = undefined,systemColorScheme = "light"→ app renders in light mode.Why it worked on Android: Android does not fire an
AppState "active"transition during OTA JS reload the same way iOS does, sosystemColorSchemewas not reset at the wrong moment.Why timeouts didn't help: The issue is not a race condition —
colorSchemeObservablewas structurally never populated in production, regardless of timing.Fix
Remove the
NODE_ENV === "test"guard socolorSchemeObservableis always updated whencolorScheme.set()is called. This makes the manual override survive any subsequentsystemColorSchemechanges triggered byAppearanceorAppStateevents.Note:
"system"maps toundefined(not"light") so thatget()correctly falls through to the real-timesystemColorSchemeobservable instead of being hardcoded.Diff
Testing
darkMode: "media"configAffected versions
Reproduced on
react-native-css-interop@0.2.3. Likely present in all prior versions with the same guard.