TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

React: The Perils of Rehydration

73 pointsby Epskampieover 3 years ago

8 comments

deckard1over 3 years ago
This is more about the perils of React switching from component classes where lifecycle methods were explicit and obvious to the multipurpose leaky abstraction known as useEffect and the hooks API. To anyone that went through the class phase, this issue is probably obvious and well known.<p>Also, Gatsby. If Gatsby is hiding the React warnings when your SSR diverges from client side, then that&#x27;s on Gatsby. It&#x27;s hard enough to debug when you know what&#x27;s going on. This is like going in blindfolded with both arms tied behind your back.<p>Luckily this issue only comes up a handful of times.
评论 #29422397 未加载
评论 #29428820 未加载
technobabblerover 3 years ago
I think the common, simpler way is to make the component itself (&lt;AuthenticatedNav&gt;) state-aware. So it always returns that component, but the component itself renders differently (`isLoggedIn &amp;&amp; &lt;NavBarSubComponent&gt;`) depending on some upstream state passed as a prop or a shared context via a context provider.<p>If you return two different tags like the author did, React won&#x27;t know how to properly inject that into the DOM. They are different elements, after all.
shadowgovtover 3 years ago
Honestly, it&#x27;s a very frustrating aspect of modern web development that developers still have to care about this client&#x2F;server split for initial render.<p>JavaScript, via Node, threatens to consume server-side implementations of user-facing output for no other reason than this is an annoying problem that gets even more annoying if your client and server are talking two different scripting languages.
评论 #29420187 未加载
评论 #29424168 未加载
ricardobeatover 3 years ago
I know this is way besides the point, but<p>&gt; Smart people realized that if we could do that rendering on the server, we could send the user a fully-formed HTML document.<p>Is so funny to read. It’s like history never happened.
评论 #29426750 未加载
edhelasover 3 years ago
If only there was a way to directly send the data when rendering the page server side...
评论 #29419399 未加载
literallyaduckover 3 years ago
Trying to couple client server might seem like a good idea, but you are always left guessing as to how the component got in the state it is in, which defeats a lot of the stateless ideas and puts us in a bad place debugging. Express is a good idea, React is a good idea, NextJs and the like make the developers guess until they get burned enough and then by that time a new concept like hooks vs class components comes to popularity and you start the process of learning where the new pit traps are located, until the next big shakeup.
评论 #29432947 未加载
whiddershinsover 3 years ago
Could this happen in sveltekit?
评论 #29420387 未加载
评论 #29427178 未加载
p2hariover 3 years ago
Just to clarify myself. If I have already logged in and now closed the window. Again open a tab and send request to the server, won&#x27;t the token&#x2F;cookies&#x2F;sessioninfo etc. be sent in the initial request to the page? And if the auth info is sent via the headers, can we not check the user login status (expired sessions) at the server and send the right component back?