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
This commit is contained in:
Marco Wang
2025-08-21 16:46:23 -07:00
committed by Facebook GitHub Bot
parent ffe52b75a3
commit da9136f587
9 changed files with 31 additions and 5 deletions
@@ -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':
@@ -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',
);
@@ -18,6 +18,8 @@ export class URLSearchParams {
}
constructor(params?: Record<string, string> | string | [string, string][]) {
/* $FlowFixMe[invalid-compare] Error discovered during Constant Condition
* roll out. See https://fburl.com/workplace/5whu3i34. */
if (params === null) {
return;
}
+4
View File
@@ -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',
);
@@ -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;
@@ -33,6 +33,8 @@ function deepFreezeAndThrowOnMutationInDev<T: {...} | Array<mixed>>(
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)
@@ -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)';
}
@@ -28,11 +28,15 @@ function InlineView(props: {
<RNTesterText style={{fontWeight: 'bold'}}>Child</RNTesterText>
<View style={{width: 30, height: 30, backgroundColor: 'red'}} />
<RNTesterText style={{fontWeight: 'bold'}}>Child</RNTesterText>
{props !== null && props.long === true && (
<RNTesterText style={{fontWeight: 'bold'}}>
aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas
</RNTesterText>
)}
{
/* $FlowFixMe[invalid-compare] Error discovered during Constant
* Condition roll out. See https://fburl.com/workplace/5whu3i34. */
props !== null && props.long === true && (
<RNTesterText style={{fontWeight: 'bold'}}>
aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas
</RNTesterText>
)
}
</RNTesterText>
</View>
);
@@ -136,6 +136,8 @@ function convertRawJsonToJSX(
actualJSON: FantomJsonObject | $ReadOnlyArray<FantomJsonObject>,
): 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)) {