question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supporting partial rehydration on server side rendered pages

See original GitHub issue

The problem

While SSR in NextJS works well with hybrid pre-rendering targets by page, it would be much more effective if this option was available on a component level rather than just by page.

Consider the following scenario: A page includes a large number of components. The majority of those components don’t have much need to be interactive on the client side after being rendered on the server while a minority of those components (say 10%) will need to re-hydrate to be interactive and have their JS loaded on the client.

In such a case, I’d have no option but to SSR the whole page and all the components involved in order to make sure that 10% of the components are gonna be interactive. At the same time, the 90% will also have to get re-hydrated, and I’d have a really bloated __NEXT_DATA__ with state and values that are not entirely needed, that will end up being evaluated and processed by the browser.

Proposed solution

Instead of doing SSR on all components and then sending the entire application to the client to be re-hydrated, I’d have the option of marking specific components to not hydrate on the client which would signal to NextJS that the component will be statically generated and potentially prevent any related data to be sent via __NEXT_DATA__ back to the client. At the same time, the components that need to be re-hydrated would get re-hydrated normally.

This could potentially bring big savings for the case mentioned above in terms of cutting down on unneeded JS that will have to be evaluated and executed by the browser.

Is this something that has been discussed before or currently on the roadmap ? Is it something that I could potentially build myself on top of NextJS ? Would really appreciate any pointers around how I could potentially solve this problem in case there are no plans for official support on it.

This post seems to be proposing a solution to the problem, I’d really love to hear your thoughts on this approach and whether you’re looking into officially supporting it.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:33
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

38reactions
timneutkenscommented, Jan 31, 2020

It’s on the roadmap and something we’re collaborating on with the React and Chrome team, we’ll share more information when possible.

Overall it’s currently not possible to do this besides following what’s described in the article.

Definitely something we plan on tackling eventually!

There’s a bunch of issues around this already so I’ll close this one.

15reactions
bramvbilsencommented, Aug 2, 2021

Is there any timeframe or priority level compared to other features? We are also really looking forward to this feature!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Progressive Hydration - Patterns.dev
Hydration allows client-side React to recognize the ReactDOM components that are rendered on the server and attach events to these components.
Read more >
The case of partial hydration (with Next and Preact) - Medium
The basic idea behind our version of partial hydration is: Instead of doing SSR and then sending your entire application to your client,...
Read more >
Hydrating text content from Server-Side Rendering | Tan Li Hau
Partial hydration in React is a mechanism to partially hydrate a server-rendered result while other parts of the pages are still loading the ......
Read more >
Rendering on the Web
The partial hydration approach comes with its own issues and compromises. It poses some interesting challenges for caching, and client-side ...
Read more >
Advanced Features: Automatic Static Optimization | Next.js
If getServerSideProps or getInitialProps is present in a page, Next.js will switch to render the page on-demand, per-request (meaning Server-Side Rendering) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found