Skip to content

Commit

Permalink
[system] Explain why AppRouterCacheProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 3, 2024
1 parent bc21246 commit d2f7072
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/data/material/guides/nextjs/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Inside `app/layout.tsx`, import the `AppRouterCacheProvider` and wrap all elemen
}
```

:::info
The `AppRouterCacheProvider` component is responsible for collecting the CSS generated by MUI System on the server, as Next.js is streaming chunks of the .html page to the client.

While it's not required to use the `AppRouterCacheProvider` component, it's recommended to use it to ensure that the styles are appended to the `<head>` and not rendering in the `<body>`.
See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 for why it's better.
:::

#### Custom cache (optional)

Use the `options` prop to override the default [cache options](https://emotion.sh/docs/@emotion/cache#options)—for example, the code snippet below shows how to change the CSS key to `css` (the default is `mui`):
Expand Down Expand Up @@ -219,6 +226,13 @@ Then, inside `pages/_app.tsx`, import the `AppCacheProvider` component and rende
}
```

:::info
The `AppCacheProvider` component is responsible for collecting the CSS generated by MUI System on the server, as Next.js is rendering the .html page to the client.

While it's not required to use the `AppCacheProvider` component, it's recommended to use it to ensure that the styles are appended to the `<head>` and not rendering in the `<body>`.
See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 for why it's better.
:::

#### Custom cache (optional)

To use a custom [Emotion cache](https://emotion.sh/docs/@emotion/cache), pass it to the `emotionCache` property in `_document.tsx`:
Expand Down

0 comments on commit d2f7072

Please sign in to comment.