@@ -34,7 +34,7 @@ function readRecord<T>(record: Thenable<T>): T | null {
3434 try {
3535 return React . use ( record ) ;
3636 } catch ( x ) {
37- if ( x === null ) {
37+ if ( record . status === 'rejected' ) {
3838 return null ;
3939 }
4040 throw x ;
@@ -88,13 +88,15 @@ export function loadHookNames(
8888 }
8989
9090 if ( ! record ) {
91- const callbacks = new Set < ( ) => mixed > ( ) ;
91+ const callbacks = new Set < ( value : any ) => mixed > ( ) ;
92+ const rejectCallbacks = new Set < ( reason : mixed ) => mixed > ( ) ;
9293 const thenable : Thenable < HookNames > = {
9394 status : 'pending' ,
9495 value : null ,
9596 reason : null ,
9697 then ( callback : ( value : any ) = > mixed , reject : ( error : mixed ) = > mixed ) {
9798 callbacks . add ( callback ) ;
99+ rejectCallbacks . add ( reject ) ;
98100 } ,
99101
100102 // Optional property used by Timeline:
@@ -113,7 +115,18 @@ export function loadHookNames(
113115 }
114116
115117 // This assumes they won't throw.
116- callbacks . forEach ( callback => callback ( ) ) ;
118+ callbacks . forEach ( callback => callback ( ( thenable : any ) . value ) ) ;
119+ callbacks . clear ( ) ;
120+ rejectCallbacks . clear ( ) ;
121+ } ;
122+ const wakeRejections = ( ) => {
123+ if ( timeoutID ) {
124+ clearTimeout ( timeoutID ) ;
125+ timeoutID = null ;
126+ }
127+ // This assumes they won't throw.
128+ rejectCallbacks . forEach ( callback => callback ( ( thenable : any ) . reason ) ) ;
129+ rejectCallbacks . clear ( ) ;
117130 callbacks . clear ( ) ;
118131 } ;
119132
@@ -148,17 +161,20 @@ export function loadHookNames(
148161 (thenable: any);
149162 fulfilledThenable.status = 'fulfilled';
150163 fulfilledThenable.value = hookNames;
164+ status = 'success';
165+ resolvedHookNames = hookNames;
166+ done();
167+ wake();
151168 } else {
152169 const notFoundThenable : RejectedThenable < HookNames > =
153170 ( thenable : any ) ;
154171 notFoundThenable . status = 'rejected' ;
155172 notFoundThenable . reason = null ;
173+ status = 'error' ;
174+ resolvedHookNames = hookNames ;
175+ done ( ) ;
176+ wakeRejections ( ) ;
156177 }
157-
158- status = 'success';
159- resolvedHookNames = hookNames;
160- done();
161- wake();
162178 } ,
163179 function onError ( error ) {
164180 if ( didTimeout ) {
@@ -178,7 +194,7 @@ export function loadHookNames(
178194
179195 status = 'error';
180196 done();
181- wake ();
197+ wakeRejections ();
182198 } ,
183199 ) ;
184200
@@ -198,7 +214,7 @@ export function loadHookNames(
198214
199215 status = 'timeout';
200216 done();
201- wake ();
217+ wakeRejections ();
202218 } , TIMEOUT ) ;
203219 } ,
204220 handleLoadComplete ,
0 commit comments