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
8253fa09
Unverified
Commit
8253fa09
authored
Jun 01, 2023
by
JJ Kasper
Committed by
GitHub
Jun 01, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add experimental id handling (#50470)
x-ref: [slack thread](
https://vercel.slack.com/archives/C04TNLL0LSK/p1684879925060159
)
parent
0c3cc045
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
276 additions
and
63 deletions
+276
-63
webpack-config.ts
packages/next/src/build/webpack-config.ts
+6
-0
app-index.tsx
packages/next/src/client/app-index.tsx
+8
-1
server-action-reducer.ts
...mponents/router-reducer/reducers/server-action-reducer.ts
+6
-0
route-loader.ts
packages/next/src/client/route-loader.ts
+12
-3
index.ts
packages/next/src/export/index.ts
+1
-0
worker.ts
packages/next/src/export/worker.ts
+4
-0
_document.tsx
packages/next/src/pages/_document.tsx
+30
-39
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+40
-12
types.ts
packages/next/src/server/app-render/types.ts
+1
-0
base-server.ts
packages/next/src/server/base-server.ts
+9
-0
config-schema.ts
packages/next/src/server/config-schema.ts
+6
-0
config-shared.ts
packages/next/src/server/config-shared.ts
+4
-0
render-result.ts
packages/next/src/server/render-result.ts
+1
-1
render.tsx
packages/next/src/server/render.tsx
+13
-6
html-context.ts
packages/next/src/shared/lib/html-context.ts
+1
-1
image-loader.ts
packages/next/src/shared/lib/image-loader.ts
+4
-0
page.tsx
...ion/deployment-id-handling/app/app/from-app/edge/page.tsx
+14
-0
page.tsx
...oduction/deployment-id-handling/app/app/from-app/page.tsx
+11
-0
layout.tsx
test/production/deployment-id-handling/app/app/layout.tsx
+15
-0
global.css
test/production/deployment-id-handling/app/global.css
+5
-0
_app.tsx
test/production/deployment-id-handling/app/pages/_app.tsx
+14
-0
index.tsx
test/production/deployment-id-handling/app/pages/index.tsx
+11
-0
pages-edge.tsx
...roduction/deployment-id-handling/app/pages/pages-edge.tsx
+15
-0
test.jpg
test/production/deployment-id-handling/app/public/test.jpg
+0
-0
deployment-id-handling.test.ts
...ion/deployment-id-handling/deployment-id-handling.test.ts
+45
-0
No files found.
packages/next/src/build/webpack-config.ts
View file @
8253fa09
...
@@ -251,6 +251,12 @@ export function getDefineEnv({
...
@@ -251,6 +251,12 @@ export function getDefineEnv({
'process.env.NEXT_RUNTIME'
:
JSON
.
stringify
(
'process.env.NEXT_RUNTIME'
:
JSON
.
stringify
(
isEdgeServer
?
'edge'
:
isNodeServer
?
'nodejs'
:
undefined
isEdgeServer
?
'edge'
:
isNodeServer
?
'nodejs'
:
undefined
),
),
'process.env.__NEXT_ACTIONS_DEPLOYMENT_ID'
:
JSON
.
stringify
(
config
.
experimental
.
useDeploymentIdServerActions
),
'process.env.__NEXT_DEPLOYMENT_ID'
:
JSON
.
stringify
(
config
.
experimental
.
deploymentId
),
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX'
:
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX'
:
JSON
.
stringify
(
fetchCacheKeyPrefix
),
JSON
.
stringify
(
fetchCacheKeyPrefix
),
'process.env.__NEXT_PREVIEW_MODE_ID'
:
JSON
.
stringify
(
previewModeId
),
'process.env.__NEXT_PREVIEW_MODE_ID'
:
JSON
.
stringify
(
previewModeId
),
...
...
packages/next/src/client/app-index.tsx
View file @
8253fa09
...
@@ -45,7 +45,14 @@ const chunkFilenameMap: any = {}
...
@@ -45,7 +45,14 @@ const chunkFilenameMap: any = {}
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
__webpack_require__
.
u
=
(
chunkId
:
any
)
=>
{
__webpack_require__
.
u
=
(
chunkId
:
any
)
=>
{
return
encodeURI
(
chunkFilenameMap
[
chunkId
]
||
getChunkScriptFilename
(
chunkId
))
return
(
encodeURI
(
chunkFilenameMap
[
chunkId
]
||
getChunkScriptFilename
(
chunkId
))
+
`
${
process
.
env
.
__NEXT_DEPLOYMENT_ID
?
`?dpl=
${
process
.
env
.
__NEXT_DEPLOYMENT_ID
}
`
:
''
}
`
)
}
}
// Ignore the module ID transform in client.
// Ignore the module ID transform in client.
...
...
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts
View file @
8253fa09
...
@@ -44,6 +44,12 @@ async function fetchServerAction(
...
@@ -44,6 +44,12 @@ async function fetchServerAction(
Accept
:
RSC_CONTENT_TYPE_HEADER
,
Accept
:
RSC_CONTENT_TYPE_HEADER
,
'Next-Action'
:
actionId
,
'Next-Action'
:
actionId
,
[
NEXT_ROUTER_STATE_TREE
]:
JSON
.
stringify
(
state
.
tree
),
[
NEXT_ROUTER_STATE_TREE
]:
JSON
.
stringify
(
state
.
tree
),
...(
process
.
env
.
__NEXT_ACTIONS_DEPLOYMENT_ID
&&
process
.
env
.
__NEXT_DEPLOYMENT_ID
?
{
'x-deployment-id'
:
process
.
env
.
__NEXT_DEPLOYMENT_ID
,
}
:
{}),
...(
state
.
nextUrl
...(
state
.
nextUrl
?
{
?
{
[
NEXT_URL
]:
state
.
nextUrl
,
[
NEXT_URL
]:
state
.
nextUrl
,
...
...
packages/next/src/client/route-loader.ts
View file @
8253fa09
...
@@ -106,6 +106,12 @@ function hasPrefetch(link?: HTMLLinkElement): boolean {
...
@@ -106,6 +106,12 @@ function hasPrefetch(link?: HTMLLinkElement): boolean {
const
canPrefetch
:
boolean
=
hasPrefetch
()
const
canPrefetch
:
boolean
=
hasPrefetch
()
const
getAssetQueryString
=
()
=>
{
return
process
.
env
.
__NEXT_DEPLOYMENT_ID
?
`?dpl=
${
process
.
env
.
__NEXT_DEPLOYMENT_ID
}
`
:
''
}
function
prefetchViaDom
(
function
prefetchViaDom
(
href
:
string
,
href
:
string
,
as
:
string
,
as
:
string
,
...
@@ -246,7 +252,8 @@ function getFilesForRoute(
...
@@ -246,7 +252,8 @@ function getFilesForRoute(
const
scriptUrl
=
const
scriptUrl
=
assetPrefix
+
assetPrefix
+
'/_next/static/chunks/pages'
+
'/_next/static/chunks/pages'
+
encodeURI
(
getAssetPathFromRoute
(
route
,
'.js'
))
encodeURI
(
getAssetPathFromRoute
(
route
,
'.js'
))
+
getAssetQueryString
()
return
Promise
.
resolve
({
return
Promise
.
resolve
({
scripts
:
[
__unsafeCreateTrustedScriptURL
(
scriptUrl
)],
scripts
:
[
__unsafeCreateTrustedScriptURL
(
scriptUrl
)],
// Styles are handled by `style-loader` in development:
// Styles are handled by `style-loader` in development:
...
@@ -263,8 +270,10 @@ function getFilesForRoute(
...
@@ -263,8 +270,10 @@ function getFilesForRoute(
return
{
return
{
scripts
:
allFiles
scripts
:
allFiles
.
filter
((
v
)
=>
v
.
endsWith
(
'.js'
))
.
filter
((
v
)
=>
v
.
endsWith
(
'.js'
))
.
map
((
v
)
=>
__unsafeCreateTrustedScriptURL
(
v
)),
.
map
((
v
)
=>
__unsafeCreateTrustedScriptURL
(
v
)
+
getAssetQueryString
()),
css
:
allFiles
.
filter
((
v
)
=>
v
.
endsWith
(
'.css'
)),
css
:
allFiles
.
filter
((
v
)
=>
v
.
endsWith
(
'.css'
))
.
map
((
v
)
=>
v
+
getAssetQueryString
()),
}
}
})
})
}
}
...
...
packages/next/src/export/index.ts
View file @
8253fa09
...
@@ -493,6 +493,7 @@ export default async function exportApp(
...
@@ -493,6 +493,7 @@ export default async function exportApp(
}
}
:
{}),
:
{}),
strictNextHead
:
!!
nextConfig
.
experimental
.
strictNextHead
,
strictNextHead
:
!!
nextConfig
.
experimental
.
strictNextHead
,
deploymentId
:
nextConfig
.
experimental
.
deploymentId
,
}
}
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
nextConfig
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
nextConfig
...
...
packages/next/src/export/worker.ts
View file @
8253fa09
...
@@ -119,6 +119,7 @@ interface RenderOpts {
...
@@ -119,6 +119,7 @@ interface RenderOpts {
incrementalCache
?:
IncrementalCache
incrementalCache
?:
IncrementalCache
strictNextHead
?:
boolean
strictNextHead
?:
boolean
originalPathname
?:
string
originalPathname
?:
string
deploymentId
?:
string
}
}
export
default
async
function
exportPage
({
export
default
async
function
exportPage
({
...
@@ -155,6 +156,9 @@ export default async function exportPage({
...
@@ -155,6 +156,9 @@ export default async function exportPage({
}
}
try
{
try
{
if
(
renderOpts
.
deploymentId
)
{
process
.
env
.
__NEXT_DEPLOYMENT_ID
=
renderOpts
.
deploymentId
}
const
{
query
:
originalQuery
=
{}
}
=
pathMap
const
{
query
:
originalQuery
=
{}
}
=
pathMap
const
{
page
}
=
pathMap
const
{
page
}
=
pathMap
const
pathname
=
normalizeAppPath
(
page
)
const
pathname
=
normalizeAppPath
(
page
)
...
...
packages/next/src/pages/_document.tsx
View file @
8253fa09
...
@@ -68,7 +68,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) {
...
@@ -68,7 +68,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) {
const
{
const
{
assetPrefix
,
assetPrefix
,
buildManifest
,
buildManifest
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
disableOptimizedLoading
,
disableOptimizedLoading
,
crossOrigin
,
crossOrigin
,
}
=
context
}
=
context
...
@@ -84,7 +84,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) {
...
@@ -84,7 +84,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) {
nonce=
{
props
.
nonce
}
nonce=
{
props
.
nonce
}
crossOrigin=
{
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
props
.
crossOrigin
||
crossOrigin
}
noModule=
{
true
}
noModule=
{
true
}
src=
{
`${assetPrefix}/_next/${polyfill}${
devOnlyCacheBuster
QueryString}`
}
src=
{
`${assetPrefix}/_next/${polyfill}${
asset
QueryString}`
}
/>
/>
))
))
}
}
...
@@ -146,7 +146,7 @@ function getDynamicChunks(
...
@@ -146,7 +146,7 @@ function getDynamicChunks(
dynamicImports
,
dynamicImports
,
assetPrefix
,
assetPrefix
,
isDevelopment
,
isDevelopment
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
disableOptimizedLoading
,
disableOptimizedLoading
,
crossOrigin
,
crossOrigin
,
}
=
context
}
=
context
...
@@ -159,9 +159,7 @@ function getDynamicChunks(
...
@@ -159,9 +159,7 @@ function getDynamicChunks(
async=
{
!
isDevelopment
&&
disableOptimizedLoading
}
async=
{
!
isDevelopment
&&
disableOptimizedLoading
}
defer=
{
!
disableOptimizedLoading
}
defer=
{
!
disableOptimizedLoading
}
key=
{
file
}
key=
{
file
}
src=
{
`${assetPrefix}/_next/${encodeURI(
src=
{
`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`
}
file
)}${devOnlyCacheBusterQueryString}`
}
nonce=
{
props
.
nonce
}
nonce=
{
props
.
nonce
}
crossOrigin=
{
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
props
.
crossOrigin
||
crossOrigin
}
/>
/>
...
@@ -178,7 +176,7 @@ function getScripts(
...
@@ -178,7 +176,7 @@ function getScripts(
assetPrefix
,
assetPrefix
,
buildManifest
,
buildManifest
,
isDevelopment
,
isDevelopment
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
disableOptimizedLoading
,
disableOptimizedLoading
,
crossOrigin
,
crossOrigin
,
}
=
context
}
=
context
...
@@ -192,9 +190,7 @@ function getScripts(
...
@@ -192,9 +190,7 @@ function getScripts(
return
(
return
(
<
script
<
script
key=
{
file
}
key=
{
file
}
src=
{
`${assetPrefix}/_next/${encodeURI(
src=
{
`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`
}
file
)}${devOnlyCacheBusterQueryString}`
}
nonce=
{
props
.
nonce
}
nonce=
{
props
.
nonce
}
async=
{
!
isDevelopment
&&
disableOptimizedLoading
}
async=
{
!
isDevelopment
&&
disableOptimizedLoading
}
defer=
{
!
disableOptimizedLoading
}
defer=
{
!
disableOptimizedLoading
}
...
@@ -358,7 +354,8 @@ function getAmpPath(ampPath: string, asPath: string): string {
...
@@ -358,7 +354,8 @@ function getAmpPath(ampPath: string, asPath: string): string {
function
getNextFontLinkTags
(
function
getNextFontLinkTags
(
nextFontManifest
:
NextFontManifest
|
undefined
,
nextFontManifest
:
NextFontManifest
|
undefined
,
dangerousAsPath
:
string
,
dangerousAsPath
:
string
,
assetPrefix
:
string
=
''
assetPrefix
:
string
=
''
,
assetQueryString
:
string
=
''
)
{
)
{
if
(
!
nextFontManifest
)
{
if
(
!
nextFontManifest
)
{
return
{
return
{
...
@@ -381,6 +378,11 @@ function getNextFontLinkTags(
...
@@ -381,6 +378,11 @@ function getNextFontLinkTags(
(
appFontsEntry
||
pageFontsEntry
)
(
appFontsEntry
||
pageFontsEntry
)
)
)
// we only add if the dpl query is present for fonts
if
(
!
assetQueryString
.
includes
(
'dpl='
))
{
assetQueryString
=
''
}
return
{
return
{
preconnect
:
preconnectToSelf
?
(
preconnect
:
preconnectToSelf
?
(
<
link
<
link
...
@@ -399,7 +401,9 @@ function getNextFontLinkTags(
...
@@ -399,7 +401,9 @@ function getNextFontLinkTags(
<
link
<
link
key=
{
fontFile
}
key=
{
fontFile
}
rel=
"preload"
rel=
"preload"
href=
{
`${assetPrefix}/_next/${encodeURI(fontFile)}`
}
href=
{
`${assetPrefix}/_next/${encodeURI(
fontFile
)}${assetQueryString}`
}
as=
"font"
as=
"font"
type=
{
`font/${ext}`
}
type=
{
`font/${ext}`
}
crossOrigin=
"anonymous"
crossOrigin=
"anonymous"
...
@@ -425,7 +429,7 @@ export class Head extends React.Component<HeadProps> {
...
@@ -425,7 +429,7 @@ export class Head extends React.Component<HeadProps> {
getCssLinks
(
files
:
DocumentFiles
):
JSX
.
Element
[]
|
null
{
getCssLinks
(
files
:
DocumentFiles
):
JSX
.
Element
[]
|
null
{
const
{
const
{
assetPrefix
,
assetPrefix
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
dynamicImports
,
dynamicImports
,
crossOrigin
,
crossOrigin
,
optimizeCss
,
optimizeCss
,
...
@@ -459,9 +463,7 @@ export class Head extends React.Component<HeadProps> {
...
@@ -459,9 +463,7 @@ export class Head extends React.Component<HeadProps> {
key=
{
`${file}-preload`
}
key=
{
`${file}-preload`
}
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
rel=
"preload"
rel=
"preload"
href=
{
`${assetPrefix}/_next/${encodeURI(
href=
{
`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`
}
file
)}${devOnlyCacheBusterQueryString}`
}
as=
"style"
as=
"style"
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
/>
/>
...
@@ -474,9 +476,7 @@ export class Head extends React.Component<HeadProps> {
...
@@ -474,9 +476,7 @@ export class Head extends React.Component<HeadProps> {
key=
{
file
}
key=
{
file
}
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
rel=
"stylesheet"
rel=
"stylesheet"
href=
{
`${assetPrefix}/_next/${encodeURI(
href=
{
`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`
}
file
)}${devOnlyCacheBusterQueryString}`
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
data
-
n
-
g=
{
isUnmanagedFile
?
undefined
:
isSharedFile
?
''
:
undefined
}
data
-
n
-
g=
{
isUnmanagedFile
?
undefined
:
isSharedFile
?
''
:
undefined
}
data
-
n
-
p=
{
isUnmanagedFile
?
undefined
:
isSharedFile
?
undefined
:
''
}
data
-
n
-
p=
{
isUnmanagedFile
?
undefined
:
isSharedFile
?
undefined
:
''
}
...
@@ -494,12 +494,8 @@ export class Head extends React.Component<HeadProps> {
...
@@ -494,12 +494,8 @@ export class Head extends React.Component<HeadProps> {
}
}
getPreloadDynamicChunks
()
{
getPreloadDynamicChunks
()
{
const
{
const
{
dynamicImports
,
assetPrefix
,
assetQueryString
,
crossOrigin
}
=
dynamicImports
,
this
.
context
assetPrefix
,
devOnlyCacheBusterQueryString
,
crossOrigin
,
}
=
this
.
context
return
(
return
(
dynamicImports
dynamicImports
...
@@ -514,7 +510,7 @@ export class Head extends React.Component<HeadProps> {
...
@@ -514,7 +510,7 @@ export class Head extends React.Component<HeadProps> {
key=
{
file
}
key=
{
file
}
href=
{
`${assetPrefix}/_next/${encodeURI(
href=
{
`${assetPrefix}/_next/${encodeURI(
file
file
)}${
devOnlyCacheBuster
QueryString}`
}
)}${
asset
QueryString}`
}
as=
"script"
as=
"script"
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
...
@@ -527,12 +523,8 @@ export class Head extends React.Component<HeadProps> {
...
@@ -527,12 +523,8 @@ export class Head extends React.Component<HeadProps> {
}
}
getPreloadMainLinks
(
files
:
DocumentFiles
):
JSX
.
Element
[]
|
null
{
getPreloadMainLinks
(
files
:
DocumentFiles
):
JSX
.
Element
[]
|
null
{
const
{
const
{
assetPrefix
,
assetQueryString
,
scriptLoader
,
crossOrigin
}
=
assetPrefix
,
this
.
context
devOnlyCacheBusterQueryString
,
scriptLoader
,
crossOrigin
,
}
=
this
.
context
const
preloadFiles
=
files
.
allFiles
.
filter
((
file
:
string
)
=>
{
const
preloadFiles
=
files
.
allFiles
.
filter
((
file
:
string
)
=>
{
return
file
.
endsWith
(
'.js'
)
return
file
.
endsWith
(
'.js'
)
})
})
...
@@ -553,9 +545,7 @@ export class Head extends React.Component<HeadProps> {
...
@@ -553,9 +545,7 @@ export class Head extends React.Component<HeadProps> {
key=
{
file
}
key=
{
file
}
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
rel=
"preload"
rel=
"preload"
href=
{
`${assetPrefix}/_next/${encodeURI(
href=
{
`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`
}
file
)}${devOnlyCacheBusterQueryString}`
}
as=
"script"
as=
"script"
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
/>
/>
...
@@ -810,7 +800,8 @@ export class Head extends React.Component<HeadProps> {
...
@@ -810,7 +800,8 @@ export class Head extends React.Component<HeadProps> {
const
nextFontLinkTags
=
getNextFontLinkTags
(
const
nextFontLinkTags
=
getNextFontLinkTags
(
nextFontManifest
,
nextFontManifest
,
dangerousAsPath
,
dangerousAsPath
,
assetPrefix
assetPrefix
,
this
.
context
.
assetQueryString
)
)
return
(
return
(
...
@@ -1073,7 +1064,7 @@ export class NextScript extends React.Component<OriginProps> {
...
@@ -1073,7 +1064,7 @@ export class NextScript extends React.Component<OriginProps> {
buildManifest
,
buildManifest
,
unstable_runtimeJS
,
unstable_runtimeJS
,
docComponentsRendered
,
docComponentsRendered
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
disableOptimizedLoading
,
disableOptimizedLoading
,
crossOrigin
,
crossOrigin
,
}
=
this
.
context
}
=
this
.
context
...
@@ -1108,7 +1099,7 @@ export class NextScript extends React.Component<OriginProps> {
...
@@ -1108,7 +1099,7 @@ export class NextScript extends React.Component<OriginProps> {
{
ampDevFiles
.
map
((
file
)
=>
(
{
ampDevFiles
.
map
((
file
)
=>
(
<
script
<
script
key=
{
file
}
key=
{
file
}
src=
{
`${assetPrefix}/_next/${file}${
devOnlyCacheBuster
QueryString}`
}
src=
{
`${assetPrefix}/_next/${file}${
asset
QueryString}`
}
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
data
-
ampdevmode
data
-
ampdevmode
...
@@ -1139,7 +1130,7 @@ export class NextScript extends React.Component<OriginProps> {
...
@@ -1139,7 +1130,7 @@ export class NextScript extends React.Component<OriginProps> {
key=
{
file
}
key=
{
file
}
src=
{
`${assetPrefix}/_next/${encodeURI(
src=
{
`${assetPrefix}/_next/${encodeURI(
file
file
)}${
devOnlyCacheBuster
QueryString}`
}
)}${
asset
QueryString}`
}
nonce=
{
this
.
props
.
nonce
}
nonce=
{
this
.
props
.
nonce
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
crossOrigin=
{
this
.
props
.
crossOrigin
||
crossOrigin
}
/>
/>
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
8253fa09
...
@@ -362,6 +362,20 @@ export async function renderToHTMLOrFlight(
...
@@ -362,6 +362,20 @@ export async function renderToHTMLOrFlight(
const
assetPrefix
=
renderOpts
.
assetPrefix
||
''
const
assetPrefix
=
renderOpts
.
assetPrefix
||
''
const
getAssetQueryString
=
(
addTimestamp
:
boolean
)
=>
{
const
isDev
=
process
.
env
.
NODE_ENV
===
'development'
let
qs
=
''
if
(
isDev
&&
addTimestamp
)
{
qs
+=
`?v=
${
Date
.
now
()}
`
}
if
(
renderOpts
.
deploymentId
)
{
qs
+=
`
${
isDev
?
'&'
:
'?'
}
dpl=
${
renderOpts
.
deploymentId
}
`
}
return
qs
}
const
createComponentAndStyles
=
async
({
const
createComponentAndStyles
=
async
({
filePath
,
filePath
,
getComponent
,
getComponent
,
...
@@ -389,9 +403,9 @@ export async function renderToHTMLOrFlight(
...
@@ -389,9 +403,9 @@ export async function renderToHTMLOrFlight(
// Because of this, we add a `?v=` query to bypass the cache during
// Because of this, we add a `?v=` query to bypass the cache during
// development. We need to also make sure that the number is always
// development. We need to also make sure that the number is always
// increasing.
// increasing.
const
fullHref
=
`
${
assetPrefix
}
/_next/
${
href
}${
const
fullHref
=
`
${
assetPrefix
}
/_next/
${
href
}${
getAssetQueryString
(
process
.
env
.
NODE_ENV
===
'development'
?
`?v=
${
Date
.
now
()}
`
:
''
true
}
`
)
}
`
// `Precedence` is an opt-in signal for React to handle resource
// `Precedence` is an opt-in signal for React to handle resource
// loading and deduplication, etc. It's also used as the key to sort
// loading and deduplication, etc. It's also used as the key to sort
...
@@ -458,7 +472,9 @@ export async function renderToHTMLOrFlight(
...
@@ -458,7 +472,9 @@ export async function renderToHTMLOrFlight(
const
fontFilename
=
preloadedFontFiles
[
i
]
const
fontFilename
=
preloadedFontFiles
[
i
]
const
ext
=
/
\.(
woff|woff2|eot|ttf|otf
)
$/
.
exec
(
fontFilename
)
!
[
1
]
const
ext
=
/
\.(
woff|woff2|eot|ttf|otf
)
$/
.
exec
(
fontFilename
)
!
[
1
]
const
type
=
`font/
${
ext
}
`
const
type
=
`font/
${
ext
}
`
const
href
=
`
${
assetPrefix
}
/_next/
${
fontFilename
}
`
const
href
=
`
${
assetPrefix
}
/_next/
${
fontFilename
}${
getAssetQueryString
(
false
)}
`
ComponentMod
.
preloadFont
(
href
,
type
)
ComponentMod
.
preloadFont
(
href
,
type
)
}
}
}
else
{
}
else
{
...
@@ -481,9 +497,9 @@ export async function renderToHTMLOrFlight(
...
@@ -481,9 +497,9 @@ export async function renderToHTMLOrFlight(
// Because of this, we add a `?v=` query to bypass the cache during
// Because of this, we add a `?v=` query to bypass the cache during
// development. We need to also make sure that the number is always
// development. We need to also make sure that the number is always
// increasing.
// increasing.
const
fullHref
=
`
${
assetPrefix
}
/_next/
${
href
}${
const
fullHref
=
`
${
assetPrefix
}
/_next/
${
href
}${
getAssetQueryString
(
process
.
env
.
NODE_ENV
===
'development'
?
`?v=
${
Date
.
now
()}
`
:
''
true
}
`
)
}
`
// `Precedence` is an opt-in signal for React to handle resource
// `Precedence` is an opt-in signal for React to handle resource
// loading and deduplication, etc. It's also used as the key to sort
// loading and deduplication, etc. It's also used as the key to sort
...
@@ -1392,7 +1408,9 @@ export async function renderToHTMLOrFlight(
...
@@ -1392,7 +1408,9 @@ export async function renderToHTMLOrFlight(
polyfill
.
endsWith
(
'.js'
)
&&
!
polyfill
.
endsWith
(
'.module.js'
)
polyfill
.
endsWith
(
'.js'
)
&&
!
polyfill
.
endsWith
(
'.module.js'
)
)
)
.
map
((
polyfill
)
=>
({
.
map
((
polyfill
)
=>
({
src
:
`
${
assetPrefix
}
/_next/
${
polyfill
}
`
,
src
:
`
${
assetPrefix
}
/_next/
${
polyfill
}${
getAssetQueryString
(
false
)}
`
,
integrity
:
subresourceIntegrityManifest
?.[
polyfill
],
integrity
:
subresourceIntegrityManifest
?.[
polyfill
],
}))
}))
...
@@ -1471,11 +1489,17 @@ export async function renderToHTMLOrFlight(
...
@@ -1471,11 +1489,17 @@ export async function renderToHTMLOrFlight(
bootstrapScripts
:
[
bootstrapScripts
:
[
...(
subresourceIntegrityManifest
...(
subresourceIntegrityManifest
?
buildManifest
.
rootMainFiles
.
map
((
src
)
=>
({
?
buildManifest
.
rootMainFiles
.
map
((
src
)
=>
({
src
:
`
${
assetPrefix
}
/_next/`
+
src
,
src
:
`
${
assetPrefix
}
/_next/`
+
src
+
getAssetQueryString
(
false
),
integrity
:
subresourceIntegrityManifest
[
src
],
integrity
:
subresourceIntegrityManifest
[
src
],
}))
}))
:
buildManifest
.
rootMainFiles
.
map
(
:
buildManifest
.
rootMainFiles
.
map
(
(
src
)
=>
`
${
assetPrefix
}
/_next/`
+
src
(
src
)
=>
`
${
assetPrefix
}
/_next/`
+
src
+
getAssetQueryString
(
false
)
)),
)),
],
],
},
},
...
@@ -1547,11 +1571,15 @@ export async function renderToHTMLOrFlight(
...
@@ -1547,11 +1571,15 @@ export async function renderToHTMLOrFlight(
// Include hydration scripts in the HTML
// Include hydration scripts in the HTML
bootstrapScripts
:
subresourceIntegrityManifest
bootstrapScripts
:
subresourceIntegrityManifest
?
buildManifest
.
rootMainFiles
.
map
((
src
)
=>
({
?
buildManifest
.
rootMainFiles
.
map
((
src
)
=>
({
src
:
`
${
assetPrefix
}
/_next/`
+
src
,
src
:
`
${
assetPrefix
}
/_next/`
+
src
+
getAssetQueryString
(
false
),
integrity
:
subresourceIntegrityManifest
[
src
],
integrity
:
subresourceIntegrityManifest
[
src
],
}))
}))
:
buildManifest
.
rootMainFiles
.
map
(
:
buildManifest
.
rootMainFiles
.
map
(
(
src
)
=>
`
${
assetPrefix
}
/_next/`
+
src
(
src
)
=>
`
${
assetPrefix
}
/_next/`
+
src
+
getAssetQueryString
(
false
)
),
),
},
},
})
})
...
...
packages/next/src/server/app-render/types.ts
View file @
8253fa09
...
@@ -132,6 +132,7 @@ export type RenderOptsPartial = {
...
@@ -132,6 +132,7 @@ export type RenderOptsPartial = {
nextConfigOutput
?:
'standalone'
|
'export'
nextConfigOutput
?:
'standalone'
|
'export'
appDirDevErrorLogger
?:
(
err
:
any
)
=>
Promise
<
void
>
appDirDevErrorLogger
?:
(
err
:
any
)
=>
Promise
<
void
>
originalPathname
?:
string
originalPathname
?:
string
deploymentId
?:
string
}
}
export
type
RenderOpts
=
LoadComponentsReturnType
&
RenderOptsPartial
export
type
RenderOpts
=
LoadComponentsReturnType
&
RenderOptsPartial
packages/next/src/server/base-server.ts
View file @
8253fa09
...
@@ -215,6 +215,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -215,6 +215,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected
readonly
buildId
:
string
protected
readonly
buildId
:
string
protected
readonly
minimalMode
:
boolean
protected
readonly
minimalMode
:
boolean
protected
readonly
renderOpts
:
{
protected
readonly
renderOpts
:
{
deploymentId
?:
string
poweredByHeader
:
boolean
poweredByHeader
:
boolean
buildId
:
string
buildId
:
string
generateEtags
:
boolean
generateEtags
:
boolean
...
@@ -417,7 +418,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -417,7 +418,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
:
undefined
:
undefined
this
.
nextFontManifest
=
this
.
getNextFontManifest
()
this
.
nextFontManifest
=
this
.
getNextFontManifest
()
if
(
process
.
env
.
NEXT_RUNTIME
!==
'edge'
)
{
if
(
this
.
nextConfig
.
experimental
.
deploymentId
)
{
process
.
env
.
__NEXT_DEPLOYMENT_ID
=
this
.
nextConfig
.
experimental
.
deploymentId
}
}
this
.
renderOpts
=
{
this
.
renderOpts
=
{
deploymentId
:
this
.
nextConfig
.
experimental
.
deploymentId
,
strictNextHead
:
!!
this
.
nextConfig
.
experimental
.
strictNextHead
,
strictNextHead
:
!!
this
.
nextConfig
.
experimental
.
strictNextHead
,
poweredByHeader
:
this
.
nextConfig
.
poweredByHeader
,
poweredByHeader
:
this
.
nextConfig
.
poweredByHeader
,
canonicalBase
:
this
.
nextConfig
.
amp
.
canonicalBase
||
''
,
canonicalBase
:
this
.
nextConfig
.
amp
.
canonicalBase
||
''
,
...
...
packages/next/src/server/config-schema.ts
View file @
8253fa09
...
@@ -270,6 +270,12 @@ const configSchema = {
...
@@ -270,6 +270,12 @@ const configSchema = {
craCompat
:
{
craCompat
:
{
type
:
'boolean'
,
type
:
'boolean'
,
},
},
useDeploymentIdServerActions
:
{
type
:
'boolean'
,
},
deploymentId
:
{
type
:
'string'
,
},
disableOptimizedLoading
:
{
disableOptimizedLoading
:
{
type
:
'boolean'
,
type
:
'boolean'
,
},
},
...
...
packages/next/src/server/config-shared.ts
View file @
8253fa09
...
@@ -144,6 +144,8 @@ export interface NextJsWebpackConfig {
...
@@ -144,6 +144,8 @@ export interface NextJsWebpackConfig {
}
}
export
interface
ExperimentalConfig
{
export
interface
ExperimentalConfig
{
useDeploymentIdServerActions
?:
boolean
deploymentId
?:
string
logging
?:
'verbose'
logging
?:
'verbose'
appDocumentPreloading
?:
boolean
appDocumentPreloading
?:
boolean
strictNextHead
?:
boolean
strictNextHead
?:
boolean
...
@@ -660,6 +662,8 @@ export const defaultConfig: NextConfig = {
...
@@ -660,6 +662,8 @@ export const defaultConfig: NextConfig = {
output
:
!!
process
.
env
.
NEXT_PRIVATE_STANDALONE
?
'standalone'
:
undefined
,
output
:
!!
process
.
env
.
NEXT_PRIVATE_STANDALONE
?
'standalone'
:
undefined
,
modularizeImports
:
undefined
,
modularizeImports
:
undefined
,
experimental
:
{
experimental
:
{
useDeploymentIdServerActions
:
false
,
deploymentId
:
process
.
env
.
NEXT_DEPLOYMENT_ID
||
''
,
appDocumentPreloading
:
undefined
,
appDocumentPreloading
:
undefined
,
clientRouterFilter
:
false
,
clientRouterFilter
:
false
,
clientRouterFilterRedirects
:
false
,
clientRouterFilterRedirects
:
false
,
...
...
packages/next/src/server/render-result.ts
View file @
8253fa09
...
@@ -7,7 +7,7 @@ export type RenderResultMetadata = {
...
@@ -7,7 +7,7 @@ export type RenderResultMetadata = {
pageData
?:
any
pageData
?:
any
revalidate
?:
any
revalidate
?:
any
staticBailoutInfo
?:
any
staticBailoutInfo
?:
any
devOnlyCacheBuster
QueryString
?:
string
asset
QueryString
?:
string
isNotFound
?:
boolean
isNotFound
?:
boolean
isRedirect
?:
boolean
isRedirect
?:
boolean
}
}
...
...
packages/next/src/server/render.tsx
View file @
8253fa09
...
@@ -246,7 +246,7 @@ export type RenderOptsPartial = {
...
@@ -246,7 +246,7 @@ export type RenderOptsPartial = {
optimizeCss
:
any
optimizeCss
:
any
nextConfigOutput
?:
'standalone'
|
'export'
nextConfigOutput
?:
'standalone'
|
'export'
nextScriptWorkers
:
any
nextScriptWorkers
:
any
devOnlyCacheBuster
QueryString
?:
string
asset
QueryString
?:
string
resolvedUrl
?:
string
resolvedUrl
?:
string
resolvedAsPath
?:
string
resolvedAsPath
?:
string
clientReferenceManifest
?:
ClientReferenceManifest
clientReferenceManifest
?:
ClientReferenceManifest
...
@@ -268,6 +268,7 @@ export type RenderOptsPartial = {
...
@@ -268,6 +268,7 @@ export type RenderOptsPartial = {
largePageDataBytes
?:
number
largePageDataBytes
?:
number
isOnDemandRevalidate
?:
boolean
isOnDemandRevalidate
?:
boolean
strictNextHead
:
boolean
strictNextHead
:
boolean
deploymentId
?:
string
}
}
export
type
RenderOpts
=
LoadComponentsReturnType
&
RenderOptsPartial
export
type
RenderOpts
=
LoadComponentsReturnType
&
RenderOptsPartial
...
@@ -411,10 +412,17 @@ export async function renderToHTML(
...
@@ -411,10 +412,17 @@ export async function renderToHTML(
// In dev we invalidate the cache by appending a timestamp to the resource URL.
// In dev we invalidate the cache by appending a timestamp to the resource URL.
// This is a workaround to fix https://github.com/vercel/next.js/issues/5860
// This is a workaround to fix https://github.com/vercel/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
renderResultMeta
.
devOnlyCacheBuster
QueryString
=
renderOpts
.
dev
renderResultMeta
.
asset
QueryString
=
renderOpts
.
dev
?
renderOpts
.
devOnlyCacheBuster
QueryString
||
`?ts=
${
Date
.
now
()}
`
?
renderOpts
.
asset
QueryString
||
`?ts=
${
Date
.
now
()}
`
:
''
:
''
// if deploymentId is provided we append it to all asset requests
if
(
renderOpts
.
deploymentId
)
{
renderResultMeta
.
assetQueryString
+=
`
${
renderResultMeta
.
assetQueryString
?
'&'
:
'?'
}
dpl=
${
renderOpts
.
deploymentId
}
`
}
// don't modify original query object
// don't modify original query object
query
=
Object
.
assign
({},
query
)
query
=
Object
.
assign
({},
query
)
...
@@ -438,8 +446,7 @@ export async function renderToHTML(
...
@@ -438,8 +446,7 @@ export async function renderToHTML(
App
,
App
,
}
=
renderOpts
}
=
renderOpts
const
devOnlyCacheBusterQueryString
=
const
assetQueryString
=
renderResultMeta
.
assetQueryString
renderResultMeta
.
devOnlyCacheBusterQueryString
let
Document
=
renderOpts
.
Document
let
Document
=
renderOpts
.
Document
...
@@ -1457,7 +1464,7 @@ export async function renderToHTML(
...
@@ -1457,7 +1464,7 @@ export async function renderToHTML(
?
pageConfig
.
unstable_runtimeJS
?
pageConfig
.
unstable_runtimeJS
:
undefined
,
:
undefined
,
unstable_JsPreload
:
pageConfig
.
unstable_JsPreload
,
unstable_JsPreload
:
pageConfig
.
unstable_JsPreload
,
devOnlyCacheBuster
QueryString
,
asset
QueryString
,
scriptLoader
,
scriptLoader
,
locale
,
locale
,
disableOptimizedLoading
,
disableOptimizedLoading
,
...
...
packages/next/src/shared/lib/html-context.ts
View file @
8253fa09
...
@@ -27,7 +27,7 @@ export type HtmlProps = {
...
@@ -27,7 +27,7 @@ export type HtmlProps = {
headTags
:
any
[]
headTags
:
any
[]
unstable_runtimeJS
?:
false
unstable_runtimeJS
?:
false
unstable_JsPreload
?:
false
unstable_JsPreload
?:
false
devOnlyCacheBuster
QueryString
:
string
asset
QueryString
:
string
scriptLoader
:
{
scriptLoader
:
{
afterInteractive
?:
string
[]
afterInteractive
?:
string
[]
beforeInteractive
?:
any
[]
beforeInteractive
?:
any
[]
...
...
packages/next/src/shared/lib/image-loader.ts
View file @
8253fa09
...
@@ -59,6 +59,10 @@ function defaultLoader({
...
@@ -59,6 +59,10 @@ function defaultLoader({
return
`
${
config
.
path
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
return
`
${
config
.
path
}
?url=
${
encodeURIComponent
(
src
)}
&w=
${
width
}
&q=
${
quality
||
75
quality
||
75
}${
process
.
env
.
__NEXT_DEPLOYMENT_ID
?
`&dpl=
${
process
.
env
.
__NEXT_DEPLOYMENT_ID
}
`
:
''
}
`
}
`
}
}
...
...
test/production/deployment-id-handling/app/app/from-app/edge/page.tsx
0 → 100644
View file @
8253fa09
import
testImage
from
'../../../public/test.jpg'
import
Image
from
'next/image'
export
default
function
Page
()
{
return
(
<>
<
p
>
hello app edge
</
p
>
<
Image
src=
{
testImage
}
alt=
"test"
/>
</>
)
}
export
const
runtime
=
'edge'
export
const
preferredRegion
=
'iad1'
test/production/deployment-id-handling/app/app/from-app/page.tsx
0 → 100644
View file @
8253fa09
import
testImage
from
'../../public/test.jpg'
import
Image
from
'next/image'
export
default
function
Page
()
{
return
(
<>
<
p
>
hello app
</
p
>
<
Image
src=
{
testImage
}
alt=
"test"
/>
</>
)
}
test/production/deployment-id-handling/app/app/layout.tsx
0 → 100644
View file @
8253fa09
import
{
Inter
}
from
'next/font/google'
import
'../global.css'
const
interFont
=
Inter
({
subsets
:
[
'latin'
],
})
export
default
function
Layout
({
children
})
{
return
(
<
html
>
<
head
/>
<
body
className=
{
interFont
.
className
}
>
{
children
}
</
body
>
</
html
>
)
}
test/production/deployment-id-handling/app/global.css
0 → 100644
View file @
8253fa09
html
{
font-size
:
14rem
;
color
:
white
;
background
:
black
;
}
test/production/deployment-id-handling/app/pages/_app.tsx
0 → 100644
View file @
8253fa09
import
'../global.css'
import
{
Inter
}
from
'next/font/google'
const
interFont
=
Inter
({
subsets
:
[
'latin'
],
})
export
default
function
App
({
Component
,
pageProps
})
{
return
(
<
div
className=
{
interFont
.
className
}
>
<
Component
{
...
pageProps
}
/>
</
div
>
)
}
test/production/deployment-id-handling/app/pages/index.tsx
0 → 100644
View file @
8253fa09
import
testImage
from
'../public/test.jpg'
import
Image
from
'next/image'
export
default
function
Page
()
{
return
(
<>
<
p
>
hello pages
</
p
>
<
Image
src=
{
testImage
}
alt=
"test image"
/>
</>
)
}
test/production/deployment-id-handling/app/pages/pages-edge.tsx
0 → 100644
View file @
8253fa09
import
testImage
from
'../public/test.jpg'
import
Image
from
'next/image'
export
default
function
Page
()
{
return
(
<>
<
p
>
hello pages edge
</
p
>
<
Image
src=
{
testImage
}
alt=
"test image"
/>
</>
)
}
export
const
config
=
{
runtime
:
'experimental-edge'
,
}
test/production/deployment-id-handling/app/public/test.jpg
0 → 100644
View file @
8253fa09
6.61 KB
test/production/deployment-id-handling/deployment-id-handling.test.ts
0 → 100644
View file @
8253fa09
import
{
createNextDescribe
}
from
'e2e-utils'
import
{
join
}
from
'node:path'
const
deploymentId
=
Date
.
now
()
+
''
createNextDescribe
(
'deployment-id-handling'
,
{
files
:
join
(
__dirname
,
'app'
),
env
:
{
NEXT_DEPLOYMENT_ID
:
deploymentId
,
},
},
({
next
})
=>
{
it
.
each
([
{
urlPath
:
'/'
},
{
urlPath
:
'/pages-edge'
},
{
urlPath
:
'/from-app'
},
{
urlPath
:
'/from-app/edge'
},
])(
'should append dpl query to all assets correctly for $urlPath'
,
async
({
urlPath
})
=>
{
const
$
=
await
next
.
render$
(
urlPath
)
const
scripts
=
Array
.
from
(
$
(
'script'
))
expect
(
scripts
.
length
).
toBeGreaterThan
(
0
)
for
(
const
script
of
scripts
)
{
if
(
script
.
attribs
.
src
)
{
expect
(
script
.
attribs
.
src
).
toContain
(
'dpl='
+
deploymentId
)
}
}
const
links
=
Array
.
from
(
$
(
'link'
))
expect
(
links
.
length
).
toBeGreaterThan
(
0
)
for
(
const
link
of
links
)
{
if
(
link
.
attribs
.
href
)
{
expect
(
link
.
attribs
.
href
).
toContain
(
'dpl='
+
deploymentId
)
}
}
}
)
}
)
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