Skip to content
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

NextJS Link tag causes styling bugs with styled components #29210

Closed
AndyW22 opened this issue Oct 21, 2021 · 8 comments
Closed

NextJS Link tag causes styling bugs with styled components #29210

AndyW22 opened this issue Oct 21, 2021 · 8 comments
Labels
duplicate This issue or pull request already exists status: waiting for author Issue with insufficient information

Comments

@AndyW22
Copy link

AndyW22 commented Oct 21, 2021

  • [ x] The issue is present in the latest release.
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

With a client side transition using the nextjs Link component, the styles in various components have issues such as the transition css property not being applied and border-radius. Its fixed when you do a full reload, and doesnt happen with regular tags.

Expected Behavior 🤔

The styling looks the same as on a full reload

Steps to Reproduce 🕹

https://github.com/AndyW22/muissrbug

Steps:

  1. yarn install && yarn build && yarn start

  2. click on the Paper component and notice the differences in the styling between the component you just clicked on and the one that is now shown on a different page, they are the same component but have different styling.

This doesnt happen if you use an <a> tag, so the issue is to do with compatibility with the nextjs Link component. This didnt happen with v4.

I followed all the steps to add styled components, the bug might be due to not doing that correctly.

I also added a key to _app.tsx for the component rendering which should re-render the component on a page transition.

Your Environment 🌎

NextJS
Material UI V5
Typescript
Styled Components

@AndyW22 AndyW22 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 21, 2021
@mnajdova
Copy link
Member

Is it intentional that you have JSS too in the project? Also, in the link that you shared, you are using styled-components directly, so I am not sure how does it related to mui. Can you elaborate? Is this a styled-components issue? Is SSR not configured correctly?

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 25, 2021
@AndyW22
Copy link
Author

AndyW22 commented Oct 25, 2021

Is it intentional that you have JSS too in the project? Also, in the link that you shared, you are using styled-components directly, so I am not sure how does it related to mui. Can you elaborate? Is this a styled-components issue? Is SSR not configured correctly?

Yes its intentional to use JSS, I am using styled components directly but that is using a styled MUI component (Paper component). without using an MUI component the bug doesnt happen.

I dont think this is a styled components issue as with MUI v4 there were no issues, but likely related to SSR config. I followed the guide to implement MUI with SSR + styled components, but either I missed something or the guide is incomplete or there is a bug with MUI.

@pedroeckel
Copy link

@AndyW22 Did you find any solution? I'm facing the same problem

@AndyW22
Copy link
Author

AndyW22 commented Oct 29, 2021

@AndyW22 Did you find any solution? I'm facing the same problem

No, only "workaround" is using <a> tags instead which ofcourse loses all of the Link tag benefits.

@opolo
Copy link

opolo commented Nov 10, 2021

We have same issue.... We should have waited with updating to MUI5 till NextJS was better tested x_x

@mnajdova
Copy link
Member

mnajdova commented Nov 23, 2021

No, only "workaround" is using tags instead which ofcourse loses all of the Link tag benefits.

@AndyW22 does it work using the Link component provided as part of the example project?

@AndyW22
Copy link
Author

AndyW22 commented Nov 23, 2021

No, only "workaround" is using tags instead which ofcourse loses all of the Link tag benefits.

@AndyW22 does it work using the Link component provided as part of the example project?

@mnajdova The example doesnt use any styled components, all it does is setup compatibility (by adding the server styled sheet on _document.tsx) but doesnt use it. all the styles are just made by importing mui components into each react component.

I tried adding the CardContainer component from my example into the /about page, and the same issue occurs.

it would be helpful if the example repo provided examples on using styled components rather than just setting it up, it seems like actually using styled components hasnt been tested but rather just adding it to the project and compiling.

@mnajdova
Copy link
Member

I am closing as a duplicate of #29742 I know that this is an older one, but more discussion happened there in the meantime. Please continue the discussion on the other issue.

@mnajdova mnajdova added the duplicate This issue or pull request already exists label Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

4 participants