main
js 35 lines 935 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {preinitScriptForSSR} from 'react-client/src/ReactFlightClientConfig';
11
12 import type {Chunk} from '../shared/ReactFlightImportMetadata';
13
14 export type ModuleLoading = null | {
15 prefix: string,
16 crossOrigin?: 'use-credentials' | '',
17 };
18
19 export function prepareDestinationWithChunks(
20 moduleLoading: ModuleLoading,
21 chunks: Array<Chunk>,
22 nonce: ?string,
23 ) {
24 if (moduleLoading !== null) {
25 for (let i = 0; i < chunks.length; i++) {
26 const chunk = chunks[i];
27 // A merged chunk is `[mergedChunkFilename, ...]`; preinit its own URL.
28 preinitScriptForSSR(
29 moduleLoading.prefix + (typeof chunk === 'string' ? chunk : chunk[0]),
30 nonce,
31 moduleLoading.crossOrigin,
32 );
33 }
34 }
35 }