File tree Expand file tree Collapse file tree 1 file changed +21
-16
lines changed
compiler/packages/react-compiler-runtime/src Expand file tree Collapse file tree 1 file changed +21
-16
lines changed Original file line number Diff line number Diff line change @@ -19,22 +19,27 @@ const ReactSecretInternals =
19
19
type MemoCache = Array < number | typeof $empty > ;
20
20
21
21
const $empty = Symbol . for ( 'react.memo_cache_sentinel' ) ;
22
- /**
23
- * DANGER: this hook is NEVER meant to be called directly!
24
- **/
25
- export function c ( size : number ) {
26
- return React . useState ( ( ) => {
27
- const $ = new Array ( size ) ;
28
- for ( let ii = 0 ; ii < size ; ii ++ ) {
29
- $ [ ii ] = $empty ;
30
- }
31
- // This symbol is added to tell the react devtools that this array is from
32
- // useMemoCache.
33
- // @ts -ignore
34
- $ [ $empty ] = true ;
35
- return $ ;
36
- } ) [ 0 ] ;
37
- }
22
+
23
+ // Re-export React.c if present, otherwise fallback to the userspace polyfill for versions of React
24
+ // < 19.
25
+ export const c =
26
+ // @ts -expect-error
27
+ typeof React . __COMPILER_RUNTIME ?. c === 'function'
28
+ ? // @ts -expect-error
29
+ React . __COMPILER_RUNTIME . c
30
+ : function c ( size : number ) {
31
+ return React . useMemo < Array < unknown > > ( ( ) => {
32
+ const $ = new Array ( size ) ;
33
+ for ( let ii = 0 ; ii < size ; ii ++ ) {
34
+ $ [ ii ] = $empty ;
35
+ }
36
+ // This symbol is added to tell the react devtools that this array is from
37
+ // useMemoCache.
38
+ // @ts -ignore
39
+ $ [ $empty ] = true ;
40
+ return $ ;
41
+ } , [ ] ) ;
42
+ } ;
38
43
39
44
const LazyGuardDispatcher : { [ key : string ] : ( ...args : Array < any > ) => any } = { } ;
40
45
[
You can’t perform that action at this time.
0 commit comments