diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index 8ae6021aec81e..16e3bceb4a6ec 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -63,6 +63,8 @@ import {validateProperties as validateInputProperties} from '../shared/ReactDOMN import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook'; import sanitizeURL from '../shared/sanitizeURL'; +import noop from 'shared/noop'; + import {trackHostMutation} from 'react-reconciler/src/ReactFiberMutationTracking'; import { @@ -319,8 +321,6 @@ function checkForUnmatchedText( return false; } -function noop() {} - export function trapClickOnNonInteractiveElement(node: HTMLElement) { // Mobile Safari does not fire properly bubble click events on // non-interactive elements, which means delegated click listeners do not diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 373f33ba03021..5aa26b26340d5 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -139,6 +139,9 @@ import {requestFormReset as requestFormResetOnFiber} from 'react-reconciler/src/ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; export {default as rendererVersion} from 'shared/ReactVersion'; + +import noop from 'shared/noop'; + export const rendererPackageName = 'react-dom'; export const extraDevToolsConfig = null; @@ -5628,16 +5631,14 @@ type SuspendedState = { }; let suspendedState: null | SuspendedState = null; -// We use a noop function when we begin suspending because if possible we want the -// waitfor step to finish synchronously. If it doesn't we'll return a function to -// provide the actual unsuspend function and that will get completed when the count -// hits zero or it will get cancelled if the root starts new work. -function noop() {} - export function startSuspendingCommit(): void { suspendedState = { stylesheets: null, count: 0, + // We use a noop function when we begin suspending because if possible we want the + // waitfor step to finish synchronously. If it doesn't we'll return a function to + // provide the actual unsuspend function and that will get completed when the count + // hits zero or it will get cancelled if the root starts new work. unsuspend: noop, }; } diff --git a/packages/react-dom/src/ReactDOMSharedInternals.js b/packages/react-dom/src/ReactDOMSharedInternals.js index ad603e83cb061..38a7d45dc5e9e 100644 --- a/packages/react-dom/src/ReactDOMSharedInternals.js +++ b/packages/react-dom/src/ReactDOMSharedInternals.js @@ -10,6 +10,8 @@ import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; import type {HostDispatcher} from './shared/ReactDOMTypes'; +import noop from 'shared/noop'; + // This should line up with NoEventPriority from react-reconciler/src/ReactEventPriorities // but we can't depend on the react-reconciler from this isomorphic code. export const NoEventPriority: EventPriority = (0: any); @@ -24,8 +26,6 @@ type ReactDOMInternals = { ) => null | Element | Text), }; -function noop() {} - function requestFormReset(element: HTMLFormElement) { throw new Error( 'Invalid form element. requestFormReset must be passed a form that was ' + diff --git a/packages/react-dom/src/ReactDOMSharedInternalsFB.js b/packages/react-dom/src/ReactDOMSharedInternalsFB.js index 4e425d5ddca79..03c1b4f11b778 100644 --- a/packages/react-dom/src/ReactDOMSharedInternalsFB.js +++ b/packages/react-dom/src/ReactDOMSharedInternalsFB.js @@ -12,6 +12,8 @@ import type {HostDispatcher} from './shared/ReactDOMTypes'; import {NoEventPriority} from 'react-reconciler/src/ReactEventPriorities'; +import noop from 'shared/noop'; + type ReactDOMInternals = { Events: [any, any, any, any, any, any], d /* ReactDOMCurrentDispatcher */: HostDispatcher, @@ -23,8 +25,6 @@ type ReactDOMInternals = { ) => null | Element | Text), }; -function noop() {} - const DefaultDispatcher: HostDispatcher = { f /* flushSyncWork */: noop, r /* requestFormReset */: noop, diff --git a/packages/react-dom/src/client/ReactDOMRootFB.js b/packages/react-dom/src/client/ReactDOMRootFB.js index c3c519650239c..66a373b0f6ca2 100644 --- a/packages/react-dom/src/client/ReactDOMRootFB.js +++ b/packages/react-dom/src/client/ReactDOMRootFB.js @@ -70,6 +70,8 @@ import { import assign from 'shared/assign'; +import noop from 'shared/noop'; + // Provided by www const ReactFiberErrorDialogWWW = require('ReactFiberErrorDialog'); @@ -206,14 +208,10 @@ function getReactRootElementInContainer(container: any) { } } -function noopOnRecoverableError() { - // This isn't reachable because onRecoverableError isn't called in the - // legacy API. -} - -function noopOnDefaultTransitionIndicator() { - // Noop -} +// This isn't reachable because onRecoverableError isn't called in the +// legacy API. +const noopOnRecoverableError = noop; +const noopOnDefaultTransitionIndicator = noop; function legacyCreateRootFromDOMContainer( container: Container, diff --git a/packages/react-reconciler/src/ReactFiberThenable.js b/packages/react-reconciler/src/ReactFiberThenable.js index d0d8ad84ee811..4f52131a649cd 100644 --- a/packages/react-reconciler/src/ReactFiberThenable.js +++ b/packages/react-reconciler/src/ReactFiberThenable.js @@ -18,6 +18,8 @@ import {getWorkInProgressRoot} from './ReactFiberWorkLoop'; import ReactSharedInternals from 'shared/ReactSharedInternals'; +import noop from 'shared/noop'; + opaque type ThenableStateDev = { didWarnAboutUncachedPromise: boolean, thenables: Array>, @@ -95,8 +97,6 @@ export function isThenableResolved(thenable: Thenable): boolean { return status === 'fulfilled' || status === 'rejected'; } -function noop(): void {} - export function trackUsedThenable( thenableState: ThenableState, thenable: Thenable, diff --git a/packages/react-server/src/ReactFizzHooks.js b/packages/react-server/src/ReactFizzHooks.js index 4ad33f9cea3f0..119c2a0778fc6 100644 --- a/packages/react-server/src/ReactFizzHooks.js +++ b/packages/react-server/src/ReactFizzHooks.js @@ -47,6 +47,8 @@ import { import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion'; import {getFormState} from './ReactFizzServer'; +import noop from 'shared/noop'; + type BasicStateAction = (S => S) | S; type Dispatch = A => void; @@ -795,8 +797,6 @@ function useMemoCache(size: number): Array { return data; } -function noop(): void {} - function clientHookNotSupported() { throw new Error( 'Cannot use state or effect Hooks in renderToHTML because ' + diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index 47f67d1eb46f1..f86dc8c9ce020 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -176,6 +176,7 @@ import { } from 'shared/ReactFeatureFlags'; import assign from 'shared/assign'; +import noop from 'shared/noop'; import getComponentNameFromType from 'shared/getComponentNameFromType'; import isArray from 'shared/isArray'; import {SuspenseException, getSuspendedThenable} from './ReactFizzThenable'; @@ -425,8 +426,6 @@ function defaultErrorHandler(error: mixed) { return null; } -function noop(): void {} - function RequestInstance( this: $FlowFixMe, resumableState: ResumableState, diff --git a/packages/react-server/src/ReactFizzThenable.js b/packages/react-server/src/ReactFizzThenable.js index f686b63d44db9..cb0ccfac69928 100644 --- a/packages/react-server/src/ReactFizzThenable.js +++ b/packages/react-server/src/ReactFizzThenable.js @@ -20,6 +20,8 @@ import type { RejectedThenable, } from 'shared/ReactTypes'; +import noop from 'shared/noop'; + export opaque type ThenableState = Array>; // An error that is thrown (e.g. by `use`) to trigger Suspense. If we @@ -40,8 +42,6 @@ export function createThenableState(): ThenableState { return []; } -function noop(): void {} - export function trackUsedThenable( thenableState: ThenableState, thenable: Thenable, diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index ed6d9c443b7bc..4048a855ef181 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -105,6 +105,8 @@ import {resolveOwner, setCurrentOwner} from './flight/ReactFlightCurrentOwner'; import {getOwnerStackByComponentInfoInDev} from 'shared/ReactComponentInfoStack'; import {resetOwnerStackLimit} from 'shared/ReactOwnerStackReset'; +import noop from 'shared/noop'; + import { callComponentInDEV, callLazyInitInDEV, @@ -443,9 +445,7 @@ function defaultErrorHandler(error: mixed) { // Don't transform to our wrapper } -function defaultPostponeHandler(reason: string) { - // Noop -} +const defaultPostponeHandler: (reason: string) => void = noop; function RequestInstance( this: $FlowFixMe, @@ -558,8 +558,6 @@ function RequestInstance( pingedTasks.push(rootTask); } -function noop() {} - export function createRequest( model: ReactClientValue, bundlerConfig: ClientManifest, diff --git a/packages/react-server/src/ReactFlightThenable.js b/packages/react-server/src/ReactFlightThenable.js index 89912a7dd5d20..47e7b914da176 100644 --- a/packages/react-server/src/ReactFlightThenable.js +++ b/packages/react-server/src/ReactFlightThenable.js @@ -20,6 +20,8 @@ import type { RejectedThenable, } from 'shared/ReactTypes'; +import noop from 'shared/noop'; + export opaque type ThenableState = Array>; // An error that is thrown (e.g. by `use`) to trigger Suspense. If we @@ -40,8 +42,6 @@ export function createThenableState(): ThenableState { return []; } -function noop(): void {} - export function trackUsedThenable( thenableState: ThenableState, thenable: Thenable, diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index b096f59292ceb..dd5b4e8c97247 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -60,9 +60,9 @@ import { disableLegacyMode, } from 'shared/ReactFeatureFlags'; -function defaultOnDefaultTransitionIndicator(): void | (() => void) { - // Noop -} +import noop from 'shared/noop'; + +const defaultOnDefaultTransitionIndicator: () => void | (() => void) = noop; // $FlowFixMe[prop-missing]: This is only in the development export. const act = React.act; diff --git a/packages/react/src/ReactChildren.js b/packages/react/src/ReactChildren.js index 8fcc83dea4b17..9b474ac832f2b 100644 --- a/packages/react/src/ReactChildren.js +++ b/packages/react/src/ReactChildren.js @@ -16,6 +16,7 @@ import type { } from 'shared/ReactTypes'; import isArray from 'shared/isArray'; +import noop from 'shared/noop'; import { getIteratorFn, REACT_ELEMENT_TYPE, @@ -82,8 +83,6 @@ function getElementKey(element: any, index: number): string { return index.toString(36); } -function noop() {} - function resolveThenable(thenable: Thenable): T { switch (thenable.status) { case 'fulfilled': { diff --git a/packages/react/src/ReactStartTransition.js b/packages/react/src/ReactStartTransition.js index 71efa5d1c253a..3e353a3b61536 100644 --- a/packages/react/src/ReactStartTransition.js +++ b/packages/react/src/ReactStartTransition.js @@ -25,6 +25,8 @@ import { import reportGlobalError from 'shared/reportGlobalError'; +import noop from 'shared/noop'; + export type Transition = { types: null | TransitionTypes, // enableViewTransition gesture: null | GestureProvider, // enableGestureTransition @@ -177,9 +179,7 @@ export function startGestureTransition( } finally { ReactSharedInternals.T = prevTransition; } - return function cancelGesture() { - // Noop - }; + return noop; } function warnAboutTransitionSubscriptions( @@ -200,5 +200,3 @@ function warnAboutTransitionSubscriptions( } } } - -function noop() {} diff --git a/packages/shared/noop.js b/packages/shared/noop.js new file mode 100644 index 0000000000000..0188292909d9e --- /dev/null +++ b/packages/shared/noop.js @@ -0,0 +1,10 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +export default function noop() {}