Unverified Commit a95a7d68 authored by Tobias's avatar Tobias Committed by GitHub

docs: Document error cases with head/body-tags (#56412)

Co-authored-by: 's avatarLee Robinson <me@leerob.io>
parent 0ea127c6
...@@ -30,6 +30,8 @@ function IndexPage() { ...@@ -30,6 +30,8 @@ function IndexPage() {
export default IndexPage export default IndexPage
``` ```
## Avoid duplicated tags
To avoid duplicate tags in your `head` you can use the `key` property, which will make sure the tag is only rendered once, as in the following example: To avoid duplicate tags in your `head` you can use the `key` property, which will make sure the tag is only rendered once, as in the following example:
```jsx ```jsx
...@@ -57,7 +59,15 @@ In this case only the second `<meta property="og:title" />` is rendered. `meta` ...@@ -57,7 +59,15 @@ In this case only the second `<meta property="og:title" />` is rendered. `meta`
> The contents of `head` get cleared upon unmounting the component, so make sure each page completely defines what it needs in `head`, without making assumptions about what other pages added. > The contents of `head` get cleared upon unmounting the component, so make sure each page completely defines what it needs in `head`, without making assumptions about what other pages added.
## Use minimal nesting
`title`, `meta` or any other elements (e.g. `script`) need to be contained as **direct** children of the `Head` element, `title`, `meta` or any other elements (e.g. `script`) need to be contained as **direct** children of the `Head` element,
or wrapped into maximum one level of `<React.Fragment>` or arrays—otherwise the tags won't be correctly picked up on client-side navigations. or wrapped into maximum one level of `<React.Fragment>` or arrays—otherwise the tags won't be correctly picked up on client-side navigations.
> We recommend using [next/script](/docs/pages/building-your-application/optimizing/scripts) in your component instead of manually creating a `<script>` in `next/head`. ## Use `next/script` for scripts
We recommend using [`next/script`](/docs/pages/building-your-application/optimizing/scripts) in your component instead of manually creating a `<script>` in `next/head`.
## No `html` or `body` tags
You **cannot** use `<Head>` to set attributes on `<html>` or `<body>` tags. This will result in an `next-head-count is missing` error. `next/head` can only handle tags inside the HTML `<head>` tag.
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