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
2139f66a
Commit
2139f66a
authored
Sep 11, 2019
by
JJ Kasper
Committed by
Joe Haddad
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for duplicate scripts and add extra de-duping (#8709)
parent
eb8c11bb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
1 deletion
+63
-1
_document.tsx
packages/next/pages/_document.tsx
+3
-1
hello.js
test/integration/dedupes-scripts/components/hello.js
+7
-0
index.js
test/integration/dedupes-scripts/pages/index.js
+9
-0
index.test.js
test/integration/dedupes-scripts/test/index.test.js
+44
-0
No files found.
packages/next/pages/_document.tsx
View file @
2139f66a
...
...
@@ -480,7 +480,7 @@ export class NextScript extends Component<OriginProps> {
'!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();'
getDynamicChunks
()
{
const
{
dynamicImports
,
assetPrefix
}
=
this
.
context
.
_documentProps
const
{
dynamicImports
,
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
const
{
_devOnlyInvalidateCacheQueryString
}
=
this
.
context
return
dedupe
(
dynamicImports
).
map
((
bundle
:
any
)
=>
{
...
...
@@ -491,6 +491,8 @@ export class NextScript extends Component<OriginProps> {
:
{
noModule
:
true
}
}
if
(
files
.
includes
(
bundle
.
file
))
return
null
return
(
<
script
async
...
...
test/integration/dedupes-scripts/components/hello.js
0 → 100644
View file @
2139f66a
import
Link
from
'next/link'
export
default
()
=>
(
<
Link
href
=
'/'
>
<
a
>
Hello
world
<
/a
>
<
/Link
>
)
test/integration/dedupes-scripts/pages/index.js
0 → 100644
View file @
2139f66a
import
dynamic
from
'next/dynamic'
const
Hello
=
dynamic
(()
=>
import
(
'../components/hello'
))
export
default
()
=>
(
<>
<
Hello
/>
<
/
>
)
test/integration/dedupes-scripts/test/index.test.js
0 → 100644
View file @
2139f66a
/* eslint-env jest */
/* global jasmine */
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
{
nextBuild
,
nextStart
,
findPort
,
killApp
,
renderViaHTTP
}
from
'next-test-utils'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
let
app
describe
(
'De-dedupes scripts in _document'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
await
nextBuild
(
appDir
)
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
it
(
'Does not have duplicate script references'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
let
foundDuplicate
=
false
const
srcs
=
new
Set
()
for
(
const
script
of
$
(
'script'
).
toArray
())
{
const
{
src
}
=
script
.
attribs
if
(
!
src
||
!
src
.
startsWith
(
'/_next/static'
))
continue
if
(
srcs
.
has
(
src
))
{
console
.
error
(
`Found duplicate script
${
src
}
`
)
foundDuplicate
=
true
}
srcs
.
add
(
src
)
}
expect
(
foundDuplicate
).
toBe
(
false
)
})
})
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