Skip to content

Commit 314a02d

Browse files
authored
[material-nextjs] Support Next.js 16 (#47134)
1 parent 6c9e82f commit 314a02d

File tree

5 files changed

+69
-44
lines changed

5 files changed

+69
-44
lines changed

docs/data/material/integrations/nextjs/nextjs.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ This option ensures that the styles generated by Material UI will be wrapped in
143143

144144
To learn more about it, see [the MDN CSS layer documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer).
145145

146+
### Next.js v16 Client Component restriction
147+
148+
If you encounter `Functions cannot be passed directly to Client Components` error from passing Next.js Link to Material UI `component` prop, you need to create a wrapper component with `use client` directive like the following:
149+
150+
```tsx title="src/components/Link.tsx"
151+
'use client';
152+
import Link, { LinkProps } from 'next/link';
153+
154+
export default Link;
155+
```
156+
157+
Then, replace the Next.js Link with the wrapper component:
158+
159+
```diff title="src/app/page.tsx"
160+
- import Link from 'next/link';
161+
+ import Link from '../components/Link';
162+
...
163+
<Button component={Link} href="/about" variant="contained">
164+
Go to About Page
165+
</Button>
166+
```
167+
146168
## Pages Router
147169

148170
This section walks through the Material UI integration with the Next.js [Pages Router](https://nextjs.org/docs/pages/building-your-application), for both [Server-side Rendering](https://nextjs.org/docs/pages/building-your-application/rendering/server-side-rendering) (SSR) and [Static Site Generation](https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation) (SSG).

packages/mui-material-nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@emotion/react": "^11.11.4",
4646
"@emotion/server": "^11.11.0",
4747
"@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
48-
"next": "^13.0.0 || ^14.0.0 || ^15.0.0",
48+
"next": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
4949
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
5050
},
5151
"peerDependenciesMeta": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../v13-appRouter';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../v13-pagesRouter';

pnpm-lock.yaml

Lines changed: 44 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)