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
2ba6db65
Unverified
Commit
2ba6db65
authored
Mar 25, 2020
by
JJ Kasper
Committed by
GitHub
Mar 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to prevent re-using workers for getStaticPaths in dev mode (#11347)
parent
67fd72b7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
+36
-11
static-paths-worker.ts
packages/next/server/static-paths-worker.ts
+7
-10
index.js
test/integration/prerender/pages/blog/[post]/index.js
+1
-0
index.test.js
test/integration/prerender/test/index.test.js
+28
-1
No files found.
packages/next/server/static-paths-worker.ts
View file @
2ba6db65
import
{
buildStaticPaths
}
from
'../build/utils'
import
{
buildStaticPaths
}
from
'../build/utils'
import
{
loadComponents
}
from
'../next-server/server/load-components'
import
{
loadComponents
}
from
'../next-server/server/load-components'
// store initial require modules so we don't clear them below
let
workerWasUsed
=
false
const
initialCache
=
new
Set
(
Object
.
keys
(
require
.
cache
))
// we call getStaticPaths in a separate process to ensure
// we call getStaticPaths in a separate process to ensure
// side-effects aren't relied on in dev that will break
// side-effects aren't relied on in dev that will break
...
@@ -13,14 +12,11 @@ export async function loadStaticPaths(
...
@@ -13,14 +12,11 @@ export async function loadStaticPaths(
pathname
:
string
,
pathname
:
string
,
serverless
:
boolean
serverless
:
boolean
)
{
)
{
// we need to clear any modules manually here since the
// we only want to use each worker once to prevent any invalid
// require-cache-hot-loader doesn't affect require cache here
// caches
// since we're in a separate process
if
(
workerWasUsed
)
{
Object
.
keys
(
require
.
cache
).
forEach
(
mod
=>
{
process
.
exit
(
1
)
if
(
!
initialCache
.
has
(
mod
))
{
delete
require
.
cache
[
mod
]
}
}
})
const
components
=
await
loadComponents
(
const
components
=
await
loadComponents
(
distDir
,
distDir
,
...
@@ -37,5 +33,6 @@ export async function loadStaticPaths(
...
@@ -37,5 +33,6 @@ export async function loadStaticPaths(
)
)
}
}
workerWasUsed
=
true
return
buildStaticPaths
(
pathname
,
components
.
getStaticPaths
)
return
buildStaticPaths
(
pathname
,
components
.
getStaticPaths
)
}
}
test/integration/prerender/pages/blog/[post]/index.js
View file @
2ba6db65
import
React
from
'react'
import
React
from
'react'
import
Link
from
'next/link'
import
Link
from
'next/link'
import
{
useRouter
}
from
'next/router'
import
{
useRouter
}
from
'next/router'
import
'firebase/firestore'
export
async
function
getStaticPaths
()
{
export
async
function
getStaticPaths
()
{
return
{
return
{
...
...
test/integration/prerender/test/index.test.js
View file @
2ba6db65
...
@@ -1065,6 +1065,16 @@ describe('SSG Prerender', () => {
...
@@ -1065,6 +1065,16 @@ describe('SSG Prerender', () => {
await
killApp
(
app
)
await
killApp
(
app
)
})
})
it
(
'should work with firebase import and getStaticPaths'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/blog/post-1'
)
expect
(
html
).
toContain
(
'post-1'
)
expect
(
html
).
not
.
toContain
(
'Error: Failed to load'
)
const
html2
=
await
renderViaHTTP
(
appPort
,
'/blog/post-1'
)
expect
(
html2
).
toContain
(
'post-1'
)
expect
(
html2
).
not
.
toContain
(
'Error: Failed to load'
)
})
it
(
'should not cache getStaticPaths errors'
,
async
()
=>
{
it
(
'should not cache getStaticPaths errors'
,
async
()
=>
{
const
errMsg
=
/The `fallback` key must be returned from getStaticPaths/
const
errMsg
=
/The `fallback` key must be returned from getStaticPaths/
await
check
(()
=>
renderViaHTTP
(
appPort
,
'/blog/post-1'
),
/post-1/
)
await
check
(()
=>
renderViaHTTP
(
appPort
,
'/blog/post-1'
),
/post-1/
)
...
@@ -1088,7 +1098,21 @@ describe('SSG Prerender', () => {
...
@@ -1088,7 +1098,21 @@ describe('SSG Prerender', () => {
})
})
describe
(
'serverless mode'
,
()
=>
{
describe
(
'serverless mode'
,
()
=>
{
const
blogPagePath
=
join
(
appDir
,
'pages/blog/[post]/index.js'
)
let
origBlogPageContent
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
// remove firebase import since it breaks in legacy serverless mode
origBlogPageContent
=
await
fs
.
readFile
(
blogPagePath
,
'utf8'
)
await
fs
.
writeFile
(
blogPagePath
,
origBlogPageContent
.
replace
(
`import 'firebase/firestore'`
,
`// import 'firebase/firestore'`
)
)
await
fs
.
writeFile
(
await
fs
.
writeFile
(
nextConfig
,
nextConfig
,
`module.exports = { target: 'serverless' }`
,
`module.exports = { target: 'serverless' }`
,
...
@@ -1106,7 +1130,10 @@ describe('SSG Prerender', () => {
...
@@ -1106,7 +1130,10 @@ describe('SSG Prerender', () => {
distPagesDir
=
join
(
appDir
,
'.next/serverless/pages'
)
distPagesDir
=
join
(
appDir
,
'.next/serverless/pages'
)
buildId
=
await
fs
.
readFile
(
join
(
appDir
,
'.next/BUILD_ID'
),
'utf8'
)
buildId
=
await
fs
.
readFile
(
join
(
appDir
,
'.next/BUILD_ID'
),
'utf8'
)
})
})
afterAll
(()
=>
killApp
(
app
))
afterAll
(
async
()
=>
{
await
fs
.
writeFile
(
blogPagePath
,
origBlogPageContent
)
await
killApp
(
app
)
})
it
(
'renders data correctly'
,
async
()
=>
{
it
(
'renders data correctly'
,
async
()
=>
{
const
port
=
await
findPort
()
const
port
=
await
findPort
()
...
...
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