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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[examples] SSR on the Next.js official example not working #32051
Comments
@ziedHamdi apparently something is not playing nice with React 18 here (React 18 was released literally 1 day ago) You can resolve this issue by downgrading to React 17 in your package.json:
|
We probably want to update the react version in the examples until we are fully compatible with React 18 |
@igordanchenko thanks for the fast reply, I'm happy that it's actually just a React 18 problem for the example. I'd be interested in how you will find the problem in React 18: Because I have React 17.0.2 in my project and that's where I noticed SSR was not working anymore after migrating to mui5. StackOverflow original problem I really don't know where to look, as I don't know what is expected to be returned by extractCriticalToChunks (kind of a black box to me)? Do I have to enable a debug mode for emotion to understand what went wrong etc... I also don't know how to create a project that reproduces the bug, since I don't know at which moment my project (with all its intricate complexities) will stop working if I start from your template and keep adding stuff. Are there any documents you could recommend for that? Or should I wait until you fix the React 18 issue and check if it was solved? |
I reproduced a 'non working' ssr version even in React 17.0.2 by starting with your working project and editing index.js in a more real world project like form https://github.com/ziedHamdi/mui-next-ssr-error I'd be glad to help find out what's going wrong, I just don't know where to start, so please do not hesitate to tell me if I can help somehow |
Hi Marija,
Thank you for taking the time to look into this bug.
The "Sign-in" link in the header should be aligned to the right, and there's
a text also to the right that says "large content screen" (see attached
picture). Do you think the problem is because the size of the screen is not
detected?
p.s: I'm wondering if there are not two issues: If you disable js, you can
see my real project without any styles at https://preprod.weally.org/ (the
link doesn't even have the capital letters)
![Capture d鈥櫭ヽran de 2022-04-05 07-07-43](https://user-images.githubusercontent.com/7271508/161685246-dd58ca02-3b4d-431a-8630-b29e4fbe0206.png)
![Capture d鈥櫭ヽran de 2022-04-05 07-23-12](https://user-images.githubusercontent.com/7271508/161685257-24980a92-df86-4f65-b4f2-f0db9e602a10.png)
|
I just saw that you also use For example, have a look how we are doing it on our documentation You will need to have configured both emotion and JSS. I would strongly recommend using |
Hi @mnajdova , I just removed makeStyle (from tss-react as described in your migration guide) and things seem to work back. There remains one issue with useMediaQuery that is not reacting when js is disabled. You can see it in the app: there's a text saying 'large screen content' that you can see on large screens if js is enabled but that disappears otherwise. Also in my app, I have nothing that works, I'll try to move files progressively to this project to understand when it stops working and get back to you with the cause, that might help other people |
@ziedHamdi did you follow the instruction for setting up SSR from the tss-react repo? |
Sure! I double-checked. You can still see it in the git history of the project. |
I confirm that react 18 break SSR for us. |
Hi @mnajdova, Best regards, |
@garronej has prepared a good repro case and based on it I've created an issue in Next.js project to clarify how this is supposed to be set up: vercel/next.js#36268 |
The created issue was closed by this PR so I assume that this should get fixed with the next Next release. |
I did try the latest nextjs 12.1.6-canary.6 release and i have still the issue. If you trying extending the theme, the component can't read a custom key that you add to the theme. Example: import { createTheme as createBaseTheme, responsiveFontSizes } from "@mui/material";
const createTheme: (themeMode: "light" | "dark", themeDirection: Direction, responsiveFont?: boolean) => ITheme = (
themeMode,
themeDirection,
responsiveFont = true,
) => {
const isLight = themeMode === "light";
const themeOptions = useMemo(() => {
return {
direction: themeDirection,
customShadows: {
z24: "0 0 4px 0 1, 0 24px 48px 0 1",
z20: "0 0 4px 0 1, 0 24px 48px 0 1",
},
customComponent: {},
};
}, [isLight, themeDirection]);
const theme = createBaseTheme(themeOptions) as unknown as ITheme;
if (responsiveFont) {
return responsiveFontSizes(theme);
}
return theme;
}; Than the customShadows cannot be found in a component which is using the key |
Please prepare a full runnable repro case so I could jump into investigating this |
Since the issue is missing key information, and has been inactive for 7 days, it has been automatically closed. |
Hi, |
The error is still there, with custom themes |
this issue is fixed. -const CustomButton = styled(Button, {})((theme) => {
+const CustomButton = styled(Button, {})(({ theme} ) => { If you want to declare custom key in theme and have it working with typescript you have to implement module augmentation, example here Also I point out that this memoization is unessesary, you create a new theme each render anyway: And here it should be |
UPDATE: It's still broken, but for another reason. This is solved, now it's this. @mnajdova I think this should be reopened until Versel fixes the regression. Best regards |
Offtopic: @garronej good that you updated your comment, next time think twice how you write a message. Thanks for the hint. |
Just experienced a similar error in my project. The html built in server-side didn't have any css and turns out it was because I updated Next to version 12.1.6. Once I downgraded it back to version 12.1.4 everything went back to normal. Using next@12.1.4, react@^18.1.0, react-dom@^18.1.0, mui/material@^5.8.0 and mui/material-icons@^5.8.0 everything works fine here. |
Hooray it works with Next 12.1.7-canary.4 馃コ |
I don't know if it is related to this bug, but I have some styles that do not appear in SSR. Even an id of a Box doesn't appear in SSR but appears when run client side. The screen captures here can be tested at my website here. Open developer mode and choose mobile view with 310px width. The first load will be css broken, then close PLEASE NOTICE EVEN THE DIV ID IS NOT PRESENT IN SSR My code is pretty forward: detail.js returns this
And IssueDetail is as follows:
|
@ziedHamdi it's super hard to tell what might be wrong based on just a code. Ideally you should provide a minimal runnable repro case of the problem and share that with maintainers so they could take a look at this. |
I know @Andarist, I'm the one who started this issue (with an example) :-). This post was just in case someone had the same issue to react here. As you can imagine, the project is complex, and some css work correctly and some other not. Finding when this occurs exactly is not easy and takes time. So I was hoping someone had this on a less complex codebase. |
You could try bisecting your codebase - remove stuff in huge chunks and observe if the issue is still reproducible. This usually helps narrow cases like this relatively quickly. |
Ok I'll try to do that and file another issue with the repo |
Was this resolved? I have the exact same issue |
OK, so in your repo, you have both CacheProvider and StyledEngineProvider. You need only CacheProvider and that will resolve the issue |
Complete the v5 migration with tss-react, it worked for me. |
Duplicates
Latest version
Current behavior 馃槸
Cloning the official next.js ssr example is not doing ssr at all:
Disabling javascript in the browser shows a raw html page (with almost no css except those for fonts)
Expected behavior 馃
Expected to see the page styled
Steps to reproduce 馃暪
Steps:
1.curl https://codeload.github.com/mui/material-ui/tar.gz/master | tar -xz --strip=2 material-ui-master/examples/nextjs
2.cd nextjs
3.yarn install
4.yarn dev
5.disabled javascript in browser
6.load localhost:3000
Context 馃敠
This is related to me migrating my project from v4 to v5. Here's the StackOverflow question related to this bug
Your environment 馃寧
`npx @mui/envinfo`
I'm using chrome
The text was updated successfully, but these errors were encountered: