Skip to content

Commit 9de32f8

Browse files
committed
update client reference types
1 parent d3d2bbf commit 9de32f8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

packages/react-server-dom-fb/src/ReactFlightClientConfigFBBundler.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ import type {
3333
ClientReferenceMetadata,
3434
} from './ReactFlightReferencesFB';
3535

36-
// eslint-disable-next-line no-unused-vars
3736
export opaque type ClientReference<T> = {
38-
moduleId: string,
39-
exportName: string,
40-
loadModule: () => Thenable<T>,
37+
getModuleId: () => string,
38+
load: () => Thenable<T>,
4139
};
4240

4341
export function prepareDestinationForModule(
@@ -73,14 +71,14 @@ const asyncModuleCache: Map<string, Thenable<any>> = new Map();
7371
export 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

Comments
 (0)