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
0c8a4017
Unverified
Commit
0c8a4017
authored
May 03, 2020
by
Jonathan Pollak
Committed by
GitHub
May 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove __NEXT_DATA__ from production builds when runtime JS is disabled (#12406)
parent
f38eb702
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
2 deletions
+103
-2
_document.tsx
packages/next/pages/_document.tsx
+2
-2
index.test.js
test/integration/disable-js/test/index.test.js
+101
-0
No files found.
packages/next/pages/_document.tsx
View file @
0c8a4017
...
...
@@ -683,7 +683,7 @@ export class NextScript extends Component<OriginProps> {
return
(
<>
{
staticMarkup
?
null
:
(
{
staticMarkup
||
disableRuntimeJS
?
null
:
(
<
script
id=
"__NEXT_DATA__"
type=
"application/json"
...
...
@@ -803,7 +803,7 @@ export class NextScript extends Component<OriginProps> {
)
)
:
null
}
{
staticMarkup
?
null
:
(
{
staticMarkup
||
disableRuntimeJS
?
null
:
(
<
script
id=
"__NEXT_DATA__"
type=
"application/json"
...
...
test/integration/disable-js/test/index.test.js
0 → 100644
View file @
0c8a4017
/* eslint-env jest */
/* global jasmine */
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
{
nextServer
,
nextBuild
,
startApp
,
stopApp
,
renderViaHTTP
,
findPort
,
launchApp
,
killApp
,
}
from
'next-test-utils'
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
let
server
let
app
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
5
const
context
=
{}
describe
(
'disabled runtime JS'
,
()
=>
{
describe
(
'production mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
app
=
nextServer
({
dir
:
join
(
__dirname
,
'../'
),
dev
:
false
,
quiet
:
true
,
})
server
=
await
startApp
(
app
)
context
.
appPort
=
appPort
=
server
.
address
().
port
})
afterAll
(()
=>
stopApp
(
server
))
it
(
'should render the page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
expect
(
html
).
toMatch
(
/Hello World/
)
})
it
(
'should not have __NEXT_DATA__ script'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'script#__NEXT_DATA__'
).
length
).
toBe
(
0
)
})
it
(
'should not have scripts'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'script[src]'
).
length
).
toBe
(
0
)
})
it
(
'should not have preload links'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'link[rel=preload]'
).
length
).
toBe
(
0
)
})
})
describe
(
'dev mode'
,
()
=>
{
let
appPort
let
app
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
join
(
__dirname
,
'../'
),
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
it
(
'should render the page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
expect
(
html
).
toMatch
(
/Hello World/
)
})
it
(
'should not have __NEXT_DATA__ script'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'script#__NEXT_DATA__'
).
length
).
toBe
(
1
)
})
it
(
'should have preload links'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'link[rel=preload]'
).
length
).
toBeGreaterThan
(
0
)
})
it
(
'should have a script for each preload link'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
const
preloadLinks
=
$
(
'link[rel=preload]'
)
preloadLinks
.
each
((
idx
,
element
)
=>
{
const
url
=
$
(
element
).
attr
(
'href'
)
expect
(
$
(
`script[src="
${
url
}
"]`
).
length
).
toBe
(
1
)
})
})
})
})
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