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
[material-ui][next] AppCacheProvider with Next v13 and v14 Pages Router causes flickering #41630
Comments
I have the same behaviour, I have no idea what we are missing but clearly the css injection is not working on the server side. You can clearly observe it by simply disabling javascript (client side), with the following code replacing <ThemeProvider theme={theme}>
<Button variant="contained">Test button</Button>
</ThemeProvider> This buttons outputs: <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary mui-d00fc6-MuiButtonBase-root-MuiButton-root" tabindex="0" type="button">Test button</button> But if you look for any of these class names in the head of your page (while JS is disabled) you'll notice that none is present. On the other hand, if we enable JS, we will have the CSS injected, something like this: <head>
<style data-emotion="mui" data-s="">.mui-f16x46-MuiButton-root{font-family:Nunito,sans-serif;}</style>
</head> That means CSS is injected on the client side, which is why the SSR rendered page is not correct (which causes the flickering). I haven't found the solution to this yet. It's strange because the install steps are pretty simple so I'm not sure what I'm missing. Maybe that's a version issue. My environmentnpx @mui/envinfo System:
OS: macOS 13.6.1
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
pnpm: 8.6.6 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 124.0.6367.78
Edge: Not Found
Safari: 17.1
npmPackages:
@emotion/react: ^11.9.3 => 11.9.3
@emotion/styled: ^11.9.3 => 11.9.3
@mui/base: 5.0.0-beta.40
@mui/core-downloads-tracker: 5.15.15
@mui/icons-material: ^5.8.4 => 5.8.4
@mui/material: ^5.15.15 => 5.15.15
@mui/material-nextjs: ^5.15.11 => 5.15.11
@mui/private-theming: 5.15.14
@mui/styled-engine: 5.15.14
@mui/system: 5.15.15
@mui/types: 7.2.14
@mui/utils: 5.15.14
@types/react: ^18.0.9 => 18.0.15
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: ^4.6.4 => 4.7.4 |
@fbozhkov You miss this line: - export default function App({ Component, pageProps }: AppProps) {
+ export default function App({ Component, pageProps, …props }: AppProps) {
return (
- <AppCacheProvider>
+ <AppCacheProvider {…props}>
<Head>
<link rel="icon" href="/tcfavicon.ico" />
</Head>
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
</AppCacheProvider>
)
}; I think we could improve the docs by: - Then, inside pages/_app.tsx, import the AppCacheProvider component and render it as the root element:
+ Then, inside pages/_app.tsx, import the AppCacheProvider component and render it as the root element (make sure to **pass the props** from `App` to the provider): |
Steps to reproduce
I have a Nextjs app with Pages router, Typescript and Tailwind. I am following the Next integration guide
Here is my
_app.tsx
and
_document.tsx
:Current behavior
Whenever a page loads/reloads you can see the button component flickering.
MUI.bug.mp4
I have also tested with Next v14 with same result. When I remove the
AppCacheProvider
from_app.tsx
I don't get that problem.Expected behavior
No response
Context
No response
Your environment
npx @mui/envinfo
Search keywords: AppCacheProvider
The text was updated successfully, but these errors were encountered: