Fix RCTAppearance setColorScheme crashing CarPlay apps (non-UIWindowScene guard) - #57876
Fix RCTAppearance setColorScheme crashing CarPlay apps (non-UIWindowScene guard)#57876SnowingFox wants to merge 1 commit into
Conversation
Summary: `RCTAppearance setColorScheme:` iterates `RCTSharedApplication().connectedScenes` and reads `scene.windows` on every scene, but `connectedScenes` can contain `UIScene` objects of any class. A CarPlay `CPTemplateApplicationScene` is a `UIScene` without a `windows` property, so the message send raises `-[CPTemplateApplicationScene windows]: unrecognized selector` and the app aborts whenever `Appearance.setColorScheme()` / `setUserInterfaceStyle()` is called. Guard each scene with `isKindOfClass:[UIWindowScene class]` before touching `.windows`, mirroring the existing pattern in `RCTUtils.mm`. Fixes react#57863. Changelog: [IOS] [FIXED] - RCTAppearance.setColorScheme() no longer crashes CarPlay apps with a non-UIWindowScene in connectedScenes Test Plan: No jest path (Objective-C, iOS-only; iOS cannot be built in this Linux environment). The added guard makes setColorScheme tolerate any non-UIWindowScene object by skipping it before the `.windows` message send. Verified by code inspection and it matches the reporter's production patch-package field-tested since 2026-08-02.
|
Hi @SnowingFox! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #57863
RCTAppearance setColorScheme:(also reached viaAppearance.setColorScheme()andsetUserInterfaceStyle) iteratesRCTSharedApplication().connectedScenesand readsscene.windowson every scene.connectedScenescontainsUISceneobjects of any class, and a CarPlayCPTemplateApplicationSceneis aUIScenethat does not implementwindows, so the message send raises-[CPTemplateApplicationScene windows]: unrecognized selectorand the app aborts.Fix: guard each scene with
isKindOfClass:[UIWindowScene class]and skip non-UIWindowSceneobjects before touching.windows, mirroring the existing pattern already used inRCTUtils.mm(if (![scene isKindOfClass:[UIWindowScene class]]) { continue; }).Note:
RCTDevMenu.mmshowOnShakehas the same unguardedfor (UIWindowScene *scene ...)loop and would crash identically in a CarPlay context; left untouched here to keep this fix minimal, but it should get the same guard.Changelog:
[IOS] [FIXED] - RCTAppearance.setColorScheme() no longer crashes CarPlay apps when connectedScenes contains a non-UIWindowScene
Test Plan:
No jest path exists for this code: it is Objective-C, iOS-only, and iOS cannot be built in the Linux environment this PR was developed in. Correctness is by code inspection.
Commands run (in the branch worktree):
git diff packages/react-native/React/CoreModules/RCTAppearance.mm— confirms the only change is the 3-line guard:for (UIWindowScene *scene in RCTSharedApplication().connectedScenes) { + if (![scene isKindOfClass:[UIWindowScene class]]) { + continue; + } [windows addObjectsFromArray:scene.windows]; }The guard makes
setColorSchemetolerate any non-UIWindowSceneobject inconnectedScenesby skipping it before the.windowsmessage send.isKindOfClass:is safe to send to anyUIScene(all areNSObject-derived), so the previously-crashing path is unreachable for CarPlay scenes.This matches the reporter's production
patch-packagefix that has been field-tested on-device since 2026-08-02.