Warn when a callback ref returns a function (#23145)
Dan Abramov committed
Jan 20, 2022 at 15:18 UTC
e4894025570ebbe5955b4e4b226dd900e17c93e7
13 files changed
+4
-30
packages/react-dom/src/__tests__/refs-test.js
-1
@@ -352,7 +352,6 @@ describe('ref swapping', () => {
352
);
353
});
354
355
- // @gate !__DEV__ || warnAboutCallbackRefReturningFunction
355
it('should warn about callback refs returning a function', () => {
356
const container = document.createElement('div');
357
expect(() => {
packages/react-reconciler/src/ReactFiberCommitWork.new.js
+2
-9
@@ -39,7 +39,6 @@ import {
39
deletedTreeCleanUpLevel,
40
enableSuspenseLayoutEffectSemantics,
41
enableUpdaterTracking,
42
- warnAboutCallbackRefReturningFunction,
42
enableCache,
43
} from 'shared/ReactFeatureFlags';
44
import {
@@ -286,10 +285,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
285
captureCommitPhaseError(current, nearestMountedAncestor, error);
286
}
287
if (__DEV__) {
289
- if (
290
- warnAboutCallbackRefReturningFunction &&
291
- typeof retVal === 'function'
292
- ) {
288
+ if (typeof retVal === 'function') {
289
console.error(
290
'Unexpected return value from a callback ref in %s. ' +
291
'A callback ref should not return a function.',
@@ -1151,10 +1147,7 @@ function commitAttachRef(finishedWork: Fiber) {
1147
retVal = ref(instanceToUse);
1148
}
1149
if (__DEV__) {
1154
- if (
1155
- warnAboutCallbackRefReturningFunction &&
1156
- typeof retVal === 'function'
1157
- ) {
1150
+ if (typeof retVal === 'function') {
1151
console.error(
1152
'Unexpected return value from a callback ref in %s. ' +
1153
'A callback ref should not return a function.',
packages/react-reconciler/src/ReactFiberCommitWork.old.js
+2
-9
@@ -39,7 +39,6 @@ import {
39
deletedTreeCleanUpLevel,
40
enableSuspenseLayoutEffectSemantics,
41
enableUpdaterTracking,
42
- warnAboutCallbackRefReturningFunction,
42
enableCache,
43
} from 'shared/ReactFeatureFlags';
44
import {
@@ -286,10 +285,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
285
captureCommitPhaseError(current, nearestMountedAncestor, error);
286
}
287
if (__DEV__) {
289
- if (
290
- warnAboutCallbackRefReturningFunction &&
291
- typeof retVal === 'function'
292
- ) {
288
+ if (typeof retVal === 'function') {
289
console.error(
290
'Unexpected return value from a callback ref in %s. ' +
291
'A callback ref should not return a function.',
@@ -1151,10 +1147,7 @@ function commitAttachRef(finishedWork: Fiber) {
1147
retVal = ref(instanceToUse);
1148
}
1149
if (__DEV__) {
1154
- if (
1155
- warnAboutCallbackRefReturningFunction &&
1156
- typeof retVal === 'function'
1157
- ) {
1150
+ if (typeof retVal === 'function') {
1151
console.error(
1152
'Unexpected return value from a callback ref in %s. ' +
1153
'A callback ref should not return a function.',
packages/shared/ReactFeatureFlags.js
-2
@@ -178,8 +178,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
178
179
export const enableUseRefAccessWarning = false;
180
181
-export const warnAboutCallbackRefReturningFunction = false;
182
-
181
export const disableSchedulerTimeoutInWorkLoop = false;
182
183
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -66,7 +66,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
66
export const enableStrictEffects = __DEV__;
67
export const createRootStrictEffectsByDefault = false;
68
export const enableUseRefAccessWarning = false;
69
-export const warnAboutCallbackRefReturningFunction = false;
69
70
export const disableSchedulerTimeoutInWorkLoop = false;
71
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
57
export const enableStrictEffects = false;
58
export const createRootStrictEffectsByDefault = false;
59
export const enableUseRefAccessWarning = false;
60
-export const warnAboutCallbackRefReturningFunction = false;
60
61
export const disableSchedulerTimeoutInWorkLoop = false;
62
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
57
export const enableStrictEffects = false;
58
export const createRootStrictEffectsByDefault = false;
59
export const enableUseRefAccessWarning = false;
60
-export const warnAboutCallbackRefReturningFunction = false;
60
61
export const disableSchedulerTimeoutInWorkLoop = false;
62
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
-1
@@ -56,7 +56,6 @@ export const enableClientRenderFallbackOnHydrationMismatch = true;
56
export const enableStrictEffects = false;
57
export const createRootStrictEffectsByDefault = false;
58
export const enableUseRefAccessWarning = false;
59
-export const warnAboutCallbackRefReturningFunction = false;
59
60
export const disableSchedulerTimeoutInWorkLoop = false;
61
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
57
export const enableStrictEffects = true;
58
export const createRootStrictEffectsByDefault = false;
59
export const enableUseRefAccessWarning = false;
60
-export const warnAboutCallbackRefReturningFunction = false;
60
61
export const disableSchedulerTimeoutInWorkLoop = false;
62
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.testing.js
-1
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
57
export const enableStrictEffects = false;
58
export const createRootStrictEffectsByDefault = false;
59
export const enableUseRefAccessWarning = false;
60
-export const warnAboutCallbackRefReturningFunction = false;
60
61
export const disableSchedulerTimeoutInWorkLoop = false;
62
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.testing.www.js
-1
@@ -57,7 +57,6 @@ export const deferRenderPhaseUpdateToNextBatch = false;
57
export const enableStrictEffects = false;
58
export const createRootStrictEffectsByDefault = false;
59
export const enableUseRefAccessWarning = false;
60
-export const warnAboutCallbackRefReturningFunction = false;
60
61
export const disableSchedulerTimeoutInWorkLoop = false;
62
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.www-dynamic.js
-1
@@ -19,7 +19,6 @@ export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
19
export const enableLegacyFBSupport = __VARIANT__;
20
export const skipUnmountedBoundaries = __VARIANT__;
21
export const enableUseRefAccessWarning = __VARIANT__;
22
-export const warnAboutCallbackRefReturningFunction = __VARIANT__;
22
export const deletedTreeCleanUpLevel = __VARIANT__ ? 3 : 1;
23
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
24
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -67,7 +67,6 @@ export const warnAboutDefaultPropsOnFunctionComponents = false;
67
export const enableGetInspectorDataForInstanceInProduction = false;
68
export const enableSuspenseServerRenderer = true;
69
export const enableSelectiveHydration = true;
70
-export const warnAboutCallbackRefReturningFunction = true;
70
71
export const enableLazyElements = true;
72
export const enableCache = true;