From eddd30ed160f4abe370053be01b86492820157bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Sat, 19 Oct 2024 12:42:39 +0200 Subject: [PATCH 1/2] refactor(invariant): using local module instead of module from fbjs/lib --- .../src/exports/AppRegistry/index.js | 2 +- .../exports/AppRegistry/renderApplication.js | 2 +- .../src/exports/AppState/index.js | 2 +- .../src/exports/Dimensions/index.js | 2 +- .../exports/InteractionManager/TaskQueue.js | 2 +- .../src/exports/InteractionManager/index.js | 2 +- .../src/exports/Linking/index.js | 2 +- .../src/exports/ScrollView/index.js | 2 +- .../src/exports/Share/index.js | 2 +- .../Touchable/ensurePositiveDelayProps.js | 2 +- .../src/modules/invariant/index.js | 50 +++++++++++++++++++ .../react-native/Animated/AnimatedEvent.js | 2 +- .../Animated/NativeAnimatedHelper.js | 2 +- .../Animated/animations/SpringAnimation.js | 2 +- .../Animated/nodes/AnimatedInterpolation.js | 2 +- .../Animated/nodes/AnimatedNode.js | 2 +- .../Animated/nodes/AnimatedProps.js | 2 +- .../Animated/nodes/AnimatedValueXY.js | 2 +- .../EventEmitter/NativeEventEmitter.js | 2 +- .../src/vendor/react-native/FlatList/index.js | 2 +- .../vendor/react-native/PooledClass/index.js | 2 - .../TurboModule/TurboModuleRegistry.js | 2 +- .../react-native/ViewabilityHelper/index.js | 2 +- .../VirtualizedList/CellRenderMask.js | 2 +- .../VirtualizedList/ChildListCollection.js | 2 +- .../VirtualizedList/StateSafePureComponent.js | 2 +- .../VirtualizedListCellRenderer.js | 2 +- .../react-native/VirtualizedList/index.js | 2 +- .../VirtualizedSectionList/index.js | 2 +- 29 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 packages/react-native-web/src/modules/invariant/index.js diff --git a/packages/react-native-web/src/exports/AppRegistry/index.js b/packages/react-native-web/src/exports/AppRegistry/index.js index 53a0af51a8..1fb629dacf 100644 --- a/packages/react-native-web/src/exports/AppRegistry/index.js +++ b/packages/react-native-web/src/exports/AppRegistry/index.js @@ -13,7 +13,7 @@ import type { Application } from './renderApplication'; import type { ComponentType, Node } from 'react'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import unmountComponentAtNode from '../unmountComponentAtNode'; import renderApplication, { getApplication } from './renderApplication'; diff --git a/packages/react-native-web/src/exports/AppRegistry/renderApplication.js b/packages/react-native-web/src/exports/AppRegistry/renderApplication.js index 95df521336..cc96c3a526 100644 --- a/packages/react-native-web/src/exports/AppRegistry/renderApplication.js +++ b/packages/react-native-web/src/exports/AppRegistry/renderApplication.js @@ -11,7 +11,7 @@ import type { ComponentType, Node } from 'react'; import AppContainer from './AppContainer'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import renderLegacy, { hydrateLegacy, render, hydrate } from '../render'; import StyleSheet from '../StyleSheet'; import React from 'react'; diff --git a/packages/react-native-web/src/exports/AppState/index.js b/packages/react-native-web/src/exports/AppState/index.js index 7acd1eac82..75d88f16f4 100644 --- a/packages/react-native-web/src/exports/AppState/index.js +++ b/packages/react-native-web/src/exports/AppState/index.js @@ -10,7 +10,7 @@ 'use client'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import EventEmitter from '../../vendor/react-native/vendor/emitter/EventEmitter'; import canUseDOM from '../../modules/canUseDom'; diff --git a/packages/react-native-web/src/exports/Dimensions/index.js b/packages/react-native-web/src/exports/Dimensions/index.js index 45c9e519ee..f00d951ba2 100644 --- a/packages/react-native-web/src/exports/Dimensions/index.js +++ b/packages/react-native-web/src/exports/Dimensions/index.js @@ -11,7 +11,7 @@ 'use client'; import type { EventSubscription } from '../../vendor/react-native/vendor/emitter/EventEmitter'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import canUseDOM from '../../modules/canUseDom'; export type DisplayMetrics = {| diff --git a/packages/react-native-web/src/exports/InteractionManager/TaskQueue.js b/packages/react-native-web/src/exports/InteractionManager/TaskQueue.js index 7381d52af6..a20b7039c5 100644 --- a/packages/react-native-web/src/exports/InteractionManager/TaskQueue.js +++ b/packages/react-native-web/src/exports/InteractionManager/TaskQueue.js @@ -8,7 +8,7 @@ * @flow */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; type SimpleTask = {| name: string, diff --git a/packages/react-native-web/src/exports/InteractionManager/index.js b/packages/react-native-web/src/exports/InteractionManager/index.js index d6a522f3cf..9c11093516 100644 --- a/packages/react-native-web/src/exports/InteractionManager/index.js +++ b/packages/react-native-web/src/exports/InteractionManager/index.js @@ -8,7 +8,7 @@ * @flow */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import type { Task } from './TaskQueue'; import TaskQueue from './TaskQueue'; import type { EventSubscription } from '../../vendor/react-native/vendor/emitter/EventEmitter'; diff --git a/packages/react-native-web/src/exports/Linking/index.js b/packages/react-native-web/src/exports/Linking/index.js index ec365eb3e6..e2c4abadd8 100644 --- a/packages/react-native-web/src/exports/Linking/index.js +++ b/packages/react-native-web/src/exports/Linking/index.js @@ -8,7 +8,7 @@ * @flow */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import canUseDOM from '../../modules/canUseDom'; const initialURL = canUseDOM ? window.location.href : ''; diff --git a/packages/react-native-web/src/exports/ScrollView/index.js b/packages/react-native-web/src/exports/ScrollView/index.js index 6b56e894fd..1654454444 100644 --- a/packages/react-native-web/src/exports/ScrollView/index.js +++ b/packages/react-native-web/src/exports/ScrollView/index.js @@ -14,7 +14,7 @@ import type { ViewProps, ViewStyle } from '../View/types'; import Dimensions from '../Dimensions'; import dismissKeyboard from '../../modules/dismissKeyboard'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; import mergeRefs from '../../modules/mergeRefs'; import Platform from '../Platform'; import ScrollViewBase from './ScrollViewBase'; diff --git a/packages/react-native-web/src/exports/Share/index.js b/packages/react-native-web/src/exports/Share/index.js index ffedec07af..5928297405 100644 --- a/packages/react-native-web/src/exports/Share/index.js +++ b/packages/react-native-web/src/exports/Share/index.js @@ -8,7 +8,7 @@ * @flow */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; type Content = | { title?: string, message?: string, url: string } diff --git a/packages/react-native-web/src/exports/Touchable/ensurePositiveDelayProps.js b/packages/react-native-web/src/exports/Touchable/ensurePositiveDelayProps.js index e6ee713f1f..b3a3b4bd27 100644 --- a/packages/react-native-web/src/exports/Touchable/ensurePositiveDelayProps.js +++ b/packages/react-native-web/src/exports/Touchable/ensurePositiveDelayProps.js @@ -7,7 +7,7 @@ * @flow */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../modules/invariant'; const ensurePositiveDelayProps = (props: any) => { invariant( diff --git a/packages/react-native-web/src/modules/invariant/index.js b/packages/react-native-web/src/modules/invariant/index.js new file mode 100644 index 0000000000..8dc9c615ab --- /dev/null +++ b/packages/react-native-web/src/modules/invariant/index.js @@ -0,0 +1,50 @@ +/* eslint-disable */ +'use strict'; + +var validateFormat = + process.env.NODE_ENV !== 'production' + ? function (format) { + if (format === undefined) { + throw new Error('invariant(...): Second argument must be a string.'); + } + } + : function (format) {}; + +function invariant(condition, format) { + for ( + var _len = arguments.length, + args = new Array(_len > 2 ? _len - 2 : 0), + _key = 2; + _key < _len; + _key++ + ) { + args[_key - 2] = arguments[_key]; + } + + validateFormat(format); + + if (!condition) { + var error; + + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ); + } else { + var argIndex = 0; + error = new Error( + format.replace(/%s/g, function () { + return String(args[argIndex++]); + }) + ); + error.name = 'Invariant Violation'; + } + + error.framesToPop = 1; // Skip invariant's own stack frame. + + throw error; + } +} + +export default invariant; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/AnimatedEvent.js b/packages/react-native-web/src/vendor/react-native/Animated/AnimatedEvent.js index 3d673ab6b8..20ca62ca19 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/AnimatedEvent.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/AnimatedEvent.js @@ -13,7 +13,7 @@ import AnimatedValue from './nodes/AnimatedValue'; import NativeAnimatedHelper from './NativeAnimatedHelper'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import {shouldUseNativeDriver}from './NativeAnimatedHelper'; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/NativeAnimatedHelper.js b/packages/react-native-web/src/vendor/react-native/Animated/NativeAnimatedHelper.js index 5f3c39c05b..b96edc28a5 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/NativeAnimatedHelper.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/NativeAnimatedHelper.js @@ -21,7 +21,7 @@ import type { import type {AnimationConfig, EndCallback} from './animations/Animation'; import type {InterpolationConfigType} from './nodes/AnimatedInterpolation'; import ReactNativeFeatureFlags from '../ReactNative/ReactNativeFeatureFlags'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import RCTDeviceEventEmitter from '../EventEmitter/RCTDeviceEventEmitter'; import type {EventSubscription} from '../vendor/emitter/EventEmitter'; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/animations/SpringAnimation.js b/packages/react-native-web/src/vendor/react-native/Animated/animations/SpringAnimation.js index 07c0df0839..d0165b50b0 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/animations/SpringAnimation.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/animations/SpringAnimation.js @@ -17,7 +17,7 @@ import type AnimatedInterpolation from '../nodes/AnimatedInterpolation'; import Animation from './Animation'; import SpringConfig from '../SpringConfig'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../../modules/invariant'; import {shouldUseNativeDriver} from '../NativeAnimatedHelper'; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedInterpolation.js b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedInterpolation.js index 4e99e64fd5..c6343073e4 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedInterpolation.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedInterpolation.js @@ -17,7 +17,7 @@ import type AnimatedNode from './AnimatedNode'; import AnimatedWithChildren from './AnimatedWithChildren'; import NativeAnimatedHelper from '../NativeAnimatedHelper'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../../modules/invariant'; import normalizeColor from '@react-native/normalize-colors'; import type {PlatformConfig} from '../AnimatedPlatformConfig'; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedNode.js b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedNode.js index 88bbdcc38e..ba37aae28c 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedNode.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedNode.js @@ -13,7 +13,7 @@ import NativeAnimatedHelper from '../NativeAnimatedHelper'; const NativeAnimatedAPI = NativeAnimatedHelper.API; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../../modules/invariant'; import type {PlatformConfig} from '../AnimatedPlatformConfig'; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedProps.js b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedProps.js index 65922d06ad..e423afb836 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedProps.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedProps.js @@ -15,7 +15,7 @@ import AnimatedNode from './AnimatedNode'; import AnimatedStyle from './AnimatedStyle'; import NativeAnimatedHelper from '../NativeAnimatedHelper'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../../modules/invariant'; class AnimatedProps extends AnimatedNode { _props: Object; diff --git a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedValueXY.js b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedValueXY.js index f7d9787fb9..724dc00f53 100644 --- a/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedValueXY.js +++ b/packages/react-native-web/src/vendor/react-native/Animated/nodes/AnimatedValueXY.js @@ -13,7 +13,7 @@ import AnimatedValue from './AnimatedValue'; import AnimatedWithChildren from './AnimatedWithChildren'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../../modules/invariant'; type ValueXYListenerCallback = (value: { x: number, diff --git a/packages/react-native-web/src/vendor/react-native/EventEmitter/NativeEventEmitter.js b/packages/react-native-web/src/vendor/react-native/EventEmitter/NativeEventEmitter.js index f7f23ac00d..6c4c2a8abc 100644 --- a/packages/react-native-web/src/vendor/react-native/EventEmitter/NativeEventEmitter.js +++ b/packages/react-native-web/src/vendor/react-native/EventEmitter/NativeEventEmitter.js @@ -16,7 +16,7 @@ import { } from '../vendor/emitter/EventEmitter'; import Platform from '../../../exports/Platform'; import RCTDeviceEventEmitter from './RCTDeviceEventEmitter'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; type NativeModule = $ReadOnly<{ addListener: (eventType: string) => void, diff --git a/packages/react-native-web/src/vendor/react-native/FlatList/index.js b/packages/react-native-web/src/vendor/react-native/FlatList/index.js index eefb789425..1acd32a30f 100644 --- a/packages/react-native-web/src/vendor/react-native/FlatList/index.js +++ b/packages/react-native-web/src/vendor/react-native/FlatList/index.js @@ -12,7 +12,7 @@ import View, { type ViewProps } from '../../../exports/View'; import StyleSheet from '../../../exports/StyleSheet'; import deepDiffer from '../deepDiffer'; import Platform from '../../../exports/Platform'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import * as React from 'react'; type ScrollViewNativeComponent = any; diff --git a/packages/react-native-web/src/vendor/react-native/PooledClass/index.js b/packages/react-native-web/src/vendor/react-native/PooledClass/index.js index d310ab4497..b60aafb197 100644 --- a/packages/react-native-web/src/vendor/react-native/PooledClass/index.js +++ b/packages/react-native-web/src/vendor/react-native/PooledClass/index.js @@ -9,8 +9,6 @@ * From React 16.0.0 */ -import invariant from 'fbjs/lib/invariant'; - var twoArgumentPooler = function(a1, a2) { var Klass = this; if (Klass.instancePool.length) { diff --git a/packages/react-native-web/src/vendor/react-native/TurboModule/TurboModuleRegistry.js b/packages/react-native-web/src/vendor/react-native/TurboModule/TurboModuleRegistry.js index 4e3bba31b1..d797ea98d7 100644 --- a/packages/react-native-web/src/vendor/react-native/TurboModule/TurboModuleRegistry.js +++ b/packages/react-native-web/src/vendor/react-native/TurboModule/TurboModuleRegistry.js @@ -11,7 +11,7 @@ 'use strict'; import type {TurboModule} from './RCTExport'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; export function get(name: string): ?T { return null; diff --git a/packages/react-native-web/src/vendor/react-native/ViewabilityHelper/index.js b/packages/react-native-web/src/vendor/react-native/ViewabilityHelper/index.js index 850118e85c..7c397d771f 100644 --- a/packages/react-native-web/src/vendor/react-native/ViewabilityHelper/index.js +++ b/packages/react-native-web/src/vendor/react-native/ViewabilityHelper/index.js @@ -12,7 +12,7 @@ import type {FrameMetricProps} from '../VirtualizedList/VirtualizedListProps'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; export type ViewToken = { item: any, diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedList/CellRenderMask.js b/packages/react-native-web/src/vendor/react-native/VirtualizedList/CellRenderMask.js index a234607ca6..dd4ddf90b3 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedList/CellRenderMask.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedList/CellRenderMask.js @@ -8,7 +8,7 @@ * @format */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; export type CellRegion = { first: number, diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedList/ChildListCollection.js b/packages/react-native-web/src/vendor/react-native/VirtualizedList/ChildListCollection.js index dc8cfe7c1f..cc9b9a7a95 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedList/ChildListCollection.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedList/ChildListCollection.js @@ -8,7 +8,7 @@ * @format */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; export default class ChildListCollection { _cellKeyToChildren: Map> = new Map(); diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedList/StateSafePureComponent.js b/packages/react-native-web/src/vendor/react-native/VirtualizedList/StateSafePureComponent.js index 145a4ebce0..ba7bcf377f 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedList/StateSafePureComponent.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedList/StateSafePureComponent.js @@ -8,7 +8,7 @@ * @format */ -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import * as React from 'react'; /** diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js b/packages/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js index b251487513..152a9ac694 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js @@ -17,7 +17,7 @@ import type {CellRendererProps, RenderItemType} from './VirtualizedListProps'; import View, { type ViewProps } from '../../../exports/View'; import StyleSheet from '../../../exports/StyleSheet'; import {VirtualizedListCellContextProvider} from './VirtualizedListContext.js'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import * as React from 'react'; type ViewStyleProp = $PropertyType; diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js b/packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js index c7d68bb716..92927cbb5f 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js @@ -46,7 +46,7 @@ import { computeWindowedRenderLimits, keyExtractor as defaultKeyExtractor, } from '../VirtualizeUtils'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import nullthrows from 'nullthrows'; import * as React from 'react'; diff --git a/packages/react-native-web/src/vendor/react-native/VirtualizedSectionList/index.js b/packages/react-native-web/src/vendor/react-native/VirtualizedSectionList/index.js index c37c8d3727..ee86fd9aeb 100644 --- a/packages/react-native-web/src/vendor/react-native/VirtualizedSectionList/index.js +++ b/packages/react-native-web/src/vendor/react-native/VirtualizedSectionList/index.js @@ -12,7 +12,7 @@ import type {ViewToken} from '../ViewabilityHelper'; import View from '../../../exports/View'; import VirtualizedList from '../VirtualizedList'; import {keyExtractor as defaultKeyExtractor} from '../VirtualizeUtils'; -import invariant from 'fbjs/lib/invariant'; +import invariant from '../../../modules/invariant'; import * as React from 'react'; type Item = any; From e65e598f87c3bf0c7d44a9538e4786dcf34d2841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Sat, 19 Oct 2024 12:57:24 +0200 Subject: [PATCH 2/2] refactor(deps): using local warning module instead of module from fbjs/lib and removing fbjs dep --- package-lock.json | 2 - packages/react-native-web/package.json | 1 - .../src/exports/ScrollView/index.js | 2 +- .../src/modules/emptyFunction/index.js | 30 ++++++++ .../src/modules/warning/index.js | 68 +++++++++++++++++++ 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 packages/react-native-web/src/modules/emptyFunction/index.js create mode 100644 packages/react-native-web/src/modules/warning/index.js diff --git a/package-lock.json b/package-lock.json index af7daecb59..b89a776f30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16569,7 +16569,6 @@ "dependencies": { "@babel/runtime": "^7.18.6", "@react-native/normalize-colors": "^0.74.1", - "fbjs": "^3.0.4", "inline-style-prefixer": "^6.0.1", "memoize-one": "^6.0.0", "nullthrows": "^1.1.1", @@ -25639,7 +25638,6 @@ "requires": { "@babel/runtime": "^7.18.6", "@react-native/normalize-colors": "^0.74.1", - "fbjs": "^3.0.4", "inline-style-prefixer": "^6.0.1", "memoize-one": "^6.0.0", "nullthrows": "^1.1.1", diff --git a/packages/react-native-web/package.json b/packages/react-native-web/package.json index 05c68b68fe..896b1338b4 100644 --- a/packages/react-native-web/package.json +++ b/packages/react-native-web/package.json @@ -24,7 +24,6 @@ "dependencies": { "@babel/runtime": "^7.18.6", "@react-native/normalize-colors": "^0.74.1", - "fbjs": "^3.0.4", "inline-style-prefixer": "^6.0.1", "memoize-one": "^6.0.0", "nullthrows": "^1.1.1", diff --git a/packages/react-native-web/src/exports/ScrollView/index.js b/packages/react-native-web/src/exports/ScrollView/index.js index 1654454444..cc73aaf6c2 100644 --- a/packages/react-native-web/src/exports/ScrollView/index.js +++ b/packages/react-native-web/src/exports/ScrollView/index.js @@ -23,7 +23,7 @@ import TextInputState from '../../modules/TextInputState'; import UIManager from '../UIManager'; import View from '../View'; import React from 'react'; -import warning from 'fbjs/lib/warning'; +import warning from '../../modules/warning'; type ScrollViewProps = { ...ViewProps, diff --git a/packages/react-native-web/src/modules/emptyFunction/index.js b/packages/react-native-web/src/modules/emptyFunction/index.js new file mode 100644 index 0000000000..2387081507 --- /dev/null +++ b/packages/react-native-web/src/modules/emptyFunction/index.js @@ -0,0 +1,30 @@ +/* eslint-disable */ +'use strict'; + +function makeEmptyFunction(arg) { + return function () { + return arg; + }; +} +/** + * This function accepts and discards inputs; it has no side effects. This is + * primarily useful idiomatically for overridable function endpoints which + * always need to be callable, since JS lacks a null-call idiom ala Cocoa. + */ + +var emptyFunction = function emptyFunction() {}; + +emptyFunction.thatReturns = makeEmptyFunction; +emptyFunction.thatReturnsFalse = makeEmptyFunction(false); +emptyFunction.thatReturnsTrue = makeEmptyFunction(true); +emptyFunction.thatReturnsNull = makeEmptyFunction(null); + +emptyFunction.thatReturnsThis = function () { + return this; +}; + +emptyFunction.thatReturnsArgument = function (arg) { + return arg; +}; + +export default emptyFunction; diff --git a/packages/react-native-web/src/modules/warning/index.js b/packages/react-native-web/src/modules/warning/index.js new file mode 100644 index 0000000000..d83b3fe1a7 --- /dev/null +++ b/packages/react-native-web/src/modules/warning/index.js @@ -0,0 +1,68 @@ +/* eslint-disable */ +'use strict'; + +import emptyFunction from '../emptyFunction'; +/** + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ + +function printWarning(format) { + for ( + var _len = arguments.length, + args = new Array(_len > 1 ? _len - 1 : 0), + _key = 1; + _key < _len; + _key++ + ) { + args[_key - 1] = arguments[_key]; + } + + var argIndex = 0; + var message = + 'Warning: ' + + format.replace(/%s/g, function () { + return args[argIndex++]; + }); + + if (typeof console !== 'undefined') { + console.error(message); + } + + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} +} + +var warning = + process.env.NODE_ENV !== 'production' + ? function (condition, format) { + if (format === undefined) { + throw new Error( + '`warning(condition, format, ...args)` requires a warning ' + + 'message argument' + ); + } + + if (!condition) { + for ( + var _len2 = arguments.length, + args = new Array(_len2 > 2 ? _len2 - 2 : 0), + _key2 = 2; + _key2 < _len2; + _key2++ + ) { + args[_key2 - 2] = arguments[_key2]; + } + + printWarning.apply(void 0, [format].concat(args)); + } + } + : emptyFunction; + +export default warning;