diff --git a/packages/runtimes/js/src/JSRuntime.js b/packages/runtimes/js/src/JSRuntime.js index d6e644a42a9..a083bafbd69 100644 --- a/packages/runtimes/js/src/JSRuntime.js +++ b/packages/runtimes/js/src/JSRuntime.js @@ -624,27 +624,30 @@ function getRegisterCode( entryBundle: NamedBundle, bundleGraph: BundleGraph, ): string { - let idToName = []; + let mappings = []; bundleGraph.traverseBundles((bundle, _, actions) => { if (bundle.bundleBehavior === 'inline') { return; } - idToName.push([ + // To make the manifest as small as possible all bundle key/values are + // serialised into a single array e.g. ['id', 'value', 'id2', 'value2']. + // `./helpers/bundle-manifest` accounts for this by iterating index by 2 + mappings.push( bundle.publicId, relativeBundlePath(entryBundle, nullthrows(bundle), { leadingDotSlash: false, }), - ]); + ); if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) { for (let referenced of bundleGraph.getReferencedBundles(bundle)) { - idToName.push([ + mappings.push( referenced.publicId, relativeBundlePath(entryBundle, nullthrows(referenced), { leadingDotSlash: false, }), - ]); + ); } // New contexts have their own manifests, so there's no need to continue. actions.skipChildren(); @@ -658,7 +661,7 @@ function getRegisterCode( : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`; return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify( - JSON.stringify(idToName), + JSON.stringify(mappings), )}));`; } diff --git a/packages/runtimes/js/src/helpers/bundle-manifest.js b/packages/runtimes/js/src/helpers/bundle-manifest.js index 792325b0f5e..916b789e772 100644 --- a/packages/runtimes/js/src/helpers/bundle-manifest.js +++ b/packages/runtimes/js/src/helpers/bundle-manifest.js @@ -1,8 +1,11 @@ var mapping = new Map(); -function register(baseUrl, pairs) { - for (var i = 0; i < pairs.length; i++) { - mapping.set(pairs[i][0], {baseUrl, path: pairs[i][1]}); +function register(baseUrl, manifest) { + for (var i = 0; i < manifest.length - 1; i += 2) { + mapping.set(manifest[i], { + baseUrl: baseUrl, + path: manifest[i + 1], + }); } }