Unverified Commit c24643ec authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Only once for the next/head usage in app dir (#44233)

Follow up for #43885

* only warn once for `next/head` usage in the loader
* add `Warning:` prefix
parent e27c7fa6
import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants' import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants'
import { warnOnce } from '../../../../shared/lib/utils/warn-once'
import { getRSCModuleType } from '../../../analysis/get-page-static-info' import { getRSCModuleType } from '../../../analysis/get-page-static-info'
import { getModuleBuildInfo } from '../get-module-build-info' import { getModuleBuildInfo } from '../get-module-build-info'
const noopHeadPath = require.resolve('next/dist/client/components/noop-head')
export default async function transformSource( export default async function transformSource(
this: any, this: any,
source: string, source: string,
...@@ -24,5 +27,10 @@ export default async function transformSource( ...@@ -24,5 +27,10 @@ export default async function transformSource(
return callback(null, source, sourceMap) return callback(null, source, sourceMap)
} }
if (noopHeadPath === this.resourcePath) {
warnOnce(
`Warning: You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.`
)
}
return callback(null, source, sourceMap) return callback(null, source, sourceMap)
} }
import { warnOnce } from '../../shared/lib/utils/warn-once'
if (process.env.NODE_ENV !== 'production') {
warnOnce(
`You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.`
)
}
export default function NoopHead() { export default function NoopHead() {
return null return null
} }
...@@ -102,12 +102,12 @@ createNextDescribe( ...@@ -102,12 +102,12 @@ createNextDescribe(
if (globalThis.isNextDev) { if (globalThis.isNextDev) {
expect( expect(
errors.some( errors.filter(
(output) => (output) =>
output === output ===
`You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.\n` `Warning: You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.\n`
) ).length
).toBe(true) ).toBe(1)
const dynamicChunkPath = path.join( const dynamicChunkPath = path.join(
next.testDir, next.testDir,
......
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