mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Warn when a callback ref returns a function (#23145)
This commit is contained in:
@@ -352,7 +352,6 @@ describe('ref swapping', () => {
|
||||
);
|
||||
});
|
||||
|
||||
// @gate !__DEV__ || warnAboutCallbackRefReturningFunction
|
||||
it('should warn about callback refs returning a function', () => {
|
||||
const container = document.createElement('div');
|
||||
expect(() => {
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
deletedTreeCleanUpLevel,
|
||||
enableSuspenseLayoutEffectSemantics,
|
||||
enableUpdaterTracking,
|
||||
warnAboutCallbackRefReturningFunction,
|
||||
enableCache,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
import {
|
||||
@@ -286,10 +285,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
|
||||
captureCommitPhaseError(current, nearestMountedAncestor, error);
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (
|
||||
warnAboutCallbackRefReturningFunction &&
|
||||
typeof retVal === 'function'
|
||||
) {
|
||||
if (typeof retVal === 'function') {
|
||||
console.error(
|
||||
'Unexpected return value from a callback ref in %s. ' +
|
||||
'A callback ref should not return a function.',
|
||||
@@ -1151,10 +1147,7 @@ function commitAttachRef(finishedWork: Fiber) {
|
||||
retVal = ref(instanceToUse);
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (
|
||||
warnAboutCallbackRefReturningFunction &&
|
||||
typeof retVal === 'function'
|
||||
) {
|
||||
if (typeof retVal === 'function') {
|
||||
console.error(
|
||||
'Unexpected return value from a callback ref in %s. ' +
|
||||
'A callback ref should not return a function.',
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
deletedTreeCleanUpLevel,
|
||||
enableSuspenseLayoutEffectSemantics,
|
||||
enableUpdaterTracking,
|
||||
warnAboutCallbackRefReturningFunction,
|
||||
enableCache,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
import {
|
||||
@@ -286,10 +285,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
|
||||
captureCommitPhaseError(current, nearestMountedAncestor, error);
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (
|
||||
warnAboutCallbackRefReturningFunction &&
|
||||
typeof retVal === 'function'
|
||||
) {
|
||||
if (typeof retVal === 'function') {
|
||||
console.error(
|
||||
'Unexpected return value from a callback ref in %s. ' +
|
||||
'A callback ref should not return a function.',
|
||||
@@ -1151,10 +1147,7 @@ function commitAttachRef(finishedWork: Fiber) {
|
||||
retVal = ref(instanceToUse);
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (
|
||||
warnAboutCallbackRefReturningFunction &&
|
||||
typeof retVal === 'function'
|
||||
) {
|
||||
if (typeof retVal === 'function') {
|
||||
console.error(
|
||||
'Unexpected return value from a callback ref in %s. ' +
|
||||
'A callback ref should not return a function.',
|
||||
|
||||
@@ -178,8 +178,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
|
||||
export const enableUseRefAccessWarning = false;
|
||||
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -66,7 +66,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = __DEV__;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = false;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = false;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -56,7 +56,6 @@ export const enableClientRenderFallbackOnHydrationMismatch = true;
|
||||
export const enableStrictEffects = false;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = true;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = false;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
|
||||
export const enableStrictEffects = false;
|
||||
export const createRootStrictEffectsByDefault = false;
|
||||
export const enableUseRefAccessWarning = false;
|
||||
export const warnAboutCallbackRefReturningFunction = false;
|
||||
|
||||
export const disableSchedulerTimeoutInWorkLoop = false;
|
||||
export const enableLazyContextPropagation = false;
|
||||
|
||||
@@ -19,7 +19,6 @@ export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
|
||||
export const enableLegacyFBSupport = __VARIANT__;
|
||||
export const skipUnmountedBoundaries = __VARIANT__;
|
||||
export const enableUseRefAccessWarning = __VARIANT__;
|
||||
export const warnAboutCallbackRefReturningFunction = __VARIANT__;
|
||||
export const deletedTreeCleanUpLevel = __VARIANT__ ? 3 : 1;
|
||||
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
|
||||
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
|
||||
|
||||
@@ -67,7 +67,6 @@ export const warnAboutDefaultPropsOnFunctionComponents = false;
|
||||
export const enableGetInspectorDataForInstanceInProduction = false;
|
||||
export const enableSuspenseServerRenderer = true;
|
||||
export const enableSelectiveHydration = true;
|
||||
export const warnAboutCallbackRefReturningFunction = true;
|
||||
|
||||
export const enableLazyElements = true;
|
||||
export const enableCache = true;
|
||||
|
||||
Reference in New Issue
Block a user