@@ -30,7 +30,6 @@ describe('useRef', () => {
30
30
31
31
const ReactFeatureFlags = require ( 'shared/ReactFeatureFlags' ) ;
32
32
ReactFeatureFlags . debugRenderPhaseSideEffectsForStrictMode = false ;
33
- ReactFeatureFlags . enableUseRefMutationWarning = true ;
34
33
35
34
act = ReactNoop . act ;
36
35
useCallback = React . useCallback ;
@@ -104,32 +103,6 @@ describe('useRef', () => {
104
103
expect ( Scheduler ) . toHaveYielded ( [ 'ping: 6' ] ) ;
105
104
} ) ;
106
105
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
-
133
106
it ( 'should return the same ref during re-renders' , ( ) => {
134
107
function Counter ( ) {
135
108
const ref = useRef ( 'val' ) ;
@@ -155,6 +128,33 @@ describe('useRef', () => {
155
128
} ) ;
156
129
157
130
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
158
158
it ( 'should warn about reads during render' , ( ) => {
159
159
function Example ( ) {
160
160
const ref = useRef ( 123 ) ;
@@ -215,7 +215,8 @@ describe('useRef', () => {
215
215
} ) ;
216
216
} ) ;
217
217
218
- it ( 'should not warn about unconditional lazy init during render' , ( ) => {
218
+ // @gate enableUseRefAccessWarning
219
+ it ( 'should warn about unconditional lazy init during render' , ( ) => {
219
220
function Example ( ) {
220
221
const ref1 = useRef ( null ) ;
221
222
const ref2 = useRef ( undefined ) ;
@@ -255,6 +256,7 @@ describe('useRef', () => {
255
256
} ) ;
256
257
} ) ;
257
258
259
+ // @gate enableUseRefAccessWarning
258
260
it ( 'should warn about reads to ref after lazy init pattern' , ( ) => {
259
261
function Example ( ) {
260
262
const ref1 = useRef ( null ) ;
@@ -288,6 +290,7 @@ describe('useRef', () => {
288
290
} ) ;
289
291
} ) ;
290
292
293
+ // @gate enableUseRefAccessWarning
291
294
it ( 'should warn about writes to ref after lazy init pattern' , ( ) => {
292
295
function Example ( ) {
293
296
const ref1 = useRef ( null ) ;
0 commit comments