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
33ebda1b
Unverified
Commit
33ebda1b
authored
Jul 09, 2020
by
Jan Potoms
Committed by
GitHub
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix root route optional catch-all prerendering (#14986)
Fixes
https://github.com/vercel/next.js/issues/14964
parent
62902545
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
4 deletions
+117
-4
index.ts
packages/next/build/index.ts
+5
-4
next.config.js
...dynamic-optional-routing-root-static-paths/next.config.js
+1
-0
[[...optionalName]].js
...al-routing-root-static-paths/pages/[[...optionalName]].js
+18
-0
index.test.js
...mic-optional-routing-root-static-paths/test/index.test.js
+93
-0
No files found.
packages/next/build/index.ts
View file @
33ebda1b
...
...
@@ -791,7 +791,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
isSsgFallback
=
ssgFallbackPages
.
has
(
page
)
const
isDynamic
=
isDynamicRoute
(
page
)
const
hasAmp
=
hybridAmpPages
.
has
(
page
)
le
t
file
=
normalizePagePath
(
page
)
cons
t
file
=
normalizePagePath
(
page
)
// The dynamic version of SSG pages are only prerendered if the fallback
// is enabled. Below, we handle the specific prerenders of these.
...
...
@@ -826,11 +826,12 @@ export default async function build(dir: string, conf = null): Promise<void> {
// `getStaticPaths` (additionalSsgPaths).
const
extraRoutes
=
additionalSsgPaths
.
get
(
page
)
||
[]
for
(
const
route
of
extraRoutes
)
{
await
moveExportedPage
(
page
,
route
,
route
,
true
,
'html'
)
await
moveExportedPage
(
page
,
route
,
route
,
true
,
'json'
)
const
pageFile
=
normalizePagePath
(
route
)
await
moveExportedPage
(
page
,
route
,
pageFile
,
true
,
'html'
)
await
moveExportedPage
(
page
,
route
,
pageFile
,
true
,
'json'
)
if
(
hasAmp
)
{
const
ampPage
=
`
${
normalizePagePath
(
route
)
}
.amp`
const
ampPage
=
`
${
pageFile
}
.amp`
await
moveExportedPage
(
page
,
ampPage
,
ampPage
,
true
,
'html'
)
await
moveExportedPage
(
page
,
ampPage
,
ampPage
,
true
,
'json'
)
}
...
...
test/integration/dynamic-optional-routing-root-static-paths/next.config.js
0 → 100644
View file @
33ebda1b
module
.
exports
=
{}
test/integration/dynamic-optional-routing-root-static-paths/pages/[[...optionalName]].js
0 → 100644
View file @
33ebda1b
export
const
getStaticPaths
=
()
=>
({
paths
:
[
{
params
:
{
optionalName
:
[]
}
},
{
params
:
{
optionalName
:
[
'one'
]
}
},
{
params
:
{
optionalName
:
[
'one'
,
'two'
]
}
},
],
fallback
:
false
,
})
export
const
getStaticProps
=
({
params
})
=>
({
props
:
{
params
}
})
export
default
function
Page
({
params
})
{
return
(
<
div
id
=
"success"
>
{
params
.
optionalName
?
params
.
optionalName
.
join
(
','
)
:
'yay'
}
<
/div
>
)
}
test/integration/dynamic-optional-routing-root-static-paths/test/index.test.js
0 → 100644
View file @
33ebda1b
/* eslint-env jest */
import
cheerio
from
'cheerio'
import
fs
from
'fs-extra'
import
{
findPort
,
killApp
,
launchApp
,
nextBuild
,
nextStart
,
renderViaHTTP
,
}
from
'next-test-utils'
import
{
join
}
from
'path'
jest
.
setTimeout
(
1000
*
60
*
2
)
let
app
let
appPort
const
appDir
=
join
(
__dirname
,
'../'
)
function
runTests
()
{
it
(
'should render optional catch-all top-level route with no segments'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#success'
).
text
()).
toBe
(
'yay'
)
})
it
(
'should render optional catch-all top-level route with one segment'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/one'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#success'
).
text
()).
toBe
(
'one'
)
})
it
(
'should render optional catch-all top-level route with two segments'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/one/two'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'#success'
).
text
()).
toBe
(
'one,two'
)
})
}
const
nextConfig
=
join
(
appDir
,
'next.config.js'
)
describe
(
'Dynamic Optional Routing'
,
()
=>
{
describe
(
'dev mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
runTests
()
})
describe
(
'production mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
const
curConfig
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
if
(
curConfig
.
includes
(
'target'
))
{
await
fs
.
writeFile
(
nextConfig
,
`module.exports = {}`
)
}
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
runTests
()
})
describe
(
'serverless mode'
,
()
=>
{
let
origNextConfig
beforeAll
(
async
()
=>
{
origNextConfig
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
await
fs
.
writeFile
(
nextConfig
,
`module.exports = { target: 'serverless' }`
)
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfig
,
origNextConfig
)
await
killApp
(
app
)
})
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