Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ClientReference<T> = {
$$id: string,
$$name: string,
$$bundles: Array<string>,
$$importMap?: ?{[string]: string},
};

const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
Expand All @@ -39,12 +40,14 @@ export function createClientReference<T>(
id: string,
exportName: string,
bundles: Array<string>,
importMap?: ?{[string]: string},
): ClientReference<T> {
return {
$$typeof: CLIENT_REFERENCE_TAG,
$$id: id,
$$name: exportName,
$$bundles: bundles,
$$importMap: importMap,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import type {Thenable} from 'shared/ReactTypes';

import type {ImportMetadata} from '../shared/ReactFlightImportMetadata';

import {ID, NAME, BUNDLES} from '../shared/ReactFlightImportMetadata';
import {
ID,
NAME,
BUNDLES,
IMPORT_MAP,
} from '../shared/ReactFlightImportMetadata';
import {prepareDestinationWithChunks} from 'react-client/src/ReactFlightClientConfig';

export type ServerManifest = {
Expand Down Expand Up @@ -60,9 +65,14 @@ export function resolveServerReference<T>(
export function preloadModule<T>(
metadata: ClientReference<T>,
): null | Thenable<any> {
if (metadata[IMPORT_MAP]) {
parcelRequire.extendImportMap(metadata[IMPORT_MAP]);
}

if (metadata[BUNDLES].length === 0) {
return null;
}

return Promise.all(metadata[BUNDLES].map(url => parcelRequire.load(url)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export function resolveClientReferenceMetadata<T>(
config: ClientManifest,
clientReference: ClientReference<T>,
): ClientReferenceMetadata {
if (clientReference.$$importMap) {
return [
clientReference.$$id,
clientReference.$$name,
clientReference.$$bundles,
clientReference.$$importMap,
];
}

return [
clientReference.$$id,
clientReference.$$name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
// This is the parsed shape of the wire format which is why it is
// condensed to only the essentialy information
export type ImportMetadata = [
/* id */ string,
/* name */ string,
/* bundles */ Array<string>,
// eslint does not understand Flow tuple syntax.
/* eslint-disable */
id: string,
name: string,
bundles: Array<string>,
importMap?: {[string]: string},
/* eslint-enable */
];

export const ID = 0;
export const NAME = 1;
export const BUNDLES = 2;
export const IMPORT_MAP = 3;
1 change: 1 addition & 0 deletions scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ declare const __turbopack_require__: ((id: string) => any) & {
declare var parcelRequire: {
(id: string): any,
load: (url: string) => Promise<mixed>,
extendImportMap: (importMap: {[string]: string}) => void,
meta: {
publicUrl: string,
},
Expand Down
Loading