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
66273807
Unverified
Commit
66273807
authored
Feb 13, 2020
by
Joe Haddad
Committed by
GitHub
Feb 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retry Static Data Fetch on Hydration (#10513)
parent
e871e86b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
8 deletions
+41
-8
router.ts
packages/next/next-server/lib/router/router.ts
+15
-8
index.js
test/integration/prerender/pages/blog/[post]/index.js
+8
-0
index.js
test/integration/prerender/pages/index.js
+3
-0
index.test.js
test/integration/prerender/test/index.test.js
+15
-0
No files found.
packages/next/next-server/lib/router/router.ts
View file @
66273807
...
...
@@ -70,19 +70,26 @@ function fetchNextData(
isServerRender
:
boolean
,
cb
?:
(...
args
:
any
)
=>
any
)
{
return
fetch
(
formatWithValidation
({
// @ts-ignore __NEXT_DATA__
pathname
:
`/_next/data/
${
__NEXT_DATA__
.
buildId
}${
pathname
}
.json`
,
query
,
})
)
.
then
(
res
=>
{
let
attempts
=
isServerRender
?
3
:
1
function
getResponse
():
Promise
<
any
>
{
return
fetch
(
formatWithValidation
({
// @ts-ignore __NEXT_DATA__
pathname
:
`/_next/data/
${
__NEXT_DATA__
.
buildId
}${
pathname
}
.json`
,
query
,
})
).
then
(
res
=>
{
if
(
!
res
.
ok
)
{
if
(
--
attempts
>
0
&&
res
.
status
>=
500
)
{
return
getResponse
()
}
throw
new
Error
(
`Failed to load static props`
)
}
return
res
.
json
()
})
}
return
getResponse
()
.
then
(
data
=>
{
return
cb
?
cb
(
data
)
:
data
})
...
...
test/integration/prerender/pages/blog/[post]/index.js
View file @
66273807
...
...
@@ -16,6 +16,8 @@ export async function unstable_getStaticPaths() {
}
}
let
counter
=
0
// eslint-disable-next-line camelcase
export
async
function
unstable_getStaticProps
({
params
})
{
if
(
params
.
post
===
'post-10'
)
{
...
...
@@ -28,6 +30,12 @@ export async function unstable_getStaticProps({ params }) {
throw
new
Error
(
'such broken..'
)
}
if
(
params
.
post
===
'post-999'
)
{
if
(
++
counter
<
3
)
{
throw
new
Error
(
'try again..'
)
}
}
return
{
props
:
{
params
,
...
...
test/integration/prerender/pages/index.js
View file @
66273807
...
...
@@ -32,6 +32,9 @@ const Page = ({ world, time }) => {
<
Link
href
=
"/blog/[post]"
as
=
"/blog/post-100"
>
<
a
id
=
"broken-post"
>
to
broken
<
/a
>
<
/Link
>
<
Link
href
=
"/blog/[post]"
as
=
"/blog/post-999"
>
<
a
id
=
"broken-at-first-post"
>
to
broken
at
first
<
/a
>
<
/Link
>
<
br
/>
<
Link
href
=
"/blog/[post]/[comment]"
as
=
"/blog/post-1/comment-1"
>
<
a
id
=
"comment-1"
>
to
another
dynamic
<
/a
>
...
...
test/integration/prerender/test/index.test.js
View file @
66273807
...
...
@@ -348,6 +348,21 @@ const runTests = (dev = false) => {
expect
(
await
browser
.
eval
(
'window.beforeClick'
)).
not
.
toBe
(
'true'
)
})
// TODO: dev currently renders this page as blocking, meaning it shows the
// server error instead of continously retrying. Do we want to change this?
if
(
!
dev
)
{
it
(
'should reload page on failed data request, and retry'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
await
browser
.
eval
(
'window.beforeClick = true'
)
await
browser
.
elementByCss
(
'#broken-at-first-post'
).
click
()
await
waitFor
(
3000
)
expect
(
await
browser
.
eval
(
'window.beforeClick'
)).
not
.
toBe
(
'true'
)
const
text
=
await
browser
.
elementByCss
(
'#params'
).
text
()
expect
(
text
).
toMatch
(
/post.*
?
post-999/
)
})
}
it
(
'should support prerendered catchall route'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/catchall/another/value'
)
const
$
=
cheerio
.
load
(
html
)
...
...
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