-
Notifications
You must be signed in to change notification settings - Fork 11
First render uses the first breakpoint it finds #8
Comments
This Problem is originated because we don't know the viewport of the client and so we fallback to mobile, and then on the client side it calculates the correct viewport and changes as can be seen on your example. |
Been investigating other libraries and seems like they use the We could use it as well to calculate our initial breakpoint what do you guys think ? Because today is always mobile so when we don't want to take the risk to have the mobile showing in desktop we use the isCalculated to prevent it from been shown in SSR. |
As an example: material UI media query ssr Here they suggest to their clients to use the user-agent-js in their side. |
That could be a good idea, by using the agent on both server and client side, it has a lot more chances of matching the real device. It would also be SSR friendly. However we would still need to run the logic in What do you think? @dinospereira @sofiacteixeira @themariamarques |
Yeah the idea was to have the What also would be cool is to see the number of times this calculates the correct breakpoint. |
@joaopedrodcf are you available to create a PR with that? |
Yeah 🔥 |
@dinospereira @sofiacteixeira @themariamarques what do you think? |
It looks like a good approach! Thanks @joaopedrodcf and @SoaresMG! |
I think its a good approach, thanks @joaopedrodcf |
Okay guys just to give an update on this so I been experimenting with So something like this could be made const ssrInferedMediaType = device.type === "mobile" ? "xs" : "xl"; And we could take advantage of the MR #28 in here to get the Another option instead of integrating the library ourselves let our clients use it and update the readme with how to do it https://codesandbox.io/s/admiring-dubinsky-6dm0u?file=/src/index.js:494-562 this sandbox show how to do it. const ssrInferedMediaType = device.type === "mobile" ? "xs" : "xl";
const mockProps = {
initialMediaType: ssrInferedMediaType,
breakpoints,
breakpointsMax
};
const rootElement = document.getElementById("root");
ReactDOM.render(
<React.Fragment>
<React.StrictMode>
<ResponsiveProvider {...mockProps}>
<App />
</ResponsiveProvider>
</React.StrictMode>
</React.Fragment>,
rootElement
); Opinions? |
what are your thoughts on this guys @SoaresMG @dinospereira @sofiacteixeira @themariamarques ? |
Closed due to project archival #76 |
Issue Report
Right now the first time
ResponsiveProvider
runs it will use the first option onbreakpoints
(which normally is the smallest one).Expected Behavior
It should render the correct breakpoint of first usage.
Actual Behavior
There is a jump from the initial breakpoint to the correct one after
useEffect
runs the first time.Steps to Reproduce the Issue
mobile
todesktop
(there is a visual jump)The text was updated successfully, but these errors were encountered: