@@ -33,11 +33,9 @@ import type {
3333 ClientReferenceMetadata ,
3434} from './ReactFlightReferencesFB' ;
3535
36- // eslint-disable-next-line no-unused-vars
3736export opaque type ClientReference < T > = {
38- moduleId : string ,
39- exportName : string ,
40- loadModule : ( ) => Thenable < T > ,
37+ getModuleId : ( ) => string ,
38+ load : ( ) => Thenable < T > ,
4139} ;
4240
4341export function prepareDestinationForModule (
@@ -73,14 +71,14 @@ const asyncModuleCache: Map<string, Thenable<any>> = new Map();
7371export function preloadModule < T > (
7472 clientReference : ClientReference < T > ,
7573) : null | Thenable < any > {
76- const existingPromise = asyncModuleCache . get ( clientReference . moduleId ) ;
74+ const existingPromise = asyncModuleCache . get ( clientReference . getModuleId ( ) ) ;
7775 if ( existingPromise ) {
7876 if ( existingPromise . status === 'fulfilled' ) {
7977 return null ;
8078 }
8179 return existingPromise ;
8280 } else {
83- const modulePromise : Thenable < T > = clientReference.loadModule ();
81+ const modulePromise : Thenable < T > = clientReference.load ();
8482 modulePromise.then(
8583 value => {
8684 const fulfilledThenable : FulfilledThenable < mixed > =
@@ -94,20 +92,21 @@ export function preloadModule<T>(
9492 rejectedThenable . reason = reason ;
9593 } ,
9694 );
97- asyncModuleCache.set(clientReference.moduleId , modulePromise);
95+ asyncModuleCache.set(clientReference.getModuleId() , modulePromise);
9896 return modulePromise;
9997 }
10098}
10199
102- export function requireModule < T > (metadata : ClientReference< T > ): T {
100+ export function requireModule < T > (clientReference : ClientReference< T > ): T {
103101 let module ;
104102 // We assume that preloadModule has been called before, which
105103 // should have added something to the module cache.
106- const promise : any = asyncModuleCache . get ( metadata . moduleId ) ;
104+ const promise : any = asyncModuleCache . get ( clientReference . getModuleId ( ) ) ;
107105 if ( promise . status === 'fulfilled' ) {
108106 module = promise . value ;
109107 } else {
110108 throw promise . reason ;
111109 }
112- return module [ metadata . exportName ] ;
110+ // We are currently only support default exports for client components
111+ return module ;
113112}
0 commit comments