Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
ffe1a12f
Unverified
Commit
ffe1a12f
authored
Dec 06, 2018
by
Tim Neutkens
Committed by
GitHub
Dec 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move getDynamicImportBundles into own ts file (#5836)
parent
3c62b075
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
get-dynamic-import-bundles.ts
packages/next-server/server/get-dynamic-import-bundles.ts
+22
-0
render.js
packages/next-server/server/render.js
+4
-14
No files found.
packages/next-server/server/get-dynamic-import-bundles.ts
0 → 100644
View file @
ffe1a12f
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
())
}
packages/next-server/server/render.js
View file @
ffe1a12f
...
@@ -10,17 +10,7 @@ import Head, { defaultHead } from '../lib/head'
...
@@ -10,17 +10,7 @@ import Head, { defaultHead } from '../lib/head'
import
Loadable
from
'../lib/loadable'
import
Loadable
from
'../lib/loadable'
import
LoadableCapture
from
'../lib/loadable-capture'
import
LoadableCapture
from
'../lib/loadable-capture'
import
{
BUILD_MANIFEST
,
REACT_LOADABLE_MANIFEST
,
SERVER_DIRECTORY
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
import
{
BUILD_MANIFEST
,
REACT_LOADABLE_MANIFEST
,
SERVER_DIRECTORY
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
import
{
getDynamicImportBundles
}
from
'./get-dynamic-import-bundles'
// 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
])
},
[])
}
export
function
renderToHTML
(
req
,
res
,
pathname
,
query
,
opts
)
{
export
function
renderToHTML
(
req
,
res
,
pathname
,
query
,
opts
)
{
return
doRender
(
req
,
res
,
pathname
,
query
,
opts
)
return
doRender
(
req
,
res
,
pathname
,
query
,
opts
)
...
@@ -66,6 +56,8 @@ async function doRender (req, res, pathname, query, {
...
@@ -66,6 +56,8 @@ async function doRender (req, res, pathname, query, {
require
(
appPath
)
require
(
appPath
)
])
])
await
Loadable
.
preloadAll
()
// Make sure all dynamic imports are loaded
Component
=
Component
.
default
||
Component
Component
=
Component
.
default
||
Component
if
(
typeof
Component
!==
'function'
)
{
if
(
typeof
Component
!==
'function'
)
{
...
@@ -134,10 +126,8 @@ async function doRender (req, res, pathname, query, {
...
@@ -134,10 +126,8 @@ async function doRender (req, res, pathname, query, {
return
{
html
,
head
,
buildManifest
}
return
{
html
,
head
,
buildManifest
}
}
}
await
Loadable
.
preloadAll
()
// Make sure all dynamic imports are loaded
const
docProps
=
await
loadGetInitialProps
(
Document
,
{
...
ctx
,
renderPage
})
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
)
const
dynamicImportsIds
=
dynamicImports
.
map
((
bundle
)
=>
bundle
.
id
)
if
(
isResSent
(
res
))
return
if
(
isResSent
(
res
))
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment