From da9136f587fa3b2be708193300d4e55537855e19 Mon Sep 17 00:00:00 2001 From: Marco Wang Date: Thu, 21 Aug 2025 16:46:23 -0700 Subject: [PATCH] Turn on null strict comparison check for xplat js (#53379) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53379 X-link: https://github.com/facebook/react/pull/34240 Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D80648362 fbshipit-source-id: cc47ae207f29a3ddb68bc0e029b8773f89503c52 --- .../typescript/components/componentsUtils.js | 4 ++++ .../Libraries/ActionSheetIOS/ActionSheetIOS.js | 4 ++++ .../react-native/Libraries/Blob/URLSearchParams.js | 2 ++ packages/react-native/Libraries/Share/Share.js | 4 ++++ .../react-native/Libraries/Utilities/HMRClient.js | 2 ++ .../Utilities/deepFreezeAndThrowOnMutationInDev.js | 2 ++ .../Libraries/WebSocket/WebSocketInterceptor.js | 2 ++ .../js/examples/Text/TextSharedExamples.js | 14 +++++++++----- .../src/getFantomRenderedOutput.js | 2 ++ 9 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js index f178527433c..71847b102cf 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js @@ -350,6 +350,8 @@ function setDefaultValue( common.default = ((defaultValue ? defaultValue : 0): number); break; case 'FloatTypeAnnotation': + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ common.default = ((defaultValue === null ? null : defaultValue @@ -357,6 +359,8 @@ function setDefaultValue( : 0): number | null); break; case 'BooleanTypeAnnotation': + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ common.default = defaultValue === null ? null : !!defaultValue; break; case 'StringTypeAnnotation': diff --git a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js index 3ed03402646..84e274c1834 100644 --- a/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -77,6 +77,8 @@ const ActionSheetIOS = { callback: (buttonIndex: number) => void, ) { invariant( + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ typeof options === 'object' && options !== null, 'Options must be a valid object', ); @@ -162,6 +164,8 @@ const ActionSheetIOS = { successCallback: Function | ((success: boolean, method: ?string) => void), ) { invariant( + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ typeof options === 'object' && options !== null, 'Options must be a valid object', ); diff --git a/packages/react-native/Libraries/Blob/URLSearchParams.js b/packages/react-native/Libraries/Blob/URLSearchParams.js index c17829849ae..1560fc2b335 100644 --- a/packages/react-native/Libraries/Blob/URLSearchParams.js +++ b/packages/react-native/Libraries/Blob/URLSearchParams.js @@ -18,6 +18,8 @@ export class URLSearchParams { } constructor(params?: Record | string | [string, string][]) { + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ if (params === null) { return; } diff --git a/packages/react-native/Libraries/Share/Share.js b/packages/react-native/Libraries/Share/Share.js index f23720e2df6..adfc6efc750 100644 --- a/packages/react-native/Libraries/Share/Share.js +++ b/packages/react-native/Libraries/Share/Share.js @@ -83,6 +83,8 @@ class Share { options?: ShareOptions = {}, ): Promise<{action: string, activityType: ?string}> { invariant( + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ typeof content === 'object' && content !== null, 'Content to share must be a valid object', ); @@ -91,6 +93,8 @@ class Share { 'At least one of URL or message is required', ); invariant( + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ typeof options === 'object' && options !== null, 'Options must be a valid object', ); diff --git a/packages/react-native/Libraries/Utilities/HMRClient.js b/packages/react-native/Libraries/Utilities/HMRClient.js index 3cde3832f74..6d16b6b973f 100644 --- a/packages/react-native/Libraries/Utilities/HMRClient.js +++ b/packages/react-native/Libraries/Utilities/HMRClient.js @@ -165,6 +165,8 @@ const HMRClient: HMRClientNativeInterface = { // Moving to top gives errors due to NativeModules not being initialized const DevLoadingView = require('./DevLoadingView').default; + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ const serverHost = port !== null && port !== '' ? `${host}:${port}` : host; const serverScheme = scheme; diff --git a/packages/react-native/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js b/packages/react-native/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js index 63701e7bca7..83b79a17182 100644 --- a/packages/react-native/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +++ b/packages/react-native/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js @@ -33,6 +33,8 @@ function deepFreezeAndThrowOnMutationInDev>( if (__DEV__) { if ( typeof object !== 'object' || + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ object === null || Object.isFrozen(object) || Object.isSealed(object) diff --git a/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js b/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js index 796c2c89b67..ea7f371ad1e 100644 --- a/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js +++ b/packages/react-native/Libraries/WebSocket/WebSocketInterceptor.js @@ -232,6 +232,8 @@ const WebSocketInterceptor = { _arrayBufferToString(data: string): ArrayBuffer | string { const value = base64.toByteArray(data).buffer; + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ if (value === undefined || value === null) { return '(no value)'; } diff --git a/packages/rn-tester/js/examples/Text/TextSharedExamples.js b/packages/rn-tester/js/examples/Text/TextSharedExamples.js index e45fac6545c..fb483463394 100644 --- a/packages/rn-tester/js/examples/Text/TextSharedExamples.js +++ b/packages/rn-tester/js/examples/Text/TextSharedExamples.js @@ -28,11 +28,15 @@ function InlineView(props: { Child Child - {props !== null && props.long === true && ( - - aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas - - )} + { + /* $FlowFixMe[invalid-compare] Error discovered during Constant + * Condition roll out. See https://fburl.com/workplace/5whu3i34. */ + props !== null && props.long === true && ( + + aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas + + ) + } ); diff --git a/private/react-native-fantom/src/getFantomRenderedOutput.js b/private/react-native-fantom/src/getFantomRenderedOutput.js index b51873446f2..a0599ef1365 100644 --- a/private/react-native-fantom/src/getFantomRenderedOutput.js +++ b/private/react-native-fantom/src/getFantomRenderedOutput.js @@ -136,6 +136,8 @@ function convertRawJsonToJSX( actualJSON: FantomJsonObject | $ReadOnlyArray, ): React.Node { let actualJSX; + /* $FlowFixMe[invalid-compare] Error discovered during Constant Condition + * roll out. See https://fburl.com/workplace/5whu3i34. */ if (actualJSON === null || typeof actualJSON === 'string') { actualJSX = actualJSON; } else if (Array.isArray(actualJSON)) {