Skip to content

Commit 551985a

Browse files
author
Brian Vaughn
committed
PR feedback
• Changed tests to use pragma • Renamed feature flag
1 parent 32e5c1b commit 551985a

13 files changed

+45
-42
lines changed

packages/react-reconciler/src/ReactFiberHooks.new.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
enableNewReconciler,
2828
decoupleUpdatePriorityFromScheduler,
2929
enableDoubleInvokingEffects,
30-
enableUseRefMutationWarning,
30+
enableUseRefAccessWarning,
3131
} from 'shared/ReactFeatureFlags';
3232

3333
import {
@@ -1216,7 +1216,7 @@ function getCallerStackFrame(): string {
12161216

12171217
function mountRef<T>(initialValue: T): {|current: T|} {
12181218
const hook = mountWorkInProgressHook();
1219-
if (enableUseRefMutationWarning) {
1219+
if (enableUseRefAccessWarning) {
12201220
if (__DEV__) {
12211221
// Support lazy initialization pattern shown in docs.
12221222
// We need to store the caller stack frame so that we don't warn on subsequent renders.

packages/react-reconciler/src/ReactFiberHooks.old.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
enableSchedulingProfiler,
2727
enableNewReconciler,
2828
decoupleUpdatePriorityFromScheduler,
29-
enableUseRefMutationWarning,
29+
enableUseRefAccessWarning,
3030
} from 'shared/ReactFeatureFlags';
3131

3232
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
@@ -1194,7 +1194,7 @@ function getCallerStackFrame(): string {
11941194

11951195
function mountRef<T>(initialValue: T): {|current: T|} {
11961196
const hook = mountWorkInProgressHook();
1197-
if (enableUseRefMutationWarning) {
1197+
if (enableUseRefAccessWarning) {
11981198
if (__DEV__) {
11991199
// Support lazy initialization pattern shown in docs.
12001200
// We need to store the caller stack frame so that we don't warn on subsequent renders.

packages/react-reconciler/src/__tests__/useRef-test.internal.js

+31-28
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ describe('useRef', () => {
3030

3131
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
3232
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
33-
ReactFeatureFlags.enableUseRefMutationWarning = true;
3433

3534
act = ReactNoop.act;
3635
useCallback = React.useCallback;
@@ -104,32 +103,6 @@ describe('useRef', () => {
104103
expect(Scheduler).toHaveYielded(['ping: 6']);
105104
});
106105

107-
it('should never warn when attaching to children', () => {
108-
class Component extends React.Component {
109-
render() {
110-
return null;
111-
}
112-
}
113-
114-
function Example({phase}) {
115-
const hostRef = useRef();
116-
const classRef = useRef();
117-
return (
118-
<>
119-
<div key={`host-${phase}`} ref={hostRef} />
120-
<Component key={`class-${phase}`} ref={classRef} />
121-
</>
122-
);
123-
}
124-
125-
act(() => {
126-
ReactNoop.render(<Example phase="mount" />);
127-
});
128-
act(() => {
129-
ReactNoop.render(<Example phase="update" />);
130-
});
131-
});
132-
133106
it('should return the same ref during re-renders', () => {
134107
function Counter() {
135108
const ref = useRef('val');
@@ -155,6 +128,33 @@ describe('useRef', () => {
155128
});
156129

157130
if (__DEV__) {
131+
it('should never warn when attaching to children', () => {
132+
class Component extends React.Component {
133+
render() {
134+
return null;
135+
}
136+
}
137+
138+
function Example({phase}) {
139+
const hostRef = useRef();
140+
const classRef = useRef();
141+
return (
142+
<>
143+
<div key={`host-${phase}`} ref={hostRef} />
144+
<Component key={`class-${phase}`} ref={classRef} />
145+
</>
146+
);
147+
}
148+
149+
act(() => {
150+
ReactNoop.render(<Example phase="mount" />);
151+
});
152+
act(() => {
153+
ReactNoop.render(<Example phase="update" />);
154+
});
155+
});
156+
157+
// @gate enableUseRefAccessWarning
158158
it('should warn about reads during render', () => {
159159
function Example() {
160160
const ref = useRef(123);
@@ -215,7 +215,8 @@ describe('useRef', () => {
215215
});
216216
});
217217

218-
it('should not warn about unconditional lazy init during render', () => {
218+
// @gate enableUseRefAccessWarning
219+
it('should warn about unconditional lazy init during render', () => {
219220
function Example() {
220221
const ref1 = useRef(null);
221222
const ref2 = useRef(undefined);
@@ -255,6 +256,7 @@ describe('useRef', () => {
255256
});
256257
});
257258

259+
// @gate enableUseRefAccessWarning
258260
it('should warn about reads to ref after lazy init pattern', () => {
259261
function Example() {
260262
const ref1 = useRef(null);
@@ -288,6 +290,7 @@ describe('useRef', () => {
288290
});
289291
});
290292

293+
// @gate enableUseRefAccessWarning
291294
it('should warn about writes to ref after lazy init pattern', () => {
292295
function Example() {
293296
const ref1 = useRef(null);

packages/shared/ReactFeatureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@ export const enableDiscreteEventFlushingChange = false;
135135

136136
export const enableDoubleInvokingEffects = false;
137137

138-
export const enableUseRefMutationWarning = false;
138+
export const enableUseRefAccessWarning = false;

packages/shared/forks/ReactFeatureFlags.native-fb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5151
export const enableDiscreteEventFlushingChange = false;
5252

5353
export const enableDoubleInvokingEffects = false;
54-
export const enableUseRefMutationWarning = false;
54+
export const enableUseRefAccessWarning = false;
5555

5656
// Flow magic to verify the exports of this file match the original version.
5757
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.native-oss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = false;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = false;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = false;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = false;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.testing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = false;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.testing.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const decoupleUpdatePriorityFromScheduler = false;
5050
export const enableDiscreteEventFlushingChange = true;
5151

5252
export const enableDoubleInvokingEffects = false;
53-
export const enableUseRefMutationWarning = false;
53+
export const enableUseRefAccessWarning = false;
5454

5555
// Flow magic to verify the exports of this file match the original version.
5656
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ export const enableTrustedTypesIntegration = false;
4848
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
4949

5050
export const enableDoubleInvokingEffects = false;
51-
export const enableUseRefMutationWarning = false;
51+
export const enableUseRefAccessWarning = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.www.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const {
2828
enableDebugTracing,
2929
skipUnmountedBoundaries,
3030
enableDoubleInvokingEffects,
31-
enableUseRefMutationWarning,
31+
enableUseRefAccessWarning,
3232
} = dynamicFeatureFlags;
3333

3434
// On WWW, __EXPERIMENTAL__ is used for a new modern build.

0 commit comments

Comments
 (0)