Skip to content

Use a shared noop function from shared/noop #33154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/ReactDOMSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ' +
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/ReactDOMSharedInternalsFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,8 +25,6 @@ type ReactDOMInternals = {
) => null | Element | Text),
};

function noop() {}

const DefaultDispatcher: HostDispatcher = {
f /* flushSyncWork */: noop,
r /* requestFormReset */: noop,
Expand Down
14 changes: 6 additions & 8 deletions packages/react-dom/src/client/ReactDOMRootFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import {

import assign from 'shared/assign';

import noop from 'shared/noop';

// Provided by www
const ReactFiberErrorDialogWWW = require('ReactFiberErrorDialog');

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Thenable<any>>,
Expand Down Expand Up @@ -95,8 +97,6 @@ export function isThenableResolved(thenable: Thenable<mixed>): boolean {
return status === 'fulfilled' || status === 'rejected';
}

function noop(): void {}

export function trackUsedThenable<T>(
thenableState: ThenableState,
thenable: Thenable<T>,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
import {getFormState} from './ReactFizzServer';

import noop from 'shared/noop';

type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;

Expand Down Expand Up @@ -795,8 +797,6 @@ function useMemoCache(size: number): Array<mixed> {
return data;
}

function noop(): void {}

function clientHookNotSupported() {
throw new Error(
'Cannot use state or effect Hooks in renderToHTML because ' +
Expand Down
3 changes: 1 addition & 2 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -425,8 +426,6 @@ function defaultErrorHandler(error: mixed) {
return null;
}

function noop(): void {}

function RequestInstance(
this: $FlowFixMe,
resumableState: ResumableState,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFizzThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {
RejectedThenable,
} from 'shared/ReactTypes';

import noop from 'shared/noop';

export opaque type ThenableState = Array<Thenable<any>>;

// An error that is thrown (e.g. by `use`) to trigger Suspense. If we
Expand All @@ -40,8 +42,6 @@ export function createThenableState(): ThenableState {
return [];
}

function noop(): void {}

export function trackUsedThenable<T>(
thenableState: ThenableState,
thenable: Thenable<T>,
Expand Down
8 changes: 3 additions & 5 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -558,8 +558,6 @@ function RequestInstance(
pingedTasks.push(rootTask);
}

function noop() {}

export function createRequest(
model: ReactClientValue,
bundlerConfig: ClientManifest,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFlightThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {
RejectedThenable,
} from 'shared/ReactTypes';

import noop from 'shared/noop';

export opaque type ThenableState = Array<Thenable<any>>;

// An error that is thrown (e.g. by `use`) to trigger Suspense. If we
Expand All @@ -40,8 +42,6 @@ export function createThenableState(): ThenableState {
return [];
}

function noop(): void {}

export function trackUsedThenable<T>(
thenableState: ThenableState,
thenable: Thenable<T>,
Expand Down
6 changes: 3 additions & 3 deletions packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/ReactChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from 'shared/ReactTypes';

import isArray from 'shared/isArray';
import noop from 'shared/noop';
import {
getIteratorFn,
REACT_ELEMENT_TYPE,
Expand Down Expand Up @@ -82,8 +83,6 @@ function getElementKey(element: any, index: number): string {
return index.toString(36);
}

function noop() {}

function resolveThenable<T>(thenable: Thenable<T>): T {
switch (thenable.status) {
case 'fulfilled': {
Expand Down
8 changes: 3 additions & 5 deletions packages/react/src/ReactStartTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,9 +179,7 @@ export function startGestureTransition(
} finally {
ReactSharedInternals.T = prevTransition;
}
return function cancelGesture() {
// Noop
};
return noop;
}

function warnAboutTransitionSubscriptions(
Expand All @@ -200,5 +200,3 @@ function warnAboutTransitionSubscriptions(
}
}
}

function noop() {}
10 changes: 10 additions & 0 deletions packages/shared/noop.js
Original file line number Diff line number Diff line change
@@ -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() {}
Loading