| 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 | export type ModuleLoading = null | { |
| 13 | prefix: string, |
| 14 | crossOrigin?: 'use-credentials' | '', |
| 15 | }; |
| 16 | |
| 17 | export function prepareDestinationWithChunks( |
| 18 | moduleLoading: ModuleLoading, |
| 19 | // Chunks are double-indexed [..., idx, filenamex, idy, filenamey, ...] |
| 20 | chunks: Array<string>, |
| 21 | nonce: ?string, |
| 22 | ) { |
| 23 | if (moduleLoading !== null) { |
| 24 | for (let i = 1; i < chunks.length; i += 2) { |
| 25 | preinitScriptForSSR( |
| 26 | moduleLoading.prefix + chunks[i], |
| 27 | nonce, |
| 28 | moduleLoading.crossOrigin, |
| 29 | ); |
| 30 | } |
| 31 | } |
| 32 | } |