Unverified Commit f0bf674e authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Remove `experimental.strictNextHead` (#81882)

parent 186d169e
...@@ -254,8 +254,6 @@ export function getDefineEnv({ ...@@ -254,8 +254,6 @@ export function getDefineEnv({
config.experimental.scrollRestoration ?? false, config.experimental.scrollRestoration ?? false,
...getImageConfig(config, dev), ...getImageConfig(config, dev),
'process.env.__NEXT_ROUTER_BASEPATH': config.basePath, '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_HAS_REWRITES': hasRewrites,
'process.env.__NEXT_CONFIG_OUTPUT': config.output, 'process.env.__NEXT_CONFIG_OUTPUT': config.output,
'process.env.__NEXT_I18N_SUPPORT': !!config.i18n, 'process.env.__NEXT_I18N_SUPPORT': !!config.i18n,
......
...@@ -144,7 +144,6 @@ async function requestHandler( ...@@ -144,7 +144,6 @@ async function requestHandler(
ComponentMod: pageMod, ComponentMod: pageMod,
pageConfig: pageMod.pageConfig, pageConfig: pageMod.pageConfig,
routeModule: pageMod.routeModule, routeModule: pageMod.routeModule,
strictNextHead: nextConfig.experimental.strictNextHead ?? true,
canonicalBase: nextConfig.amp.canonicalBase || '', canonicalBase: nextConfig.amp.canonicalBase || '',
previewProps: prerenderManifest.preview, previewProps: prerenderManifest.preview,
ampOptimizerConfig: nextConfig.experimental.amp?.optimizer, ampOptimizerConfig: nextConfig.experimental.amp?.optimizer,
......
...@@ -293,8 +293,6 @@ export async function handler( ...@@ -293,8 +293,6 @@ export async function handler(
reactLoadableManifest, reactLoadableManifest,
assetPrefix: nextConfig.assetPrefix, assetPrefix: nextConfig.assetPrefix,
strictNextHead:
nextConfig.experimental.strictNextHead ?? true,
previewProps: prerenderManifest.preview, previewProps: prerenderManifest.preview,
images: nextConfig.images as any, images: nextConfig.images as any,
nextConfigOutput: nextConfig.output, nextConfigOutput: nextConfig.output,
......
...@@ -50,104 +50,52 @@ export function isEqualNode(oldTag: Element, newTag: Element) { ...@@ -50,104 +50,52 @@ export function isEqualNode(oldTag: Element, newTag: Element) {
return oldTag.isEqualNode(newTag) 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) { const oldTags = new Set(headEl.querySelectorAll(`${type}[data-next-head]`))
updateElements = (type, components) => {
const headEl = document.querySelector('head')
if (!headEl) return
const oldTags = new Set(headEl.querySelectorAll(`${type}[data-next-head]`)) if (type === 'meta') {
const metaCharset = headEl.querySelector('meta[charset]')
if (type === 'meta') { if (metaCharset !== null) {
const metaCharset = headEl.querySelector('meta[charset]') oldTags.add(metaCharset)
if (metaCharset !== null) {
oldTags.add(metaCharset)
}
} }
}
const newTags: Element[] = [] const newTags: Element[] = []
for (let i = 0; i < components.length; i++) { for (let i = 0; i < components.length; i++) {
const component = components[i] const component = components[i]
const newTag = reactElementToDOM(component) const newTag = reactElementToDOM(component)
newTag.setAttribute('data-next-head', '') newTag.setAttribute('data-next-head', '')
let isNew = true
for (const oldTag of oldTags) {
if (isEqualNode(oldTag, newTag)) {
oldTags.delete(oldTag)
isNew = false
break
}
}
if (isNew) { let isNew = true
newTags.push(newTag) for (const oldTag of oldTags) {
if (isEqualNode(oldTag, newTag)) {
oldTags.delete(oldTag)
isNew = false
break
} }
} }
for (const oldTag of oldTags) { if (isNew) {
oldTag.parentNode?.removeChild(oldTag) newTags.push(newTag)
}
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)
} }
} }
} 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) for (const oldTag of oldTags) {
const oldTags: Element[] = [] oldTag.parentNode?.removeChild(oldTag)
}
for ( for (const newTag of newTags) {
let i = 0, j = headCountEl.previousElementSibling; // meta[charset] must be first element so special case
i < headCount; if (
i++, j = j?.previousElementSibling || null newTag.tagName.toLowerCase() === 'meta' &&
newTag.getAttribute('charset') !== null
) { ) {
if (j?.tagName?.toLowerCase() === type) { headEl.prepend(newTag)
oldTags.push(j)
}
} }
const newTags = (components.map(reactElementToDOM) as HTMLElement[]).filter( headEl.appendChild(newTag)
(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()
} }
} }
......
...@@ -393,7 +393,6 @@ async function exportAppImpl( ...@@ -393,7 +393,6 @@ async function exportAppImpl(
serverActionsManifest, serverActionsManifest,
} }
: {}), : {}),
strictNextHead: nextConfig.experimental.strictNextHead ?? true,
deploymentId: nextConfig.deploymentId, deploymentId: nextConfig.deploymentId,
htmlLimitedBots: nextConfig.htmlLimitedBots.source, htmlLimitedBots: nextConfig.htmlLimitedBots.source,
experimental: { experimental: {
......
...@@ -657,22 +657,12 @@ export class Head extends React.Component<HeadProps> { ...@@ -657,22 +657,12 @@ export class Head extends React.Component<HeadProps> {
child.props['rel'] === 'preload' && child.props['rel'] === 'preload' &&
child.props['as'] === 'style' child.props['as'] === 'style'
) { ) {
if (this.context.strictNextHead) { cssPreloads.push(child)
cssPreloads.push(
React.cloneElement(child, { 'data-next-head': '' })
)
} else {
cssPreloads.push(child)
}
} else { } else {
if (child) { if (child) {
if (this.context.strictNextHead) { otherHeadElements.push(
otherHeadElements.push( React.cloneElement(child, { 'data-next-head': '' })
React.cloneElement(child, { 'data-next-head': '' }) )
)
} else {
otherHeadElements.push(child)
}
} }
} }
}) })
...@@ -811,12 +801,6 @@ export class Head extends React.Component<HeadProps> { ...@@ -811,12 +801,6 @@ export class Head extends React.Component<HeadProps> {
</> </>
)} )}
{head} {head}
{this.context.strictNextHead ? null : (
<meta
name="next-head-count"
content={React.Children.count(head || []).toString()}
/>
)}
{children} {children}
......
...@@ -565,7 +565,6 @@ export default abstract class Server< ...@@ -565,7 +565,6 @@ export default abstract class Server<
supportsDynamicResponse: true, supportsDynamicResponse: true,
trailingSlash: this.nextConfig.trailingSlash, trailingSlash: this.nextConfig.trailingSlash,
deploymentId: this.nextConfig.deploymentId, deploymentId: this.nextConfig.deploymentId,
strictNextHead: this.nextConfig.experimental.strictNextHead ?? true,
poweredByHeader: this.nextConfig.poweredByHeader, poweredByHeader: this.nextConfig.poweredByHeader,
canonicalBase: this.nextConfig.amp.canonicalBase || '', canonicalBase: this.nextConfig.amp.canonicalBase || '',
generateEtags, generateEtags,
......
...@@ -414,7 +414,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -414,7 +414,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
algorithm: z.enum(['sha256', 'sha384', 'sha512']).optional(), algorithm: z.enum(['sha256', 'sha384', 'sha512']).optional(),
}) })
.optional(), .optional(),
strictNextHead: z.boolean().optional(),
swcPlugins: z swcPlugins: z
// The specific swc plugin's option is unknown, use z.any() here // The specific swc plugin's option is unknown, use z.any() here
.array(z.tuple([z.string(), z.record(z.string(), z.any())])) .array(z.tuple([z.string(), z.record(z.string(), z.any())]))
......
...@@ -335,8 +335,6 @@ export interface ExperimentalConfig { ...@@ -335,8 +335,6 @@ export interface ExperimentalConfig {
dynamicOnHover?: boolean dynamicOnHover?: boolean
appDocumentPreloading?: boolean appDocumentPreloading?: boolean
preloadEntriesOnStart?: boolean preloadEntriesOnStart?: boolean
/** @default true */
strictNextHead?: boolean
clientRouterFilter?: boolean clientRouterFilter?: boolean
clientRouterFilterRedirects?: boolean clientRouterFilterRedirects?: boolean
/** /**
...@@ -1472,7 +1470,6 @@ export const defaultConfig = Object.freeze({ ...@@ -1472,7 +1470,6 @@ export const defaultConfig = Object.freeze({
devtoolSegmentExplorer: true, devtoolSegmentExplorer: true,
browserDebugInfoInTerminal: false, browserDebugInfoInTerminal: false,
optimizeRouterScrolling: false, optimizeRouterScrolling: false,
strictNextHead: true,
}, },
htmlLimitedBots: undefined, htmlLimitedBots: undefined,
bundlePagesRouterDependencies: false, bundlePagesRouterDependencies: false,
......
...@@ -287,7 +287,6 @@ export type RenderOptsPartial = { ...@@ -287,7 +287,6 @@ export type RenderOptsPartial = {
images: ImageConfigComplete images: ImageConfigComplete
largePageDataBytes?: number largePageDataBytes?: number
isOnDemandRevalidate?: boolean isOnDemandRevalidate?: boolean
strictNextHead: boolean
isPossibleServerAction?: boolean isPossibleServerAction?: boolean
isExperimentalCompile?: boolean isExperimentalCompile?: boolean
isPrefetch?: boolean isPrefetch?: boolean
...@@ -1524,7 +1523,6 @@ export async function renderToHTMLImpl( ...@@ -1524,7 +1523,6 @@ export async function renderToHTMLImpl(
notFoundSrcPage: notFoundSrcPage && dev ? notFoundSrcPage : undefined, notFoundSrcPage: notFoundSrcPage && dev ? notFoundSrcPage : undefined,
}, },
nonce, nonce,
strictNextHead: renderOpts.strictNextHead,
buildManifest: filteredBuildManifest, buildManifest: filteredBuildManifest,
docComponentsRendered, docComponentsRendered,
dangerousAsPath: router.asPath, dangerousAsPath: router.asPath,
......
...@@ -9,7 +9,6 @@ import { createContext, useContext, type JSX } from 'react' ...@@ -9,7 +9,6 @@ import { createContext, useContext, type JSX } from 'react'
export type HtmlProps = { export type HtmlProps = {
__NEXT_DATA__: NEXT_DATA __NEXT_DATA__: NEXT_DATA
nonce?: string nonce?: string
strictNextHead: boolean
dangerousAsPath: string dangerousAsPath: string
docComponentsRendered: { docComponentsRendered: {
Html?: boolean Html?: boolean
......
...@@ -4,12 +4,6 @@ module.exports = { ...@@ -4,12 +4,6 @@ module.exports = {
// Make sure entries are not getting disposed. // Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60, 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 // scroll position can be finicky with the
// indicators showing so hide by default // indicators showing so hide by default
devIndicators: false, devIndicators: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment