Skip to content

Align nullable types across Appearance API (#56687)#56687

Open
huntie wants to merge 2 commits intofacebook:mainfrom
huntie:export-D103865622
Open

Align nullable types across Appearance API (#56687)#56687
huntie wants to merge 2 commits intofacebook:mainfrom
huntie:export-D103865622

Conversation

@huntie
Copy link
Copy Markdown
Member

@huntie huntie commented May 5, 2026

Summary:
Simplify and align nullable values in the Appearance API.

API Flow / Strict TS API Manual .d.ts
getColorScheme() ColorSchemeName | null (narrowed) ColorSchemeName | null
useColorScheme() ColorSchemeName | null (narrowed) ColorSchemeName | null (fixed)

At the native spec level, nullability is removed entirely — the module always returns a valid color scheme, and the module-level ?Spec already covers the "module absent" case.

Changelog:
[General][Breaking] - Fix return type of useColorScheme() hook (now ColorSchemeName | null)

  • Release Crew note: This is a net fix/extension of D102527387

Differential Revision: D103865622

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 5, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels May 5, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 5, 2026

@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D103865622.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

huntie added 2 commits May 6, 2026 01:29
Summary:

Removes `'unspecified'` from the return type of `Appearance.getColorScheme()` and `useColorScheme()`, splitting the setter input into a separate `ColorSchemeOverride` type. This resolves a longstanding misalignment between what native returns and what the types promise.

**Motivation**

`'unspecified'` is only meaningful as an input to `setColorScheme()` — neither iOS nor Android ever returns it from `getColorScheme()`. When `setColorScheme('unspecified')` is called, the JS layer re-queries the native module and caches the resolved system value.

After this change:

- `Appearance.getColorScheme()` returns `'light' | 'dark'` (no longer `'unspecified'`)
- `Appearance.setColorScheme()` receives `'light' | 'dark' | 'unspecified'`

Paired with docs updates:
- facebook/react-native-website#5060
- facebook/react-native-website#5069

**History of this API**

- The TurboModule spec originally typed these methods as plain `string` because codegen didn't support union types (T52919652).
- When support landed, D63681874 upgraded to `ColorSchemeName = 'light' | 'dark' | 'unspecified'` — a type-level cleanup that inadvertently widened return types to include `'unspecified'`, a value native never returns. This caused `$FlowFixMe` suppressions across downstream callers.
- D80705652 later aligned the `.d.ts` and fixed a bug where `setColorScheme('unspecified')` threw an incorrect invariant.

Changelog:
[General][Breaking] - `useColorScheme()` no longer returns `'unspecified'` (this was always the case, but is a breaking type change)

Differential Revision: D102527387
Summary:

Simplify and align nullable values in the `Appearance` API.

| API | Flow / Strict TS API | Manual `.d.ts` |
|---|---|---|
| `getColorScheme()` | `ColorSchemeName | null` (narrowed) | `ColorSchemeName | null` |
| `useColorScheme()` | `ColorSchemeName | null` (narrowed) | `ColorSchemeName | null` (fixed) |

At the native spec level, nullability is removed entirely — the module always returns a valid color scheme, and the module-level `?Spec` already covers the "module absent" case.

Changelog: [Internal] - This is a net fix/extension of D102527387

Differential Revision: D103865622
@meta-codesync meta-codesync Bot changed the title Align nullable types across Appearance API Align nullable types across Appearance API (#56687) May 6, 2026
@huntie huntie force-pushed the export-D103865622 branch from 900aac6 to 5341f7e Compare May 6, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant