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
5dfc7da2
Unverified
Commit
5dfc7da2
authored
Mar 05, 2020
by
Joe Haddad
Committed by
GitHub
Mar 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getStaticPaths modules being cached in dev mode (#10852)
parent
69ba7934
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
static-paths-worker.ts
packages/next/server/static-paths-worker.ts
+8
-7
index.test.js
test/integration/prerender/test/index.test.js
+40
-0
No files found.
packages/next/server/static-paths-worker.ts
View file @
5dfc7da2
import
{
join
}
from
'path'
import
{
buildStaticPaths
}
from
'../build/utils'
import
{
buildStaticPaths
}
from
'../build/utils'
import
{
getPagePath
}
from
'../next-server/server/require'
import
{
loadComponents
}
from
'../next-server/server/load-components'
import
{
loadComponents
}
from
'../next-server/server/load-components'
import
{
PAGES_MANIFEST
,
SERVER_DIRECTORY
}
from
'../next-server/lib/constants'
// store initial require modules so we don't clear them below
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
...
@@ -16,10 +16,11 @@ export async function loadStaticPaths(
...
@@ -16,10 +16,11 @@ export async function loadStaticPaths(
// we need to clear any modules manually here since the
// we need to clear any modules manually here since the
// require-cache-hot-loader doesn't affect require cache here
// require-cache-hot-loader doesn't affect require cache here
// since we're in a separate process
// since we're in a separate process
delete
require
.
cache
[
join
(
distDir
,
SERVER_DIRECTORY
,
PAGES_MANIFEST
)]
Object
.
keys
(
require
.
cache
).
forEach
(
mod
=>
{
if
(
!
initialCache
.
has
(
mod
))
{
const
pagePath
=
await
getPagePath
(
pathname
,
distDir
,
serverless
,
true
)
delete
require
.
cache
[
mod
]
delete
require
.
cache
[
pagePath
]
}
})
const
components
=
await
loadComponents
(
const
components
=
await
loadComponents
(
distDir
,
distDir
,
...
...
test/integration/prerender/test/index.test.js
View file @
5dfc7da2
...
@@ -983,6 +983,46 @@ describe('SSG Prerender', () => {
...
@@ -983,6 +983,46 @@ describe('SSG Prerender', () => {
runTests
(
true
)
runTests
(
true
)
})
})
describe
(
'dev mode getStaticPaths'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfig
,
// we set cpus to 1 so that we make sure the requests
// aren't being cached at the jest-worker level
`module.exports = { experimental: { cpus: 1 } }`
,
'utf8'
)
await
fs
.
remove
(
join
(
appDir
,
'.next'
))
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
})
afterAll
(
async
()
=>
{
await
fs
.
remove
(
nextConfig
)
await
killApp
(
app
)
})
it
(
'should not cache getStaticPaths errors'
,
async
()
=>
{
const
errMsg
=
/The `fallback` key must be returned from getStaticPaths/
await
check
(()
=>
renderViaHTTP
(
appPort
,
'/blog/post-1'
),
/post-1/
)
const
blogPage
=
join
(
appDir
,
'pages/blog/[post]/index.js'
)
const
origContent
=
await
fs
.
readFile
(
blogPage
,
'utf8'
)
await
fs
.
writeFile
(
blogPage
,
origContent
.
replace
(
'fallback: true,'
,
'/* fallback: true, */'
)
)
try
{
await
check
(()
=>
renderViaHTTP
(
appPort
,
'/blog/post-1'
),
errMsg
)
await
fs
.
writeFile
(
blogPage
,
origContent
)
await
check
(()
=>
renderViaHTTP
(
appPort
,
'/blog/post-1'
),
/post-1/
)
}
finally
{
await
fs
.
writeFile
(
blogPage
,
origContent
)
}
})
})
describe
(
'serverless mode'
,
()
=>
{
describe
(
'serverless mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
await
fs
.
writeFile
(
await
fs
.
writeFile
(
...
...
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