@@ -33,7 +33,6 @@ import {
33
33
enableDebugTracing ,
34
34
enableSchedulingProfiler ,
35
35
enableCache ,
36
- enableUseRefAccessWarning ,
37
36
enableLazyContextPropagation ,
38
37
enableTransitionTracing ,
39
38
enableUseMemoCacheHook ,
@@ -2330,90 +2329,11 @@ function createEffectInstance(): EffectInstance {
2330
2329
return { destroy : undefined } ;
2331
2330
}
2332
2331
2333
- let stackContainsErrorMessage: boolean | null = null;
2334
-
2335
- function getCallerStackFrame(): string {
2336
- // eslint-disable-next-line react-internal/prod-error-codes
2337
- const stackFrames = new Error ( 'Error message' ) . stack . split ( '\n' ) ;
2338
-
2339
- // Some browsers (e.g. Chrome) include the error message in the stack
2340
- // but others (e.g. Firefox) do not.
2341
- if ( stackContainsErrorMessage === null ) {
2342
- stackContainsErrorMessage = stackFrames [ 0 ] . includes ( 'Error message' ) ;
2343
- }
2344
-
2345
- return stackContainsErrorMessage
2346
- ? stackFrames . slice ( 3 , 4 ) . join ( '\n' )
2347
- : stackFrames . slice ( 2 , 3 ) . join ( '\n' ) ;
2348
- }
2349
-
2350
2332
function mountRef< T > (initialValue: T): { current : T } {
2351
2333
const hook = mountWorkInProgressHook ( ) ;
2352
- if ( enableUseRefAccessWarning ) {
2353
- if ( __DEV__ ) {
2354
- // Support lazy initialization pattern shown in docs.
2355
- // We need to store the caller stack frame so that we don't warn on subsequent renders.
2356
- let hasBeenInitialized = initialValue != null ;
2357
- let lazyInitGetterStack = null ;
2358
- let didCheckForLazyInit = false ;
2359
-
2360
- // Only warn once per component+hook.
2361
- let didWarnAboutRead = false ;
2362
- let didWarnAboutWrite = false ;
2363
-
2364
- let current = initialValue ;
2365
- const ref = {
2366
- get current ( ) {
2367
- if ( ! hasBeenInitialized ) {
2368
- didCheckForLazyInit = true ;
2369
- lazyInitGetterStack = getCallerStackFrame ( ) ;
2370
- } else if ( currentlyRenderingFiber !== null && ! didWarnAboutRead ) {
2371
- if (
2372
- lazyInitGetterStack === null ||
2373
- lazyInitGetterStack !== getCallerStackFrame ( )
2374
- ) {
2375
- didWarnAboutRead = true ;
2376
- console . warn (
2377
- '%s: Unsafe read of a mutable value during render.\n\n' +
2378
- 'Reading from a ref during render is only safe if:\n' +
2379
- '1. The ref value has not been updated, or\n' +
2380
- '2. The ref holds a lazily-initialized value that is only set once.\n' ,
2381
- getComponentNameFromFiber ( currentlyRenderingFiber ) || 'Unknown' ,
2382
- ) ;
2383
- }
2384
- }
2385
- return current ;
2386
- } ,
2387
- set current ( value : any ) {
2388
- if ( currentlyRenderingFiber !== null && ! didWarnAboutWrite ) {
2389
- if ( hasBeenInitialized || ! didCheckForLazyInit ) {
2390
- didWarnAboutWrite = true ;
2391
- console . warn (
2392
- '%s: Unsafe write of a mutable value during render.\n\n' +
2393
- 'Writing to a ref during render is only safe if the ref holds ' +
2394
- 'a lazily-initialized value that is only set once.\n' ,
2395
- getComponentNameFromFiber ( currentlyRenderingFiber ) || 'Unknown' ,
2396
- ) ;
2397
- }
2398
- }
2399
-
2400
- hasBeenInitialized = true ;
2401
- current = value ;
2402
- } ,
2403
- } ;
2404
- Object . seal ( ref ) ;
2405
- hook . memoizedState = ref ;
2406
- return ref ;
2407
- } else {
2408
- const ref = { current : initialValue } ;
2409
- hook . memoizedState = ref ;
2410
- return ref ;
2411
- }
2412
- } else {
2413
- const ref = { current : initialValue } ;
2414
- hook . memoizedState = ref ;
2415
- return ref ;
2416
- }
2334
+ const ref = { current : initialValue } ;
2335
+ hook . memoizedState = ref ;
2336
+ return ref ;
2417
2337
}
2418
2338
2419
2339
function updateRef< T > (initialValue: T): { current : T } {
0 commit comments