Skip to content

Commit

Permalink
Only once for the next/head usage in app dir (#44233)
Browse files Browse the repository at this point in the history
Follow up for #43885

* only warn once for `next/head` usage in the loader
* add `Warning:` prefix
  • Loading branch information
huozhi committed Dec 21, 2022
1 parent e27c7fa commit c24643e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
@@ -1,7 +1,10 @@
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 { getModuleBuildInfo } from '../get-module-build-info'

const noopHeadPath = require.resolve('next/dist/client/components/noop-head')

export default async function transformSource(
this: any,
source: string,
Expand All @@ -24,5 +27,10 @@ export default async function transformSource(
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)
}
8 changes: 0 additions & 8 deletions packages/next/client/components/noop-head.tsx
@@ -1,11 +1,3 @@
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() {
return null
}
8 changes: 4 additions & 4 deletions test/e2e/app-dir/head/head.test.ts
Expand Up @@ -102,12 +102,12 @@ createNextDescribe(

if (globalThis.isNextDev) {
expect(
errors.some(
errors.filter(
(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`
)
).toBe(true)
`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(1)

const dynamicChunkPath = path.join(
next.testDir,
Expand Down

0 comments on commit c24643e

Please sign in to comment.