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
5de6f46d
Unverified
Commit
5de6f46d
authored
Oct 24, 2022
by
Jiachi Liu
Committed by
GitHub
Oct 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support next option for Request (#41614)
Follow up for #41505. Addding `next` option to Request options
parent
496b2eb7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
16 deletions
+43
-16
app-render.tsx
packages/next/server/app-render.tsx
+10
-10
node-polyfill-fetch.js
packages/next/server/node-polyfill-fetch.js
+12
-1
context.ts
packages/next/server/web/sandbox/context.ts
+2
-0
global.d.ts
packages/next/types/global.d.ts
+8
-5
page.tsx
test/e2e/app-dir/app-alias/src/app/typing/page.tsx
+11
-0
No files found.
packages/next/server/app-render.tsx
View file @
5de6f46d
...
...
@@ -208,8 +208,8 @@ function patchFetch(ComponentMod: any) {
const
staticGenerationAsyncStorage
=
ComponentMod
.
staticGenerationAsyncStorage
const
origFetch
=
globalThis
.
fetch
globalThis
.
fetch
=
async
(
url
,
opts
)
=>
{
const
orig
in
Fetch
=
globalThis
.
fetch
globalThis
.
fetch
=
async
(
input
,
init
)
=>
{
const
staticGenerationStore
=
'getStore'
in
staticGenerationAsyncStorage
?
staticGenerationAsyncStorage
.
getStore
()
...
...
@@ -219,18 +219,18 @@ function patchFetch(ComponentMod: any) {
staticGenerationStore
||
{}
if
(
staticGenerationStore
&&
isStaticGeneration
)
{
if
(
opts
&&
typeof
opts
===
'object'
)
{
if
(
opts
.
cache
===
'no-store'
)
{
if
(
init
&&
typeof
init
===
'object'
)
{
if
(
init
.
cache
===
'no-store'
)
{
staticGenerationStore
.
revalidate
=
0
// TODO: ensure this error isn't logged to the user
// seems it's slipping through currently
throw
new
DynamicServerError
(
`no-store fetch
${
url
}${
pathname
?
`
${
pathname
}
`
:
''
}
`
`no-store fetch
${
input
}${
pathname
?
`
${
pathname
}
`
:
''
}
`
)
}
const
hasNextConfig
=
'next'
in
opts
const
next
=
(
hasNextConfig
&&
opts
.
next
)
||
{}
const
hasNextConfig
=
'next'
in
init
const
next
=
init
.
next
||
{}
if
(
typeof
next
.
revalidate
===
'number'
&&
(
typeof
fetchRevalidate
===
'undefined'
||
...
...
@@ -241,15 +241,15 @@ function patchFetch(ComponentMod: any) {
// TODO: ensure this error isn't logged to the user
// seems it's slipping through currently
throw
new
DynamicServerError
(
`revalidate:
${
next
.
revalidate
}
fetch
${
url
}${
`revalidate:
${
next
.
revalidate
}
fetch
${
input
}${
pathname
?
`
${
pathname
}
`
:
''
}
`
)
}
if
(
hasNextConfig
)
delete
opts
.
next
if
(
hasNextConfig
)
delete
init
.
next
}
}
return
orig
Fetch
(
url
,
opts
)
return
orig
inFetch
(
input
,
init
)
}
}
...
...
packages/next/server/node-polyfill-fetch.js
View file @
5de6f46d
...
...
@@ -6,6 +6,17 @@ if (!global.fetch) {
?
require
(
'next/dist/compiled/undici'
)
:
require
(
'next/dist/compiled/node-fetch'
)
}
function
getRequestImpl
()
{
const
OriginRequest
=
getFetchImpl
().
Request
return
class
Request
extends
OriginRequest
{
constructor
(
input
,
init
)
{
super
(
input
,
init
)
this
.
next
=
init
?.
next
}
}
}
// Due to limitation of global configuration, we have to do this resolution at runtime
global
.
fetch
=
(...
args
)
=>
{
const
fetchImpl
=
getFetchImpl
()
...
...
@@ -44,7 +55,7 @@ if (!global.fetch) {
},
Request
:
{
get
()
{
return
get
FetchImpl
().
Request
return
get
RequestImpl
()
},
},
Response
:
{
...
...
packages/next/server/web/sandbox/context.ts
View file @
5de6f46d
...
...
@@ -265,6 +265,7 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
const
__Request
=
context
.
Request
context
.
Request
=
class
extends
__Request
{
next
?:
NextFetchRequestConfig
|
undefined
constructor
(
input
:
URL
|
RequestInfo
,
init
?:
RequestInit
|
undefined
)
{
const
url
=
typeof
input
!==
'string'
&&
'url'
in
input
...
...
@@ -272,6 +273,7 @@ Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation`),
:
String
(
input
)
validateURL
(
url
)
super
(
url
,
init
)
this
.
next
=
init
?.
next
}
}
...
...
packages/next/types/global.d.ts
View file @
5de6f46d
...
...
@@ -12,6 +12,10 @@ declare namespace NodeJS {
interface
ProcessEnv
{
readonly
NODE_ENV
:
'development'
|
'production'
|
'test'
}
interface
RequestInit
extends
globalThis
.
RequestInit
{
next
?:
NextFetchRequestConfig
|
undefined
}
}
declare
module
'*.module.css'
{
...
...
@@ -34,11 +38,10 @@ interface Window {
__NEXT_HMR_CB
?:
null
|
((
message
?:
string
)
=>
void
)
}
type
NextFetchRequestConfig
=
{
interface
NextFetchRequestConfig
{
revalidate
?:
number
}
declare
function
fetch
(
url
:
RequestInfo
,
opts
:
RequestInit
&
{
next
?:
NextFetchRequestConfig
}
):
Promise
<
Response
>
interface
RequestInit
{
next
?:
NextFetchRequestConfig
|
undefined
}
test/e2e/app-dir/app-alias/src/app/typing/page.tsx
0 → 100644
View file @
5de6f46d
// Typing test
// eslint-disable-next-line
function
noop
()
{
fetch
(
'/button'
,
{
next
:
{
revalidate
:
0
}
})
const
request
=
new
Request
(
'/button'
,
{
next
:
{
revalidate
:
0
}
})
fetch
(
request
)
}
export
default
function
page
()
{
return
'typing'
}
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