-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Responsive: Not rendering correctly with SSR #3110
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
@teoraunio thanks for the detailed report!
const getWidth = () => {
if (isBrowser) return window.innerWidth
return 1000
}
<div className="top-bar">
<Responsive fireOnMount getWidth={getWidth} minWidth={1000}>
<div className="desktop-content-1" />
<div className="desktop-content-2" />
</Responsive>
<Responsive fireOnMount getWidth={getWidth} maxWidth={1000}>
<div className="mobile-content" />
</Responsive>
</div> If issue will not be solved, just ping me and I will reopen it. Can you please also create an example repo with a preconfigured env, if it will persist? |
@layershifter Thanks for your quick reply! Unfortunately, this did not fix the issue. Now exactly the same is happening if the window width is less than 1000 pixels in the first render. So when the child div's className should be
The content inside the div is correct, only the className is incorrect. I am not able to create an example repo at the moment but I may look into it later on if necessary. |
Yes, please create a repo with a simple example. |
I've updated a message (fixed I've checked all should work correct, waiting for a repro repo. Please keep it simple. |
Will reopen if we will receive a repro case. |
This didn't work for me either. I'll try to get a repro repo over tomorrow. |
Nvm. Replacing your
Thanks for the help! |
Thanks for this great feature. I had to use const isBrowser = () => typeof window !== 'undefined'
const getWidth = () => (isBrowser() ? window.innerWidth : 0) |
in server side getWidth 0 render with Mobile view |
My comment there contains working solutions. |
Bug Report
I am trying to create a top bar which uses two Responsive elements to determine if it should render content for over or under 1000 pixel resolution. The app is using server side rendering.
The problem (code below to understand the props and classes):
When the window size is over 1000 pixels, it will render a Responsive element that has
minWidth={1000}
as expected, but the first element inside the Responsive is actually from the other Responsive element withmaxWidth={1000}
So what happens is:
maxWidth=1000
aswindow
doesn't yet exist and the width is set to 0 inside the Responsive component.minWidth=1000
<div>
element that should have classdesktop-content-1
has falsely classmobile-content
that is defined inside the otherResponsive
element.I am aware that this can be fixed by wrapping both Responsive elements in separate containers, but it means using unnecessary elements and it should at least be specified in the documentation.
Steps
You need an app that uses Server Side Rendering with the following piece of code rendered to reproduce the problem:
Expected Result
The width of the window is over 1000 pixels.
Actual Result
The width of the window is over 1000 pixels.
Version
0.77.1
The text was updated successfully, but these errors were encountered: