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
356636c8
Commit
356636c8
authored
Jun 29, 2019
by
JJ Kasper
Committed by
Joe Haddad
Jun 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add updated de-duping logic for next/dynamic (#7705)
parent
7049c3b3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
40 deletions
+34
-40
utils.ts
packages/next-server/lib/utils.ts
+1
-1
get-dynamic-import-bundles.ts
packages/next-server/server/get-dynamic-import-bundles.ts
+0
-28
render.tsx
packages/next-server/server/render.tsx
+24
-11
react-loadable-plugin.ts
packages/next/build/webpack/plugins/react-loadable-plugin.ts
+9
-0
No files found.
packages/next-server/lib/utils.ts
View file @
356636c8
...
...
@@ -2,7 +2,7 @@ import { format, UrlObject, URLFormatOptions } from 'url'
import
{
ServerResponse
,
IncomingMessage
}
from
'http'
import
{
ComponentType
}
from
'react'
import
{
ParsedUrlQuery
}
from
'querystring'
import
{
ManifestItem
}
from
'../server/
get-dynamic-import-bundles
'
import
{
ManifestItem
}
from
'../server/
render
'
import
{
BaseRouter
}
from
'./router/router'
/**
...
...
packages/next-server/server/get-dynamic-import-bundles.ts
deleted
100644 → 0
View file @
7049c3b3
export
type
ManifestItem
=
{
id
:
number
|
string
name
:
string
file
:
string
publicPath
:
string
}
export
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.tsx
View file @
356636c8
...
...
@@ -24,17 +24,21 @@ import { RequestContext } from '../lib/request-context'
import
{
LoadableContext
}
from
'../lib/loadable-context'
import
{
RouterContext
}
from
'../lib/router-context'
import
{
DataManager
}
from
'../lib/data-manager'
import
{
ManifestItem
,
getDynamicImportBundles
,
Manifest
as
ReactLoadableManifest
,
}
from
'./get-dynamic-import-bundles'
import
{
getPageFiles
,
BuildManifest
}
from
'./get-page-files'
import
{
AmpStateContext
}
from
'../lib/amp-context'
import
optimizeAmp
from
'./optimize-amp'
import
{
isInAmpMode
}
from
'../lib/amp'
import
{
IPageConfig
}
from
'./load-components'
export
type
ManifestItem
=
{
id
:
number
|
string
name
:
string
file
:
string
publicPath
:
string
}
type
ReactLoadableManifest
=
{
[
moduleId
:
string
]:
ManifestItem
[]
}
function
noRouter
()
{
const
message
=
'No router instance found. you should only use "next/router" inside the client side of your app. https://err.sh/zeit/next.js/no-router-instance'
...
...
@@ -468,12 +472,21 @@ export async function renderToHTML(
return
dataManagerData
}
const
dynamicImports
=
[
...
getDynamicImportBundles
(
reactLoadableManifest
,
reactLoadableModules
),
]
const
dynamicImportsIds
:
any
=
[
...
new
Set
(
dynamicImports
.
map
(
bundle
=>
bundle
.
id
)),
]
const
dynamicImportIdsSet
=
new
Set
<
string
>
()
const
dynamicImports
:
ManifestItem
[]
=
[]
for
(
const
mod
of
reactLoadableModules
)
{
const
manifestItem
=
reactLoadableManifest
[
mod
]
if
(
manifestItem
)
{
manifestItem
.
map
(
item
=>
{
dynamicImports
.
push
(
item
)
dynamicImportIdsSet
.
add
(
item
.
id
as
string
)
})
}
}
const
dynamicImportsIds
=
[...
dynamicImportIdsSet
]
const
inAmpMode
=
isInAmpMode
(
ampState
)
const
hybridAmp
=
ampState
.
hybrid
...
...
packages/next/build/webpack/plugins/react-loadable-plugin.ts
View file @
356636c8
...
...
@@ -61,6 +61,15 @@ function buildManifest(
manifest
[
request
]
=
[]
}
// Avoid duplicate files
if
(
manifest
[
request
].
some
(
item
=>
item
.
id
===
id
&&
item
.
file
===
file
)
)
{
continue
}
manifest
[
request
].
push
({
id
,
name
,
...
...
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