Skip to content

Commit a64b21b

Browse files
jcperez-chmeta-codesync[bot]
authored andcommitted
Remove 6 $FlowFixMe[sketchy-null-*] suppressions (Button, URL, ScrollView, RNTester) (#59211)
Summary: Pull Request resolved: #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
1 parent 2fd8fd6 commit a64b21b

5 files changed

Lines changed: 13 additions & 12 deletions

File tree

‎packages/react-native/Libraries/Blob/URL.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export class URL {
8181
// $FlowFixMe[missing-local-annot]
8282
constructor(url: string, base?: string | URL) {
8383
let baseUrl = null;
84-
// $FlowFixMe[sketchy-null-string]
85-
if (!base || validateBaseUrl(url)) {
84+
if (base == null || base === '' || validateBaseUrl(url)) {
8685
this._url = url;
8786
if (this._url.includes('#')) {
8887
const split = this._url.split('#');

‎packages/react-native/Libraries/Components/Button.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ const Button: component(
271271
accessibilityActions={accessibilityActions}
272272
onAccessibilityAction={onAccessibilityAction}
273273
accessibilityLabel={
274-
// $FlowFixMe[sketchy-null-string]
275-
ariaLabel || accessibilityLabel
274+
ariaLabel != null && ariaLabel !== '' ? ariaLabel : accessibilityLabel
276275
}
277276
accessibilityHint={accessibilityHint}
278277
accessibilityLanguage={accessibilityLanguage}

‎packages/react-native/Libraries/Components/ScrollView/ScrollView.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,8 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
15861586
// then the second tap goes to the actual interior view)
15871587
const {keyboardShouldPersistTaps} = this.props;
15881588
const keyboardNeverPersistTaps =
1589-
// $FlowFixMe[sketchy-null-bool]
1590-
!keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never';
1589+
keyboardShouldPersistTaps == null ||
1590+
keyboardShouldPersistTaps === 'never';
15911591

15921592
if (typeof e.target === 'number') {
15931593
if (__DEV__) {
@@ -1669,8 +1669,8 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
16691669

16701670
const {keyboardShouldPersistTaps} = this.props;
16711671
const keyboardNeverPersistsTaps =
1672-
// $FlowFixMe[sketchy-null-bool]
1673-
!keyboardShouldPersistTaps || keyboardShouldPersistTaps === 'never';
1672+
keyboardShouldPersistTaps == null ||
1673+
keyboardShouldPersistTaps === 'never';
16741674

16751675
// Dismiss the keyboard now if we didn't become responder in capture phase
16761676
// to eat presses, but still want to dismiss on interaction.

‎packages/rn-tester/js/examples/Pressable/PressableExample.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ function ForceTouchExample() {
191191
style={styles.wrapper}
192192
testID="pressable_3dtouch_button"
193193
onStartShouldSetResponder={() => true}
194-
// $FlowFixMe[sketchy-null-number]
195-
onResponderMove={event => setForce(event.nativeEvent?.force || 1)}
194+
onResponderMove={event => {
195+
const touchForce = event.nativeEvent?.force;
196+
setForce(
197+
touchForce != null && Boolean(touchForce) ? touchForce : 1,
198+
);
199+
}}
196200
onResponderRelease={event => setForce(0)}>
197201
<Text style={styles.button}>Press Me</Text>
198202
</View>

‎packages/rn-tester/js/utils/useJsStalls.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ const useJsStalls = (): ({
6767
onStall: ({busyTime}) =>
6868
setStallsState(state => {
6969
// If previous interval was cleared
70-
// $FlowFixMe[sketchy-null-number]
71-
if (!state.stallIntervalId) {
70+
if (!Boolean(state.stallIntervalId)) {
7271
return state;
7372
}
7473

0 commit comments

Comments
 (0)