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
95fb221e
Unverified
Commit
95fb221e
authored
May 03, 2022
by
JJ Kasper
Committed by
GitHub
May 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix asPath handling for data route revalidation in minimal mode (#36660)
parent
fdc4ab88
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
19 deletions
+90
-19
base-server.ts
packages/next/server/base-server.ts
+22
-19
required-server-files.test.ts
test/production/required-server-files.test.ts
+33
-0
[slug].js
...tion/required-server-files/pages/fallback-false/[slug].js
+35
-0
No files found.
packages/next/server/base-server.ts
View file @
95fb221e
...
...
@@ -465,8 +465,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
:
matchedPathname
let
srcPathname
=
isDataUrl
?
parsedMatchedPath
.
pathname
?.
replace
(
/
\.
json$/
,
''
)
||
matchedPathnameNoExt
?
this
.
stripNextDataPath
(
parsedMatchedPath
.
pathname
?.
replace
(
/
\.
json$/
,
''
)
||
matchedPathnameNoExt
)
||
'/'
:
matchedPathnameNoExt
if
(
this
.
nextConfig
.
i18n
)
{
...
...
@@ -1338,21 +1340,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this
.
nextConfig
.
i18n
?.
locales
).
pathname
const
stripNextDataPath
=
(
path
:
string
)
=>
{
if
(
path
.
includes
(
this
.
buildId
))
{
const
splitPath
=
path
.
substring
(
path
.
indexOf
(
this
.
buildId
)
+
this
.
buildId
.
length
)
path
=
denormalizePagePath
(
splitPath
.
replace
(
/
\.
json$/
,
''
))
}
if
(
this
.
nextConfig
.
i18n
)
{
return
normalizeLocalePath
(
path
,
locales
).
pathname
}
return
path
}
const
handleRedirect
=
(
pageData
:
any
)
=>
{
const
redirect
=
{
destination
:
pageData
.
pageProps
.
__N_REDIRECT
,
...
...
@@ -1383,8 +1370,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// remove /_next/data prefix from urlPathname so it matches
// for direct page visit and /_next/data visit
if
(
isDataReq
)
{
resolvedUrlPathname
=
stripNextDataPath
(
resolvedUrlPathname
)
urlPathname
=
stripNextDataPath
(
urlPathname
)
resolvedUrlPathname
=
this
.
stripNextDataPath
(
resolvedUrlPathname
)
urlPathname
=
this
.
stripNextDataPath
(
urlPathname
)
}
let
ssgCacheKey
=
...
...
@@ -1743,6 +1730,22 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}
}
private
stripNextDataPath
(
path
:
string
)
{
if
(
path
.
includes
(
this
.
buildId
))
{
const
splitPath
=
path
.
substring
(
path
.
indexOf
(
this
.
buildId
)
+
this
.
buildId
.
length
)
path
=
denormalizePagePath
(
splitPath
.
replace
(
/
\.
json$/
,
''
))
}
if
(
this
.
nextConfig
.
i18n
)
{
const
{
locales
}
=
this
.
nextConfig
.
i18n
return
normalizeLocalePath
(
path
,
locales
).
pathname
}
return
path
}
private
async
renderToResponse
(
ctx
:
RequestContext
):
Promise
<
ResponsePayload
|
null
>
{
...
...
test/production/required-server-files.test.ts
View file @
95fb221e
...
...
@@ -56,6 +56,10 @@ describe('should set-up next', () => {
source
:
'/an-ssg-path'
,
destination
:
'/hello.txt'
,
},
{
source
:
'/fallback-false/:path'
,
destination
:
'/hello.txt'
,
},
],
afterFiles
:
[
{
...
...
@@ -980,6 +984,35 @@ describe('should set-up next', () => {
expect
(
JSON
.
parse
(
$
(
'#router'
).
text
()).
asPath
).
toBe
(
'/an-ssg-path'
)
})
it
(
'should have correct asPath on dynamic SSG page fallback correctly'
,
async
()
=>
{
const
toCheck
=
[
{
pathname
:
'/fallback-false/first'
,
matchedPath
:
'/fallback-false/first'
,
},
{
pathname
:
'/fallback-false/first'
,
matchedPath
:
`/_next/data/
${
next
.
buildId
}
/fallback-false/first.json`
,
},
]
for
(
const
check
of
toCheck
)
{
console
.
warn
(
'checking'
,
check
)
const
res
=
await
fetchViaHTTP
(
appPort
,
check
.
pathname
,
undefined
,
{
headers
:
{
'x-matched-path'
:
check
.
matchedPath
,
},
redirect
:
'manual'
,
})
const
html
=
await
res
.
text
()
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#page'
).
text
()).
toBe
(
'blog slug'
)
expect
(
$
(
'#asPath'
).
text
()).
toBe
(
'/fallback-false/first'
)
expect
(
$
(
'#pathname'
).
text
()).
toBe
(
'/fallback-false/[slug]'
)
expect
(
JSON
.
parse
(
$
(
'#query'
).
text
())).
toEqual
({
slug
:
'first'
})
}
})
it
(
'should copy and read .env file'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/api/env'
)
...
...
test/production/required-server-files/pages/fallback-false/[slug].js
0 → 100644
View file @
95fb221e
import
{
useRouter
}
from
'next/router'
export
default
function
Page
(
props
)
{
const
router
=
useRouter
()
return
(
<>
<
p
id
=
"page"
>
blog
slug
<
/p
>
<
p
id
=
"props"
>
{
JSON
.
stringify
(
props
)}
<
/p
>
<
p
id
=
"query"
>
{
JSON
.
stringify
(
router
.
query
)}
<
/p
>
<
p
id
=
"pathname"
>
{
router
.
pathname
}
<
/p
>
<
p
id
=
"asPath"
>
{
router
.
asPath
}
<
/p
>
<
/
>
)
}
export
function
getStaticProps
({
params
})
{
console
.
log
({
blogSlug
:
true
,
params
})
return
{
props
:
{
random
:
Math
.
random
()
+
Date
.
now
(),
blogSlug
:
true
,
params
,
},
revalidate
:
1
,
}
}
export
function
getStaticPaths
()
{
return
{
paths
:
[
'/fallback-false/first'
,
'/fallback-false/second'
],
fallback
:
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