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
99aea513
Unverified
Commit
99aea513
authored
Mar 15, 2022
by
Jiachi Liu
Committed by
GitHub
Mar 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhance: cover re-exported gsp cases for runtime fallback (#35326)
Cover re-exported gsp cases from #35011
parent
2e16d02f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
7 deletions
+37
-7
entries.ts
packages/next/build/entries.ts
+20
-5
fallback-re-export-gsp.js
test/unit/fixtures/page-runtime/fallback-re-export-gsp.js
+5
-0
fallback-with-gsp.js
test/unit/fixtures/page-runtime/fallback-with-gsp.js
+0
-0
parse-page-runtime.test.ts
test/unit/parse-page-runtime.test.ts
+12
-2
No files found.
packages/next/build/entries.ts
View file @
99aea513
...
...
@@ -144,7 +144,7 @@ export async function getPageRuntime(
for
(
const
node
of
body
)
{
const
{
type
,
declaration
}
=
node
if
(
type
===
'ExportDeclaration'
)
{
// `export const config`
//
Match
`export const config`
const
valueNode
=
declaration
?.
declarations
?.[
0
]
if
(
valueNode
?.
id
?.
value
===
'config'
)
{
const
props
=
valueNode
.
init
.
properties
...
...
@@ -155,15 +155,30 @@ export async function getPageRuntime(
pageRuntime
=
runtime
===
'edge'
||
runtime
===
'nodejs'
?
runtime
:
pageRuntime
}
else
if
(
declaration
?.
type
===
'FunctionDeclaration'
)
{
//
`export function getStaticProps` and
// `export function getServerSideProps`
//
Match `export function getStaticProps | getServerSideProps`
const
identifier
=
declaration
.
identifier
?.
value
if
(
declaration
.
identifier
?.
value
===
'getStaticProps'
||
declaration
.
identifier
?.
value
===
'getServerSideProps'
identifier
===
'getStaticProps'
||
identifier
===
'getServerSideProps'
)
{
isRuntimeRequired
=
true
}
}
}
else
if
(
type
===
'ExportNamedDeclaration'
)
{
// Match `export { getStaticProps | getServerSideProps } <from '../..'>`
const
{
specifiers
}
=
node
for
(
const
specifier
of
specifiers
)
{
const
{
orig
}
=
specifier
const
hasDataFetchingExports
=
specifier
.
type
===
'ExportSpecifier'
&&
orig
?.
type
===
'Identifier'
&&
(
orig
?.
value
===
'getStaticProps'
||
orig
?.
value
===
'getServerSideProps'
)
if
(
hasDataFetchingExports
)
{
isRuntimeRequired
=
true
break
}
}
}
}
}
catch
(
err
)
{}
...
...
test/unit/fixtures/page-runtime/fallback-re-export-gsp.js
0 → 100644
View file @
99aea513
export
{
getStaticProps
}
from
'../lib/utils'
export
default
function
ImportGsp
({
gsp
})
{
return
`import-
${
gsp
}
`
}
test/unit/fixtures/page-runtime/fallback.js
→
test/unit/fixtures/page-runtime/fallback
-with-gsp
.js
View file @
99aea513
File moved
test/unit/parse-page-runtime.test.ts
View file @
99aea513
...
...
@@ -24,10 +24,20 @@ describe('parse page runtime config', () => {
)
expect
(
runtime
).
toBe
(
undefined
)
})
})
describe
(
'fallback to the global runtime configuration'
,
()
=>
{
it
(
'should fallback when gSP is defined and exported'
,
async
()
=>
{
const
runtime
=
await
getPageRuntime
(
join
(
fixtureDir
,
'page-runtime/fallback-with-gsp.js'
),
'edge'
)
expect
(
runtime
).
toBe
(
'edge'
)
})
it
(
'should fallback
to the global runtime configuration if a runtime is needed
'
,
async
()
=>
{
it
(
'should fallback
when gSP is re-exported from other module
'
,
async
()
=>
{
const
runtime
=
await
getPageRuntime
(
join
(
fixtureDir
,
'page-runtime/fallback.js'
),
join
(
fixtureDir
,
'page-runtime/fallback
-re-export-gsp
.js'
),
'edge'
)
expect
(
runtime
).
toBe
(
'edge'
)
...
...
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