react-media-match
react-media-match copied to clipboard
Partial Hydration based SSR media queries
It's possible to render a "predicted" target during SSR, but the guess might be incorrect. In order to "fix" we have to render everything twice:
- first with predicted target, to match SSRed markup
- next with the real target, where some pieces of Application could be rendered a bit differently. And that has a cost.
Proposal
MediaMatchesmight partial hydrate their children, in order to keep existing HTML if targets do not match, and update with a proper markup later.- that would reduce the amount of work React has to do.
MediaServerRendercan do it automatically for a whole application as well.
Should be safe due to a top-level matches provider, which can orchestrate everything below it.
Alternatively
- expose "couldUseHydration" function, which will propose to use
renderin case ofhydrationwill lead to adouble rendering. It's way faster to drop HTML andrenderReactComponent, than to hydrate twice.
Don't forget about #11 - almost the same (but the opposite). #36 and #11 could play very nicely together.