Unverified Commit ffe1a12f authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move getDynamicImportBundles into own ts file (#5836)

parent 3c62b075
type ManifestItem = {
id: number|string,
name: string,
file: string,
publicPath: string
}
type Manifest = {[moduleId: string]: ManifestItem[]}
type DynamicImportBundles = Set<ManifestItem>
// Based on https://github.com/jamiebuilds/react-loadable/pull/132
export function getDynamicImportBundles (manifest: Manifest, moduleIds: string[]): DynamicImportBundles {
return moduleIds.reduce((bundles: DynamicImportBundles, moduleId: string): DynamicImportBundles => {
if (typeof manifest[moduleId] === 'undefined') {
return bundles
}
manifest[moduleId].map((item) => bundles.add(item))
return bundles
}, new Set())
}
......@@ -10,17 +10,7 @@ import Head, { defaultHead } from '../lib/head'
import Loadable from '../lib/loadable'
import LoadableCapture from '../lib/loadable-capture'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH } from 'next-server/constants'
// Based on https://github.com/jamiebuilds/react-loadable/pull/132
function getDynamicImportBundles (manifest, moduleIds) {
return moduleIds.reduce((bundles, moduleId) => {
if (typeof manifest[moduleId] === 'undefined') {
return bundles
}
return bundles.concat(manifest[moduleId])
}, [])
}
import {getDynamicImportBundles} from './get-dynamic-import-bundles'
export function renderToHTML (req, res, pathname, query, opts) {
return doRender(req, res, pathname, query, opts)
......@@ -66,6 +56,8 @@ async function doRender (req, res, pathname, query, {
require(appPath)
])
await Loadable.preloadAll() // Make sure all dynamic imports are loaded
Component = Component.default || Component
if (typeof Component !== 'function') {
......@@ -134,10 +126,8 @@ async function doRender (req, res, pathname, query, {
return { html, head, buildManifest }
}
await Loadable.preloadAll() // Make sure all dynamic imports are loaded
const docProps = await loadGetInitialProps(Document, { ...ctx, renderPage })
const dynamicImports = [...(new Set(getDynamicImportBundles(reactLoadableManifest, reactLoadableModules)))]
const dynamicImports = [...getDynamicImportBundles(reactLoadableManifest, reactLoadableModules)]
const dynamicImportsIds = dynamicImports.map((bundle) => bundle.id)
if (isResSent(res)) return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment