@@ -16,7 +16,6 @@ let assertLog;
1616let useMemo ;
1717let useState ;
1818let useMemoCache ;
19- let waitForThrow ;
2019let MemoCacheSentinel ;
2120let ErrorBoundary ;
2221
@@ -32,7 +31,6 @@ describe('useMemoCache()', () => {
3231 useMemo = React . useMemo ;
3332 useMemoCache = require ( 'react/compiler-runtime' ) . c ;
3433 useState = React . useState ;
35- waitForThrow = require ( 'internal-test-utils' ) . waitForThrow ;
3634 MemoCacheSentinel = Symbol . for ( 'react.memo_cache_sentinel' ) ;
3735
3836 class _ErrorBoundary extends React . Component {
@@ -577,11 +575,7 @@ describe('useMemoCache()', () => {
577575 'Some expensive processing... [A2]' ,
578576 'Suspend! [chunkB]' ,
579577
580- ...( gate ( 'enableSiblingPrerendering' )
581- ? gate ( 'enableNoCloningMemoCache' )
582- ? [ 'Suspend! [chunkB]' ]
583- : [ 'Some expensive processing... [A2]' , 'Suspend! [chunkB]' ]
584- : [ ] ) ,
578+ ...( gate ( 'enableSiblingPrerendering' ) ? [ 'Suspend! [chunkB]' ] : [ ] ) ,
585579 ] ) ;
586580
587581 // The second chunk hasn't loaded yet, so we're still showing the
@@ -600,26 +594,13 @@ describe('useMemoCache()', () => {
600594 await act ( ( ) => setInput ( 'hi!' ) ) ;
601595
602596 // Once the input has updated, we go back to rendering the transition.
603- if ( gate ( flags => flags . enableNoCloningMemoCache ) ) {
604- // We did not have process the first chunk again. We reused the
605- // computation from the earlier attempt.
606- assertLog ( [
607- 'Suspend! [chunkB]' ,
608-
609- ...( gate ( 'enableSiblingPrerendering' ) ? [ 'Suspend! [chunkB]' ] : [ ] ) ,
610- ] ) ;
611- } else {
612- // Because we clone/reset the memo cache after every aborted attempt, we
613- // must process the first chunk again.
614- assertLog ( [
615- 'Some expensive processing... [A2]' ,
616- 'Suspend! [chunkB]' ,
617-
618- ...( gate ( 'enableSiblingPrerendering' )
619- ? [ 'Some expensive processing... [A2]' , 'Suspend! [chunkB]' ]
620- : [ ] ) ,
621- ] ) ;
622- }
597+ // We did not have process the first chunk again. We reused the
598+ // computation from the earlier attempt.
599+ assertLog ( [
600+ 'Suspend! [chunkB]' ,
601+
602+ ...( gate ( 'enableSiblingPrerendering' ) ? [ 'Suspend! [chunkB]' ] : [ ] ) ,
603+ ] ) ;
623604
624605 expect ( root ) . toMatchRenderedOutput (
625606 < >
@@ -630,18 +611,9 @@ describe('useMemoCache()', () => {
630611
631612 // Finish loading the data.
632613 await act ( ( ) => updatedChunkB . resolve ( 'B2' ) ) ;
633- if ( gate ( flags => flags . enableNoCloningMemoCache ) ) {
634- // We did not have process the first chunk again. We reused the
635- // computation from the earlier attempt.
636- assertLog ( [ ] ) ;
637- } else {
638- // Because we clone/reset the memo cache after every aborted attempt, we
639- // must process the first chunk again.
640- //
641- // That's three total times we've processed the first chunk, compared to
642- // just once when enableNoCloningMemoCache is on.
643- assertLog ( [ 'Some expensive processing... [A2]' ] ) ;
644- }
614+ // We did not have process the first chunk again. We reused the
615+ // computation from the earlier attempt.
616+ assertLog ( [ ] ) ;
645617 expect ( root ) . toMatchRenderedOutput (
646618 < >
647619 < div > Input: hi!</ div >
@@ -667,7 +639,7 @@ describe('useMemoCache()', () => {
667639 }
668640
669641 // Baseline / source code
670- function useUserMemo ( value ) {
642+ function useManualMemo ( value ) {
671643 return useMemo ( ( ) => [ value ] , [ value ] ) ;
672644 }
673645
@@ -683,24 +655,22 @@ describe('useMemoCache()', () => {
683655 }
684656
685657 /**
686- * Test case: note that the initial render never completes
658+ * Test with useMemoCache
687659 */
688660 let root = ReactNoop . createRoot ( ) ;
689- const IncorrectInfiniteComponent = makeComponent ( useCompilerMemo ) ;
690- root . render ( < IncorrectInfiniteComponent value = { 2 } /> ) ;
691- await waitForThrow (
692- 'Too many re-renders. React limits the number of renders to prevent ' +
693- 'an infinite loop.' ,
694- ) ;
661+ const CompilerMemoComponent = makeComponent ( useCompilerMemo ) ;
662+ await act ( ( ) => {
663+ root . render ( < CompilerMemoComponent value = { 2 } /> ) ;
664+ } ) ;
665+ expect ( root ) . toMatchRenderedOutput ( < div > 2</ div > ) ;
695666
696667 /**
697- * Baseline test: initial render is expected to complete after a retry
698- * (triggered by the setState)
668+ * Test with useMemo
699669 */
700670 root = ReactNoop . createRoot ( ) ;
701- const CorrectComponent = makeComponent ( useUserMemo ) ;
671+ const HookMemoComponent = makeComponent ( useManualMemo ) ;
702672 await act ( ( ) => {
703- root . render ( < CorrectComponent value = { 2 } /> ) ;
673+ root . render ( < HookMemoComponent value = { 2 } /> ) ;
704674 } ) ;
705675 expect ( root ) . toMatchRenderedOutput ( < div > 2</ div > ) ;
706676 } ) ;
0 commit comments