Warn when a callback ref returns a function (#23145)

This commit is contained in:
Dan Abramov
2022-01-20 15:18:38 +00:00
committed by GitHub
parent 05a55a4b09
commit e489402557
13 changed files with 4 additions and 30 deletions
-1
View File
@@ -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.',
-2
View File
@@ -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;