Next.js website is working fine in production mode but not dev mode
Answered
Cordilleran Flycatcher posted this in #help-forum
Cordilleran FlycatcherOP
I have a responsive navigation bar (using Material UI's app bar).
In production mode, the app bar loads properly depending on the browser size. On smaller browsers/mobile devices, a hamburger icon is visible. On larger browsers, all the navigation options are out in the open straightaway.
In dev mode, I am always shown a mobile view with the hamburger icon, even on larger devices like my laptop. Why is there this discrepancy? How can I get rid of it?
In production mode, the app bar loads properly depending on the browser size. On smaller browsers/mobile devices, a hamburger icon is visible. On larger browsers, all the navigation options are out in the open straightaway.
In dev mode, I am always shown a mobile view with the hamburger icon, even on larger devices like my laptop. Why is there this discrepancy? How can I get rid of it?
Answered by Cordilleran Flycatcher
I think my browser was zoomed in to 175%. I didn't realize that for a long time.
46 Replies
Asian black bear
Are you using the
/pages or /app directory for your application?@Asian black bear Are you using the `/pages` or `/app` directory for your application?
Cordilleran FlycatcherOP
/app directory
Asian black bear
How did you implement support for
emotion? Did you start with the MUI template, or copy and paste stuff from github?@Asian black bear How did you implement support for `emotion`? Did you start with the MUI template, or copy and paste stuff from github?
Cordilleran FlycatcherOP
I think I started with the MUI template.
I basically just installed
I basically just installed
emotion with npm. npm install @mui/material @emotion/react @emotion/stylednpm install @mui/material @emotion/react @emotion/styledAsian black bear
that is probably the issue
@Asian black bear that is probably the issue
Cordilleran FlycatcherOP
What should I do to fix the issue?
Asian black bear
If you aren't extremely motivated to use the
/app dir wait until the support from MUI and Emotion is more enthusiastic. Otherwise, I am using them together with the template project provided with MUI and it does work OK! https://github.com/mui/material-ui/tree/master/examples/material-next-app-router-tsIf you are the sort of person that likes to add stuff from an empty project, these are the particular files that enable support: https://github.com/mui/material-ui/tree/master/examples/material-next-app-router-ts/src/components/Theme/ThemeRegistry
@Asian black bear If you aren't extremely motivated to use the `/app` dir wait until the support from MUI and Emotion is more enthusiastic. Otherwise, I am using them together with the template project provided with MUI and it does work OK! https://github.com/mui/material-ui/tree/master/examples/material-next-app-router-ts
Cordilleran FlycatcherOP
Thanks! MUI and emotion does work fine in production mode, just not dev mode. I think I will switch to something like DaisyUI which supposedly works with the /app directory for now.
Asian black bear
I have been on an entire adventure of considering switching away from MUI, but the real production-ready component libraries not using css-in-js are nonexistent
The difference between working in production and dev has to do with reconciliation/hydration stuff, and the example above definitely does fix it.
I am using a hybrid strategy for a project where the actual widgets like menus/buttons/inputs are MUI in
use client, but using tailwindcss instead of the sx prop, and not using any of MUI's document layout stuff like Typographyhonestly the pages are much faster now, and although skeptical at the beginning, it is actually working quite well.
@Asian black bear honestly the pages are much faster now, and although skeptical at the beginning, it is actually working quite well.
Cordilleran FlycatcherOP
Looking at the example above, do I just need to create a Theme/ThemeRegistry directory and add these three files in it in order to use MUI? https://github.com/mui/material-ui/tree/master/examples/material-next-app-router-ts/src/components/Theme/ThemeRegistry
Is there anything else I need to do?
Is there anything else I need to do?
Asian black bear
You have to wrap with the provider in the root layout too
And obviously implement the dependency tree from the provider
@Asian black bear You have to wrap with the provider in the root layout too
Cordilleran FlycatcherOP
I did this but I am still seeing the hamburger icon/mobile view on desktop.
@Asian black bear And obviously implement the dependency tree from the provider
Cordilleran FlycatcherOP
Can you elaborate on how to do this? I would appreciate it. Thanks
Cordilleran FlycatcherOP
My files are near identical to the ones in the repository you shared
@Asian black bear I am using a hybrid strategy for a project where the actual widgets like menus/buttons/inputs are MUI in `use client`, but using tailwindcss instead of the sx prop, and not using any of MUI's document layout stuff like Typography
Cordilleran FlycatcherOP
I'm not using the hybrid strategy. I'll try that and replace the sx prop
Cordilleran FlycatcherOP
Screw it, screw Next.js app directory and MUI for now. I love the app directory and I think its quite nice, but I really want to use MUI for my current project and I don't think the hassle of trying to optimize it for Nextjs is worth it. I will stick to Reactjs for now.
Cordilleran FlycatcherOP
I am getting the same issue in normal React and even Vite. idk what's going on
Asian black bear
Next.js pages dir is pretty much "just react" as you are saying, and MUI is really well supported there
How are you styling the navbar break? Is it with just media queries, or are you implementing a breakpoint with JS somehow?
@Asian black bear Next.js pages dir is pretty much "just react" as you are saying, and MUI is really well supported there
Cordilleran FlycatcherOP
Thanks so much for taking the time to help me with this.
Here is a reddit post I made. It includes the code for the navbar component. https://www.reddit.com/r/reactjs/comments/14lzxq3/reactvitenext_app_works_fine_in_production_mode/
The same component was used in Next.js, the create-react-app application, and Vite application.
I even tried copying and pasting a responsive navbar directly from the MUI website, but the issue still persisted on Next, CRA, and Vite. The navbar is responsive in production mode but not dev mode.
I mentioned in this comment that I checked to see if React/Next was detecting my device to be a mobile device in dev mode, and that is not the case. https://www.reddit.com/r/react/comments/14me7n5/comment/jq1vcy7/?utm_source=share&utm_medium=web2x&context=3
Here is a reddit post I made. It includes the code for the navbar component. https://www.reddit.com/r/reactjs/comments/14lzxq3/reactvitenext_app_works_fine_in_production_mode/
The same component was used in Next.js, the create-react-app application, and Vite application.
I even tried copying and pasting a responsive navbar directly from the MUI website, but the issue still persisted on Next, CRA, and Vite. The navbar is responsive in production mode but not dev mode.
I mentioned in this comment that I checked to see if React/Next was detecting my device to be a mobile device in dev mode, and that is not the case. https://www.reddit.com/r/react/comments/14me7n5/comment/jq1vcy7/?utm_source=share&utm_medium=web2x&context=3
Cordilleran FlycatcherOP
I even installed this node package to see what kind of device the website thinks I am using. https://github.com/Jam3/detect It clearly knows the website is being accessed from a desktop but yet still generates a mobile view in dev mode.
The website works fine on other browsers, just not Chrome. Must be some issue with Chrome then
Asian black bear
@Cordilleran Flycatcher The code you have posted on reddit isn't even a valid react component?
@Asian black bear <@113463039428182016> The code you have posted on reddit isn't even a valid react component?
Cordilleran FlycatcherOP
See here - https://pastebin.com/wUbMKDmp
Asian black bear
ok, I just didn't see the start of the function hiding with the imports
Cordilleran FlycatcherOP
The issue is with the Chrome browser. In Guest mode on Chrome and on other browsers like Microsoft Edge, everything is fine in dev mode. Something is up with the chrome dev tools when I am in my user account on Chrome.
Asian black bear
did you write all of this yourself, or is it a template from somewhere?
@Asian black bear did you write all of this yourself, or is it a template from somewhere?
Cordilleran FlycatcherOP
the code for the navbar? it is taken from MUI. It is a combination of the App bar with responsive menu
and Responsive App bar with Drawer from here - https://mui.com/material-ui/react-app-bar/
and Responsive App bar with Drawer from here - https://mui.com/material-ui/react-app-bar/
Asian black bear
I know what the MUI parts, just all of the rest of the code around them?
Cordilleran FlycatcherOP
Yea they were all taken from the MUI site and modified slightly for my project
Cordilleran FlycatcherOP
The issue has been fixed! Thanks for all the help! Case closed.
Asian black bear
I am unable to duplicate the failure in codesandbox
what was the issue>
@Asian black bear what was the issue>
Cordilleran FlycatcherOP
I think my browser was zoomed in to 175%. I didn't realize that for a long time.
Answer
Asian black bear
that would certainly do it!
Good luck on your project!
Cordilleran FlycatcherOP
Thanks! and thank you for all your help!