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
dcb0a656
Unverified
Commit
dcb0a656
authored
Apr 13, 2020
by
JJ Kasper
Committed by
GitHub
Apr 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gip identifiers to NEXT_DATA (#11835)
* Add gip identifiers to NEXT_DATA * Update test a bit
parent
cbcb10b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
0 deletions
+109
-0
utils.ts
packages/next/next-server/lib/utils.ts
+2
-0
render.tsx
packages/next/next-server/server/render.tsx
+8
-0
index.js
test/integration/gip-identifier/pages/index.js
+1
-0
index.test.js
test/integration/gip-identifier/test/index.test.js
+98
-0
No files found.
packages/next/next-server/lib/utils.ts
View file @
dcb0a656
...
...
@@ -82,6 +82,8 @@ export type NEXT_DATA = {
gsp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
gip
?:
boolean
appGip
?:
boolean
}
/**
...
...
packages/next/next-server/server/render.tsx
View file @
dcb0a656
...
...
@@ -195,6 +195,8 @@ function renderDocument(
gsp
,
gssp
,
customServer
,
gip
,
appGip
,
}:
RenderOpts
&
{
props
:
any
docProps
:
DocumentInitialProps
...
...
@@ -218,6 +220,8 @@ function renderDocument(
gsp
?:
boolean
gssp
?:
boolean
customServer
?:
boolean
gip
?:
boolean
appGip
?:
boolean
}
):
string
{
return
(
...
...
@@ -241,6 +245,8 @@ function renderDocument(
gsp
,
// whether the page is getStaticProps
gssp
,
// whether the page is getServerSideProps
customServer
,
// whether the user is using a custom server
gip
,
// whether the page has getInitialProps
appGip
,
// whether the _app has getInitialProps
},
dangerousAsPath
,
canonicalBase
,
...
...
@@ -777,6 +783,8 @@ export async function renderToHTML(
polyfillFiles
,
gsp
:
!!
getStaticProps
?
true
:
undefined
,
gssp
:
!!
getServerSideProps
?
true
:
undefined
,
gip
:
hasPageGetInitialProps
?
true
:
undefined
,
appGip
:
!
defaultAppGetInitialProps
?
true
:
undefined
,
})
if
(
inAmpMode
&&
html
)
{
...
...
test/integration/gip-identifier/pages/index.js
0 → 100644
View file @
dcb0a656
export
default
()
=>
'hi'
test/integration/gip-identifier/test/index.test.js
0 → 100644
View file @
dcb0a656
/* eslint-env jest */
/* global jasmine */
import
cheerio
from
'cheerio'
import
fs
from
'fs-extra'
import
{
findPort
,
killApp
,
launchApp
,
nextBuild
,
nextStart
,
renderViaHTTP
,
}
from
'next-test-utils'
import
{
join
}
from
'path'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
const
appDir
=
join
(
__dirname
,
'..'
)
const
appPage
=
join
(
appDir
,
'pages/_app.js'
)
const
indexPage
=
join
(
appDir
,
'pages/index.js'
)
let
app
let
appPort
let
indexPageContent
const
runTests
=
isDev
=>
{
const
getData
=
async
()
=>
{
if
(
isDev
)
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
}
else
{
const
{
code
}
=
await
nextBuild
(
appDir
)
if
(
code
!==
0
)
throw
new
Error
(
`build faild, exit code:
${
code
}
`
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
}
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
await
killApp
(
app
)
const
$
=
cheerio
.
load
(
html
)
return
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
text
())
}
it
(
'should not have gip or appGip in NEXT_DATA for page without getInitialProps'
,
async
()
=>
{
const
data
=
await
getData
()
expect
(
data
.
gip
).
toBe
(
undefined
)
expect
(
data
.
appGip
).
toBe
(
undefined
)
})
it
(
'should have gip in NEXT_DATA for page with getInitialProps'
,
async
()
=>
{
indexPageContent
=
await
fs
.
readFile
(
indexPage
,
'utf8'
)
await
fs
.
writeFile
(
indexPage
,
`
const Page = () => 'hi'
Page.getInitialProps = () => ({ hello: 'world' })
export default Page
`
)
const
data
=
await
getData
()
expect
(
data
.
gip
).
toBe
(
true
)
})
it
(
'should have gip and appGip in NEXT_DATA for page with getInitialProps and _app with getInitialProps'
,
async
()
=>
{
await
fs
.
writeFile
(
appPage
,
`
const App = ({ Component, pageProps }) => <Component {...pageProps} />
App.getInitialProps = async (ctx) => {
let pageProps = {}
if (ctx.Component.getInitialProps) {
pageProps = await ctx.Component.getInitialProps(ctx.ctx)
}
return { pageProps }
}
export default App
`
)
const
data
=
await
getData
()
expect
(
data
.
gip
).
toBe
(
true
)
expect
(
data
.
appGip
).
toBe
(
true
)
})
it
(
'should only have appGip in NEXT_DATA for page without getInitialProps and _app with getInitialProps'
,
async
()
=>
{
await
fs
.
writeFile
(
indexPage
,
indexPageContent
)
const
data
=
await
getData
()
await
fs
.
remove
(
appPage
)
expect
(
data
.
gip
).
toBe
(
undefined
)
expect
(
data
.
appGip
).
toBe
(
true
)
})
}
describe
(
'gip identifiers'
,
()
=>
{
describe
(
'dev mode'
,
()
=>
{
runTests
(
true
)
})
describe
(
'production mode'
,
()
=>
{
runTests
()
})
})
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