I started creating an isomorphic React/Redux app based on Node. One requirement of the project is "adapative" rendering of specific components based on a "mobile" and "desktop" view. I have implemented Redux action and reducer to store screen-information about the user's view (based on media queries - "small", "medium", "large") in the state. On resize the state/store gets updated. The default state is "small".
const defaultState = {
isMobile: true,
isTablet: false,
isDesktop: false,
sizes: {
small: true,
medium: false,
large: false,
huge: false,
},
};
In the component which needs to be rendered "adaptive" in two different versions based on the screen size, I simply do a:
if (small) return variation1
if (medium) return variation2
All working.
Now I am facing two problems:
my app is isomorphic, that means the markup renders also server-side. The server doesn't know anything about the user's browser and media queries. So because my default state is "small", the server will always render "variation1". The node-server is the entry point for the site. It looks like the rendering needs to be "delayed" (middleware?) and the server needs to get some information back from the client about the browser width before the React app gets "delivered". Any idea how this problem can be solved?
because the rendering is based on the state, after load "variation 1" can be always seen first for a few milliseconds (flicker), even when the browser size is "desktop". This is because the JS detection takes a few milliseconds before the state gets updated with the current screen width. I think this plays together with above problem and the default state.
I couldn't find any solution for 1, but I guess there must be something isomorphic AND responsive/adaptive.