@@ -24,6 +24,35 @@ describe('Store', () => {
2424 let store ;
2525 let withErrorsOrWarningsIgnored ;
2626
27+ function readValue ( promise ) {
28+ if ( typeof React . use === 'function' ) {
29+ return React . use ( promise ) ;
30+ }
31+
32+ // Support for React < 19.0
33+ switch ( promise . status ) {
34+ case 'fulfilled' :
35+ return promise . value ;
36+ case 'rejected' :
37+ throw promise . reason ;
38+ case 'pending' :
39+ throw promise ;
40+ default :
41+ promise . status = 'pending' ;
42+ promise . then (
43+ value => {
44+ promise . status = 'fulfilled' ;
45+ promise . value = value ;
46+ } ,
47+ reason => {
48+ promise . status = 'rejected' ;
49+ promise . reason = reason ;
50+ } ,
51+ ) ;
52+ throw promise ;
53+ }
54+ }
55+
2756 beforeAll ( ( ) => {
2857 // JSDDOM doesn't implement getClientRects so we're just faking one for testing purposes
2958 Element . prototype . getClientRects = function ( this : Element ) {
@@ -107,11 +136,7 @@ describe('Store', () => {
107136 let Dynamic = null ;
108137 const Owner = ( ) => {
109138 Dynamic = < Child /> ;
110- if ( React . use ) {
111- React . use ( promise ) ;
112- } else {
113- throw promise ;
114- }
139+ readValue ( promise ) ;
115140 } ;
116141 const Parent = ( ) => {
117142 return Dynamic ;
@@ -462,12 +487,9 @@ describe('Store', () => {
462487 // @reactVersion >= 18.0
463488 it ( 'should display Suspense nodes properly in various states' , async ( ) => {
464489 const Loading = ( ) => < div > Loading...</ div > ;
490+ const never = new Promise ( ( ) => { } ) ;
465491 const SuspendingComponent = ( ) => {
466- if ( React . use ) {
467- React . use ( new Promise ( ( ) => { } ) ) ;
468- } else {
469- throw new Promise ( ( ) => { } ) ;
470- }
492+ readValue ( never ) ;
471493 } ;
472494 const Component = ( ) => {
473495 return < div > Hello</ div > ;
@@ -514,12 +536,9 @@ describe('Store', () => {
514536 it ( 'should support nested Suspense nodes' , async ( ) => {
515537 const Component = ( ) => null ;
516538 const Loading = ( ) => < div > Loading...</ div > ;
539+ const never = new Promise ( ( ) => { } ) ;
517540 const Never = ( ) => {
518- if ( React . use ) {
519- React . use ( new Promise ( ( ) => { } ) ) ;
520- } else {
521- throw new Promise ( ( ) => { } ) ;
522- }
541+ readValue ( never ) ;
523542 } ;
524543
525544 const Wrapper = ( {
@@ -1019,12 +1038,9 @@ describe('Store', () => {
10191038
10201039 it ( 'should display a partially rendered SuspenseList' , async ( ) => {
10211040 const Loading = ( ) => < div > Loading...</ div > ;
1041+ const never = new Promise ( ( ) => { } ) ;
10221042 const SuspendingComponent = ( ) => {
1023- if ( React . use ) {
1024- React . use ( new Promise ( ( ) => { } ) ) ;
1025- } else {
1026- throw new Promise ( ( ) => { } ) ;
1027- }
1043+ readValue ( never ) ;
10281044 } ;
10291045 const Component = ( ) => {
10301046 return < div > Hello</ div > ;
@@ -1379,12 +1395,9 @@ describe('Store', () => {
13791395 // @reactVersion >= 18.0
13801396 it ( 'should display Suspense nodes properly in various states' , async ( ) => {
13811397 const Loading = ( ) => < div > Loading...</ div > ;
1398+ const never = new Promise ( ( ) => { } ) ;
13821399 const SuspendingComponent = ( ) => {
1383- if ( React . use ) {
1384- React . use ( new Promise ( ( ) => { } ) ) ;
1385- } else {
1386- throw new Promise ( ( ) => { } ) ;
1387- }
1400+ readValue ( never ) ;
13881401 } ;
13891402 const Component = ( ) => {
13901403 return < div > Hello</ div > ;
@@ -2081,6 +2094,8 @@ describe('Store', () => {
20812094 [root]
20822095 ▾ <App>
20832096 <Suspense>
2097+ [suspense-root] rects={null}
2098+ <Suspense name="App" rects={null}>
20842099 ` ) ;
20852100
20862101 // Render again to unmount it before it finishes loading
@@ -2826,7 +2841,7 @@ describe('Store', () => {
28262841
28272842 function Component ( { children, promise} ) {
28282843 if ( promise ) {
2829- React . use ( promise ) ;
2844+ readValue ( promise ) ;
28302845 }
28312846 return < div > { children } </ div > ;
28322847 }
@@ -2901,7 +2916,7 @@ describe('Store', () => {
29012916
29022917 function Component ( { children, promise} ) {
29032918 if ( promise ) {
2904- React . use ( promise ) ;
2919+ readValue ( promise ) ;
29052920 }
29062921 return < div > { children } </ div > ;
29072922 }
0 commit comments