-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Component styles are overridden when rendered inside Next.js layout #199
Comments
This appears to only be an issue when building for development. If I build for production, the style sheets are generated as expected and don't cause the precedence issue that I'm seeing in development. For example, in dev, the |
I am using AppBar is an example here. The AppBar is a component that wraps Paper and override the background. In Next.js app router, AppBar is used in The root cause comes from the styles of the Paper being generated to both Because the produced HTML of AppBar includes classes of the Paper like this: <div class="appbar paper">
// layout.css
.paper { background: white };
.appbar { background: blue };
// page.css
.paper { background: white }; This causes In production, the CSS files are built with a different process, so there are no duplicate CSS however, there is a possibility that the order of the might be different. Update This issue involves Next.js because |
Just bumped into this bug as well with my project. Would love to see it resolved. |
Hey folks. I am looking into this. |
Steps to reproduce
Review the styles being applied to the nav links in the mobile appbar of both Next.js and Vite versions of the example app. Observe how the styles are incorrect when on the home page of the Next app but are correct on the about page.
Current behavior
I've run into an issue that appears when using the Next.js plugin but doesn't exist when using the Vite plugin. As you'll see in the example app, the nav links in the appbar drawer on mobile don't have the correct alignment or padding specified by the
ListItemButton
styles. However, if you flip to the About page and inspect the links in the drawer, you'll see theListItemButton
styles are being applied as expected.From what I can tell, it looks like the Next.js plugin is generating styles at a route file level (e.g.
page.tsx
,layout.tsx
) instead of at a component/module level like the Vite plugin appears to do. In the Next app,(public)/page.tsx
has anotherButton
on the page so the base button styles frompage.tsx
take precedence over the styles being generated forlayout.tsx
that renders theSiteAppBar
component containing the links. In the Vite example app, though, the styles are being generated separately for thesite-app-bar.tsx
module and take precedence so theListItemButton
alignment and padding are applied as expected.Expected behavior
Styles for components rendered within Next.js layout components should not be overridden by those in page components.
Context
No response
Your environment
npx @mui/envinfo
Search keywords: nextjs vite plugin layout components override
The text was updated successfully, but these errors were encountered: