-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
Allow className to be used on the Main element #3799
Conversation
return ( | ||
<Fragment> | ||
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} /> | ||
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} className={className} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add a test case for this. So that it won't break in the future 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have something in today. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies. It has taken a bit longer than expected to get to this.
I opened up the test
folder and was trying to decipher where everything was located. Is it just me, or does everything seem a bit "disorderly" there? At the very least, I was having some trouble getting my bearings.
Any suggestions to which file this test should reside in would be very helpful. :)
Same issue here after upgrading to 5.0.0. @stephencorwin how do you overcome the issue meanwhile? |
@kachkaev I ended up moving everything within the We definitely should still be able to use |
I still wonder why it’s needed, there is an id on the element, it’s Selectable using css 🤔 |
I simply solved the lack of className in Main by wrapping it into a div: Now i’m also wondering if a complication of Main in v5 is worth it given that the fix is so easy. Only those who are switching from Next v4 to v5 may get confused, and according to the number of :thumbs_up: in the PR, the number of us is not so large. |
Right, so there is no real gain in adding this, since you can either: I'm basically trying to avoid adding something (shipping more code) for something that can be done like your suggestion 👍👌 Either way thank you very much @stephencorwin for making the PR and @kachkaev for getting involved 🙏 👍 |
Makes sense. If I remember correctly, the only reason why I had to have this additional |
Thank you for this PR @stephencorwin – your investigation of this issue really helped me migrate to next v5! |
@timneutkens For me, I find having to refer to Personally, I don't usually subscribe to using Bootstrap, but ALOT of the project that I take on are already using it. If I cannot drop a class provded from Bootstrap on tldr – this was supported before and |
In short, I'll write the test case this weekend to finish pushing it through if you will reopen the PR. |
The reason the className was added was because there was no good way to select the wrapping div. Note how here the className is set on the With regards to styling and eg bootstrap, the recommended way to do wrapping of all pages is https://github.com/zeit/next.js/tree/canary/examples/layout-component, since _document is also only server rendered. |
The only non-breaking change would involve forcing a wrapper div inside Main, but that would be the same as not using Fragments. In most cases an extra wrapper div can bring pain because it may require styling. So in general it’s great that Fragment helps get rid of that forced extra div, while _document gives enough flexibility to add a wrapper if it’s needed. |
Exactly @kachkaev 🙏 |
Not totally in love with it, but I could concede. Personally, I feel as though every component that involves injecting DOM nodes, should support the However, the example that is shown from @kachkaev + the layout component makes me think that I might be able to approach it very much like the Handlebar's Thanks! 👍 |
I was using
next 4.2.3
. I just upgraded to5.0.0
today and discovered that the classes that were being passed in on the<Main />
component in the_document.js
were no longer coming though.After some digging, it looks like the
className
pass-through was removed in 4.3.0-canary.1.Clearly, the reason why it was removed was because
<Main />
is now returning a<Fragment />
instead of a<div />
as the top-level element.<Fragment />
does not supportclassName
as a prop.https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html
This PR aims to still allow a user to pass in classes via:
Styled Components
This is especially important in the case of supporting
styled-components
.tl;dr;
styled-components
requires theclassName
pass-through for any component composed withstyled()
.https://www.styled-components.com/docs/basics#styling-any-components
This used to work, but no longer does:
Use Case
Sticky Vertical Layout
<Header />
fixed to the top<Footer />
sticky to the bottom (content pushed)<Main />
flexesNo longer works:
![image](https://user-images.githubusercontent.com/3931162/36192162-7292d3c6-112e-11e8-998f-5de4a2731e95.png)
Before:
![image](https://user-images.githubusercontent.com/3931162/36192383-3fa0f21c-112f-11e8-9e4d-7bc9f39f0a77.png)