-
-
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
Next.js 13 app directory support #34896
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
All styled components would need to be marked, as they all depend on Emtion's context. |
Any take on this so far? So for now I would say wrapping our components that include mui components with |
Can someone share an example code please where Material UI is being used in the /app directory? I am not able to figure out how to do that since there is no documentation for that. |
Strictly speaking, there is no issue with using MUI components in the app directory, as long as they are used in client components. |
So there is no way to use Material UI in a server side rendered Next component? |
But I was confused about certain things like how in previous nextjs versions, we added _app.tsx and _document.tsx in the page directory. I wanted to know how to do it know in app directory as most of the syntax has changed and including these files in app directory gives error. Can someone help me by providing code or some link for help. Thanks in advance. |
Not the right thread to discuss this issue. This is a Next js specific concern and not a MUI one. Would be better if discussed on a Next js forum |
@alaindeurveilher The issue with running this on the client is that the styles wont be calculated and appended to the page before render, where the app will flicker initially without styles until mui loads it's components. I hope we get a response on that, if mui is considering this issue for and is planned or has an official workaround to compile the styles on the server. @ahmedjaved753 this is not a Next.js concern to integrate other libraries into their framework. |
With NextJS, there isn't any flicker because of SSR for the client components. |
@alikleit client component doesn't mean that everything is done on the client side. It just means that the component is interactive and should send JS to the client. The rendering of the component is always done on the server, the only difference is that server components don't send JS to the client themselves. Though, using client components within a server component will still send the JS used in the client component. Read the next docs for a better explanation: https://nextjs.org/docs/getting-started/react-essentials#client-components |
I believe that we used to add custom code to extract MUI stylesheets from I do know client component are as well SSR, but that does not mean these will also compile the things mentioned above 😃 so as the pages from Plus when my
While my inspector looks like this:
which I ran with a minimalistic layout (will not show you the flicker / but with a complex one - it will) . Then that tell you something? Unless, there's a proper official way to compose that 😃 |
AFAIK, you would need to do something similar for app directory. See here (and the rest of the thread) for an example: #34898 (comment). By following the steps described in the thread, you'll get the styles injected inside |
when using @urql/exchange-graphcache it throw hydrationError |
Ok, trying to understand a lot today (brain won't let me sleep until I am satisfied with my understanding... or asking question to understand!). I may use less technical words are vaguely/broadly definition, in a way to create a better mental picture for myself. If you feel that those vague/broad terms are too off the track, don't hesitate to correct me. With the release of v5.14.0, the MUI ecosystem now works inside Next.js But, as I understand the RSC2 system, this fix does not allow to benefit of the server-side rendering feature3 of the RSC since the As such, component that should be static in nature in the current MUI/Emotion ecosystem (such as So far so good? I think I am not too far off in my understanding 🤔? I read many of the issues raised regarding this So does that leave us with either having one or the other; or a painfully enormous hybrid version where each component has both static for RSC and dynamics for clients components? Footnotes
|
@sharky98 I think the most important thing that you seem to misunderstand, is that adding |
@gijsbotje Thank you for the feedback. This helped me update my mental image of the RSC feature.
If Client Component are also server-rendered, how they manage the "no-hooks", "no-browser-specific-variables", etc. that are in place for RSC? Unless they render only a skeleton-like HTML and CSS without any pre-run of the dynamic stuff (which seems to be what Next.js is doing: In that case, updating my mental image, I would summarize it as RSC are server-rendered with full HTML and CSS and served as static component to the client to be inserted somewhere in the DOM. For the Client Component, they are server-rendered with the bare skeleton HTML and CSS and served to the client alongside some JavaScript for it to do its magic. If I'm not mistaken, in React world, most extra work that JavaScript would do is change the state, which triggers what they call a render.
So, even though I misunderstood the rendering aspect, with this part of your comment, I think my conclusion is pretty much the same? As long as a library such as MUI is based on CSS-in-JS framework using a dynamic styling philosophy, RSC are impossible; only the benefit of whatever the server is able to do during the first rendering is added (or kept, since it was already like that before the |
But you need to enable JS to |
Closing this as MUI libraries are compatible as of You can follow #34905 to see what's coming next to improve Next.js integration.
We have started to explore a zero-runtime CSS solution, you can check out the very beginning of this effort here, and keep an eye out for a proper RFC next week! |
Duplicates
Latest version
Summary 💡
Material UI v5 doesn't support Next.js app directory. Even though the error comes from
@emotion\react
and not Material UI itself, I think this should be tracked here as well.The "primary" error (there might be other problems once the Emotion issue is fixed) is:
Related Emotion issue: emotion-js/emotion#2928
Examples 🌈
I've created a minimal (failing) example using
create-next-app
: https://github.com/MidnightDesign/nextjs13-material-uiMotivation 🔦
No response
The text was updated successfully, but these errors were encountered: