-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Add use client
directive to all components in a new build step
#37503
Comments
I looked into this for one of my packages, and decided to NOT do it as part of the core module because it's too platform specific. The I do, however, wish that MUI implemented a more SSR-friendly approach for components. Especially for super common ones like Your best bet would be to just |
Any updates ? |
I think MUI can instead publish a script to handle this as a separate package instead. Taking reference from similar offerings, e.g. Chakra UI has a dedicated package |
@altechzilla Thanks for sharing ~
You are right that it is not part of normal JS, but to my understanding it is specific to React Server Components (per the related RFC) and not Next.js, it's just that this issue is highly visible in Next 13 apps because the new app directory makes full use of RSC!
Making these common components (layout components in particular) work as React Server components is definitely on the agenda! |
@mwskwong Thanks for sharing this, I'll try it out ~
At this point, we're just trying to get the MUI libraries working out of the box in a Next 13 app directory without requiring any extra installation steps or config changes! |
Which is the best DX IMO. I think there are other projects already start doing it. If I have to say, I will properly think MUI Joy is the best place to start. I would imagine it is more approachable than doing it in MUI Material v6. |
As a temporary workaround, I have setup something that utilizes TypeScript path aliases to provide the behaviour we want. First, create a file (I've called it "use client";
// "node_modules" is required here to make sure we don't go into a recursive loop with the path alias.
export * from "node_modules/@mui/material"; Second, in the {
"compilerOptions": {
"paths": {
"@mui/material": [
"./src/material"
]
}
}
} With this, when |
That's a good idea, and it does work. Unfortunately, the tradeoff is it breaks tree shaking, so the entire |
This SWC plugin can match which components to insert the 'use client' directive based on the incoming path. |
I think we could do the same in MUI X, issue created mui/mui-x#9833. |
Another thought, it feels that it would be great to move our Next.js documentation from Pages Router to App Router, so that we are forced to add |
Part of #34905
Next.js 13 considers all components in the
app
directory server components by default, requiring client components to be identified with a'use client'
directive.A new build step similar to
yarn docs:api:build
will be added to add'use client'
to all Material UI, Base UI and Joy UI componentsThe text was updated successfully, but these errors were encountered: