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