From a64b21b1a0d02e997ee54da7ce1629b084af5fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JC=20P=C3=A9rez=20Chavez?= Date: Mon, 19 Oct 2026 23:11:25 -0700 Subject: [PATCH] Remove 6 $FlowFixMe[sketchy-null-*] suppressions (Button, URL, ScrollView, RNTester) (#59211) Summary: Pull Request resolved: https://github.com/react/react-native/pull/59211 Replaces six `$FlowFixMe[sketchy-null-string|bool|number]` suppressions with explicit checks that keep the exact runtime behavior, including for `''`, `0` and `NaN`. - `Button`: `ariaLabel || accessibilityLabel` became `ariaLabel != null && ariaLabel !== '' ? ariaLabel : accessibilityLabel`, so an empty `aria-label` still falls back to `accessibilityLabel`. - `URL`: in the constructor, `!base` became `base == null || base === ''`. A `URL` instance is always truthy, so this matches the old check. - `ScrollView` (2): `keyboardShouldPersistTaps` is typed `?('always' | 'never' | 'handled')`, whose values are never falsy. So `!keyboardShouldPersistTaps` is the same as `keyboardShouldPersistTaps == null`. - RNTester `PressableExample`: `setForce(event.nativeEvent?.force || 1)` became `touchForce != null && Boolean(touchForce) ? touchForce : 1`, reading the value into a local const. `Boolean()` keeps the `0`/`NaN` fallback exactly as `||` did, and `!= null` lets Flow refine the value to `number`. - RNTester `useJsStalls`: `!state.stallIntervalId` became `!Boolean(state.stallIntervalId)`. The interval ID is an opaque `IntervalID` in the OSS Flow libdefs, so it can't be compared with `0`; `Boolean()` keeps the exact semantics. No new suppressions, casts, comments, or tests. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D126162944 fbshipit-source-id: d0402e37351005d364a45c90d3bb086953179242 --- packages/react-native/Libraries/Blob/URL.js | 3 +-- packages/react-native/Libraries/Components/Button.js | 3 +-- .../Libraries/Components/ScrollView/ScrollView.js | 8 ++++---- .../rn-tester/js/examples/Pressable/PressableExample.js | 8 ++++++-- packages/rn-tester/js/utils/useJsStalls.js | 3 +-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/react-native/Libraries/Blob/URL.js b/packages/react-native/Libraries/Blob/URL.js index 3da963315be..8386cc6d979 100644 --- a/packages/react-native/Libraries/Blob/URL.js +++ b/packages/react-native/Libraries/Blob/URL.js @@ -81,8 +81,7 @@ export class URL { // $FlowFixMe[missing-local-annot] constructor(url: string, base?: string | URL) { let baseUrl = null; - // $FlowFixMe[sketchy-null-string] - if (!base || validateBaseUrl(url)) { + if (base == null || base === '' || validateBaseUrl(url)) { this._url = url; if (this._url.includes('#')) { const split = this._url.split('#'); diff --git a/packages/react-native/Libraries/Components/Button.js b/packages/react-native/Libraries/Components/Button.js index ee8b2272f27..f1cbd0fda2b 100644 --- a/packages/react-native/Libraries/Components/Button.js +++ b/packages/react-native/Libraries/Components/Button.js @@ -271,8 +271,7 @@ const Button: component( accessibilityActions={accessibilityActions} onAccessibilityAction={onAccessibilityAction} accessibilityLabel={ - // $FlowFixMe[sketchy-null-string] - ariaLabel || accessibilityLabel + ariaLabel != null && ariaLabel !== '' ? ariaLabel : accessibilityLabel } accessibilityHint={accessibilityHint} accessibilityLanguage={accessibilityLanguage} diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js index 5c7974f2ac3..55ebda75d1a 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js @@ -1586,8 +1586,8 @@ class ScrollView extends React.Component { // then the second tap goes to the actual interior view) const {keyboardShouldPersistTaps} = this.props; const keyboardNeverPersistTaps = - // $FlowFixMe[sketchy-null-bool] - !keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never'; + keyboardShouldPersistTaps == null || + keyboardShouldPersistTaps === 'never'; if (typeof e.target === 'number') { if (__DEV__) { @@ -1669,8 +1669,8 @@ class ScrollView extends React.Component { const {keyboardShouldPersistTaps} = this.props; const keyboardNeverPersistsTaps = - // $FlowFixMe[sketchy-null-bool] - !keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never'; + keyboardShouldPersistTaps == null || + keyboardShouldPersistTaps === 'never'; // Dismiss the keyboard now if we didn't become responder in capture phase // to eat presses, but still want to dismiss on interaction. diff --git a/packages/rn-tester/js/examples/Pressable/PressableExample.js b/packages/rn-tester/js/examples/Pressable/PressableExample.js index fc7ba7bb800..e875940c9c8 100644 --- a/packages/rn-tester/js/examples/Pressable/PressableExample.js +++ b/packages/rn-tester/js/examples/Pressable/PressableExample.js @@ -191,8 +191,12 @@ function ForceTouchExample() { style={styles.wrapper} testID="pressable_3dtouch_button" onStartShouldSetResponder={() => true} - // $FlowFixMe[sketchy-null-number] - onResponderMove={event => setForce(event.nativeEvent?.force || 1)} + onResponderMove={event => { + const touchForce = event.nativeEvent?.force; + setForce( + touchForce != null && Boolean(touchForce) ? touchForce : 1, + ); + }} onResponderRelease={event => setForce(0)}> Press Me diff --git a/packages/rn-tester/js/utils/useJsStalls.js b/packages/rn-tester/js/utils/useJsStalls.js index 7dc9c979682..c2d6058e7bc 100644 --- a/packages/rn-tester/js/utils/useJsStalls.js +++ b/packages/rn-tester/js/utils/useJsStalls.js @@ -67,8 +67,7 @@ const useJsStalls = (): ({ onStall: ({busyTime}) => setStallsState(state => { // If previous interval was cleared - // $FlowFixMe[sketchy-null-number] - if (!state.stallIntervalId) { + if (!Boolean(state.stallIntervalId)) { return state; }