Back to Next Js

Viewport `meta` tags should not be used in `_document.js` ``

errors/no-document-viewport-meta.mdx

16.2.5718 B
Original Source

Why This Error Occurred

Adding <meta name="viewport" ...> in pages/_document.js will lead to unexpected results since it cannot be deduped. The viewport tag should be handled by next/head in pages/_app.js.

Possible Ways to Fix It

Set your viewport meta tag in pages/_app.js instead:

jsx
import Head from 'next/head'

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Head>
        <meta name="viewport" content="viewport-fit=cover" />
      </Head>
      <Component {...pageProps} />
    </>
  )
}

export default MyApp