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
f0bf674e
Unverified
Commit
f0bf674e
authored
Jul 21, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Jul 21, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `experimental.strictNextHead` (#81882)
parent
186d169e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
409 additions
and
636 deletions
+409
-636
define-env.ts
packages/next/src/build/define-env.ts
+0
-2
edge-ssr.ts
packages/next/src/build/templates/edge-ssr.ts
+0
-1
pages.ts
packages/next/src/build/templates/pages.ts
+0
-2
head-manager.ts
packages/next/src/client/head-manager.ts
+32
-84
index.ts
packages/next/src/export/index.ts
+0
-1
_document.tsx
packages/next/src/pages/_document.tsx
+4
-20
base-server.ts
packages/next/src/server/base-server.ts
+0
-1
config-schema.ts
packages/next/src/server/config-schema.ts
+0
-1
config-shared.ts
packages/next/src/server/config-shared.ts
+0
-3
render.tsx
packages/next/src/server/render.tsx
+0
-2
html-context.shared-runtime.ts
packages/next/src/shared/lib/html-context.shared-runtime.ts
+0
-1
next.config.js
...opment/pages-dir/client-navigation/fixture/next.config.js
+0
-6
head.test.ts
test/development/pages-dir/client-navigation/head.test.ts
+152
-180
rendering-head.test.ts
...opment/pages-dir/client-navigation/rendering-head.test.ts
+221
-332
No files found.
packages/next/src/build/define-env.ts
View file @
f0bf674e
...
...
@@ -254,8 +254,6 @@ export function getDefineEnv({
config
.
experimental
.
scrollRestoration
??
false
,
...
getImageConfig
(
config
,
dev
),
'process.env.__NEXT_ROUTER_BASEPATH'
:
config
.
basePath
,
'process.env.__NEXT_STRICT_NEXT_HEAD'
:
config
.
experimental
.
strictNextHead
??
true
,
'process.env.__NEXT_HAS_REWRITES'
:
hasRewrites
,
'process.env.__NEXT_CONFIG_OUTPUT'
:
config
.
output
,
'process.env.__NEXT_I18N_SUPPORT'
:
!!
config
.
i18n
,
...
...
packages/next/src/build/templates/edge-ssr.ts
View file @
f0bf674e
...
...
@@ -144,7 +144,6 @@ async function requestHandler(
ComponentMod
:
pageMod
,
pageConfig
:
pageMod
.
pageConfig
,
routeModule
:
pageMod
.
routeModule
,
strictNextHead
:
nextConfig
.
experimental
.
strictNextHead
??
true
,
canonicalBase
:
nextConfig
.
amp
.
canonicalBase
||
''
,
previewProps
:
prerenderManifest
.
preview
,
ampOptimizerConfig
:
nextConfig
.
experimental
.
amp
?.
optimizer
,
...
...
packages/next/src/build/templates/pages.ts
View file @
f0bf674e
...
...
@@ -293,8 +293,6 @@ export async function handler(
reactLoadableManifest
,
assetPrefix
:
nextConfig
.
assetPrefix
,
strictNextHead
:
nextConfig
.
experimental
.
strictNextHead
??
true
,
previewProps
:
prerenderManifest
.
preview
,
images
:
nextConfig
.
images
as
any
,
nextConfigOutput
:
nextConfig
.
output
,
...
...
packages/next/src/client/head-manager.ts
View file @
f0bf674e
...
...
@@ -50,104 +50,52 @@ export function isEqualNode(oldTag: Element, newTag: Element) {
return
oldTag
.
isEqualNode
(
newTag
)
}
let
updateElements
:
(
type
:
string
,
components
:
JSX
.
Element
[])
=>
void
function
updateElements
(
type
:
string
,
components
:
JSX
.
Element
[])
{
const
headEl
=
document
.
querySelector
(
'head'
)
if
(
!
headEl
)
return
if
(
process
.
env
.
__NEXT_STRICT_NEXT_HEAD
)
{
updateElements
=
(
type
,
components
)
=>
{
const
headEl
=
document
.
querySelector
(
'head'
)
if
(
!
headEl
)
return
const
oldTags
=
new
Set
(
headEl
.
querySelectorAll
(
`
${
type
}
[data-next-head]`
))
const
oldTags
=
new
Set
(
headEl
.
querySelectorAll
(
`
${
type
}
[data-next-head]`
))
if
(
type
===
'meta'
)
{
const
metaCharset
=
headEl
.
querySelector
(
'meta[charset]'
)
if
(
metaCharset
!==
null
)
{
oldTags
.
add
(
metaCharset
)
}
if
(
type
===
'meta'
)
{
const
metaCharset
=
headEl
.
querySelector
(
'meta[charset]'
)
if
(
metaCharset
!==
null
)
{
oldTags
.
add
(
metaCharset
)
}
}
const
newTags
:
Element
[]
=
[]
for
(
let
i
=
0
;
i
<
components
.
length
;
i
++
)
{
const
component
=
components
[
i
]
const
newTag
=
reactElementToDOM
(
component
)
newTag
.
setAttribute
(
'data-next-head'
,
''
)
let
isNew
=
true
for
(
const
oldTag
of
oldTags
)
{
if
(
isEqualNode
(
oldTag
,
newTag
))
{
oldTags
.
delete
(
oldTag
)
isNew
=
false
break
}
}
const
newTags
:
Element
[]
=
[]
for
(
let
i
=
0
;
i
<
components
.
length
;
i
++
)
{
const
component
=
components
[
i
]
const
newTag
=
reactElementToDOM
(
component
)
newTag
.
setAttribute
(
'data-next-head'
,
''
)
if
(
isNew
)
{
newTags
.
push
(
newTag
)
let
isNew
=
true
for
(
const
oldTag
of
oldTags
)
{
if
(
isEqualNode
(
oldTag
,
newTag
))
{
oldTags
.
delete
(
oldTag
)
isNew
=
false
break
}
}
for
(
const
oldTag
of
oldTags
)
{
oldTag
.
parentNode
?.
removeChild
(
oldTag
)
}
for
(
const
newTag
of
newTags
)
{
// meta[charset] must be first element so special case
if
(
newTag
.
tagName
.
toLowerCase
()
===
'meta'
&&
newTag
.
getAttribute
(
'charset'
)
!==
null
)
{
headEl
.
prepend
(
newTag
)
}
headEl
.
appendChild
(
newTag
)
if
(
isNew
)
{
newTags
.
push
(
newTag
)
}
}
}
else
{
updateElements
=
(
type
,
components
)
=>
{
const
headEl
=
document
.
getElementsByTagName
(
'head'
)[
0
]
const
headCountEl
:
HTMLMetaElement
=
headEl
.
querySelector
(
'meta[name=next-head-count]'
)
as
HTMLMetaElement
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
if
(
!
headCountEl
)
{
console
.
error
(
'Warning: next-head-count is missing. https://nextjs.org/docs/messages/next-head-count-missing'
)
return
}
}
const
headCount
=
Number
(
headCountEl
.
content
)
const
oldTags
:
Element
[]
=
[]
for
(
const
oldTag
of
oldTags
)
{
oldTag
.
parentNode
?.
removeChild
(
oldTag
)
}
for
(
let
i
=
0
,
j
=
headCountEl
.
previousElementSibling
;
i
<
headCount
;
i
++
,
j
=
j
?.
previousElementSibling
||
null
for
(
const
newTag
of
newTags
)
{
// meta[charset] must be first element so special case
if
(
newTag
.
tagName
.
toLowerCase
()
===
'meta'
&&
newTag
.
getAttribute
(
'charset'
)
!==
null
)
{
if
(
j
?.
tagName
?.
toLowerCase
()
===
type
)
{
oldTags
.
push
(
j
)
}
headEl
.
prepend
(
newTag
)
}
const
newTags
=
(
components
.
map
(
reactElementToDOM
)
as
HTMLElement
[]).
filter
(
(
newTag
)
=>
{
for
(
let
k
=
0
,
len
=
oldTags
.
length
;
k
<
len
;
k
++
)
{
const
oldTag
=
oldTags
[
k
]
if
(
isEqualNode
(
oldTag
,
newTag
))
{
oldTags
.
splice
(
k
,
1
)
return
false
}
}
return
true
}
)
oldTags
.
forEach
((
t
)
=>
t
.
parentNode
?.
removeChild
(
t
))
newTags
.
forEach
((
t
)
=>
headEl
.
insertBefore
(
t
,
headCountEl
))
headCountEl
.
content
=
(
headCount
-
oldTags
.
length
+
newTags
.
length
).
toString
()
headEl
.
appendChild
(
newTag
)
}
}
...
...
packages/next/src/export/index.ts
View file @
f0bf674e
...
...
@@ -393,7 +393,6 @@ async function exportAppImpl(
serverActionsManifest
,
}
:
{}),
strictNextHead
:
nextConfig
.
experimental
.
strictNextHead
??
true
,
deploymentId
:
nextConfig
.
deploymentId
,
htmlLimitedBots
:
nextConfig
.
htmlLimitedBots
.
source
,
experimental
:
{
...
...
packages/next/src/pages/_document.tsx
View file @
f0bf674e
...
...
@@ -657,22 +657,12 @@ export class Head extends React.Component<HeadProps> {
child
.
props
[
'rel'
]
===
'preload'
&&
child
.
props
[
'as'
]
===
'style'
)
{
if
(
this
.
context
.
strictNextHead
)
{
cssPreloads
.
push
(
React
.
cloneElement
(
child
,
{
'data-next-head'
:
''
})
)
}
else
{
cssPreloads
.
push
(
child
)
}
cssPreloads
.
push
(
child
)
}
else
{
if
(
child
)
{
if
(
this
.
context
.
strictNextHead
)
{
otherHeadElements
.
push
(
React
.
cloneElement
(
child
,
{
'data-next-head'
:
''
})
)
}
else
{
otherHeadElements
.
push
(
child
)
}
otherHeadElements
.
push
(
React
.
cloneElement
(
child
,
{
'data-next-head'
:
''
})
)
}
}
})
...
...
@@ -811,12 +801,6 @@ export class Head extends React.Component<HeadProps> {
</>
)
}
{
head
}
{
this
.
context
.
strictNextHead
?
null
:
(
<
meta
name=
"next-head-count"
content=
{
React
.
Children
.
count
(
head
||
[]).
toString
()
}
/>
)
}
{
children
}
...
...
packages/next/src/server/base-server.ts
View file @
f0bf674e
...
...
@@ -565,7 +565,6 @@ export default abstract class Server<
supportsDynamicResponse
:
true
,
trailingSlash
:
this
.
nextConfig
.
trailingSlash
,
deploymentId
:
this
.
nextConfig
.
deploymentId
,
strictNextHead
:
this
.
nextConfig
.
experimental
.
strictNextHead
??
true
,
poweredByHeader
:
this
.
nextConfig
.
poweredByHeader
,
canonicalBase
:
this
.
nextConfig
.
amp
.
canonicalBase
||
''
,
generateEtags
,
...
...
packages/next/src/server/config-schema.ts
View file @
f0bf674e
...
...
@@ -414,7 +414,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
algorithm
:
z
.
enum
([
'sha256'
,
'sha384'
,
'sha512'
]).
optional
(),
})
.
optional
(),
strictNextHead
:
z
.
boolean
().
optional
(),
swcPlugins
:
z
// The specific swc plugin's option is unknown, use z.any() here
.
array
(
z
.
tuple
([
z
.
string
(),
z
.
record
(
z
.
string
(),
z
.
any
())]))
...
...
packages/next/src/server/config-shared.ts
View file @
f0bf674e
...
...
@@ -335,8 +335,6 @@ export interface ExperimentalConfig {
dynamicOnHover
?:
boolean
appDocumentPreloading
?:
boolean
preloadEntriesOnStart
?:
boolean
/** @default true */
strictNextHead
?:
boolean
clientRouterFilter
?:
boolean
clientRouterFilterRedirects
?:
boolean
/**
...
...
@@ -1472,7 +1470,6 @@ export const defaultConfig = Object.freeze({
devtoolSegmentExplorer
:
true
,
browserDebugInfoInTerminal
:
false
,
optimizeRouterScrolling
:
false
,
strictNextHead
:
true
,
},
htmlLimitedBots
:
undefined
,
bundlePagesRouterDependencies
:
false
,
...
...
packages/next/src/server/render.tsx
View file @
f0bf674e
...
...
@@ -287,7 +287,6 @@ export type RenderOptsPartial = {
images
:
ImageConfigComplete
largePageDataBytes
?:
number
isOnDemandRevalidate
?:
boolean
strictNextHead
:
boolean
isPossibleServerAction
?:
boolean
isExperimentalCompile
?:
boolean
isPrefetch
?:
boolean
...
...
@@ -1524,7 +1523,6 @@ export async function renderToHTMLImpl(
notFoundSrcPage
:
notFoundSrcPage
&&
dev
?
notFoundSrcPage
:
undefined
,
},
nonce
,
strictNextHead
:
renderOpts
.
strictNextHead
,
buildManifest
:
filteredBuildManifest
,
docComponentsRendered
,
dangerousAsPath
:
router
.
asPath
,
...
...
packages/next/src/shared/lib/html-context.shared-runtime.ts
View file @
f0bf674e
...
...
@@ -9,7 +9,6 @@ import { createContext, useContext, type JSX } from 'react'
export
type
HtmlProps
=
{
__NEXT_DATA__
:
NEXT_DATA
nonce
?:
string
strictNextHead
:
boolean
dangerousAsPath
:
string
docComponentsRendered
:
{
Html
?:
boolean
...
...
test/development/pages-dir/client-navigation/fixture/next.config.js
View file @
f0bf674e
...
...
@@ -4,12 +4,6 @@ module.exports = {
// Make sure entries are not getting disposed.
maxInactiveAge
:
1000
*
60
*
60
,
},
experimental
:
process
.
env
.
TEST_STRICT_NEXT_HEAD
!==
undefined
?
{
strictNextHead
:
process
.
env
.
TEST_STRICT_NEXT_HEAD
===
'true'
,
}
:
{},
// scroll position can be finicky with the
// indicators showing so hide by default
devIndicators
:
false
,
...
...
test/development/pages-dir/client-navigation/head.test.ts
View file @
f0bf674e
This diff is collapsed.
Click to expand it.
test/development/pages-dir/client-navigation/rendering-head.test.ts
View file @
f0bf674e
This diff is collapsed.
Click to expand it.
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