Live data from Hacker News

React: The Perils of Rehydration

joshwcomeau.com

11–20 of 37 posts

Re: React: The Perils of Rehydration

#11
post #7
post #4

Earlier quoted context omitted.

I'd suggest you re-read this[1] section of the article -- they're talking about "server-side generation" where rendering happens at compile time, not at request time (to avoid delaying responses with on-the-fly render computation). The data you're referring to will not be available at compile time. [1] https://www.joshwcomeau.com/react/the-perils-of-rehydration/...

Personally, and I totally recognize that I'm likely arguing a moot point, I don't conflate static-site generation and server-side rendering and I don't think they can or should be used interchangeably as the author indicates. If my site can be hosted by Nginx alone, it's not server-side rendering to me. On the other hand, if I am paying for the overhead of running a node server to host my site, but it doesn't support…

In the Next.js/Vercel world, this hybrid architecture is primarily (I believe) an issue of cost savings (for them and you). For $20/mo Vercel will host your hybrid Next.js side, yet do all of the backend configuration and maintenance on your behalf, configuring not just NPM but Lambda and Cloudflare Workers, along with nginx and caching and CDN mirroring and invalidations, all seamlessly.

So as a dev you can just code against the Next.js docs and not have to play devops. That's a LOT of time savings for $20/mo, and you can afford way more page hits this way than a barebones $20/mo NPM VM would get you. Yes, backend it's super complex and fanned out to different providers, but Vercel manages all of that for you.

I imagine Gatsby and Netlify are similar, but not sure. Next.js was designed around Vercel specifically (sadly) and there's a lot of vendor-specific lock-in features.

Re: React: The Perils of Rehydration

#12

Honestly, it's a very frustrating aspect of modern web development that developers still have to care about this client/server split for initial render. 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.

Nobody has yet stepped up and delivered a WASM PHP client side renderer. I bet it would even be size competitive with modern JS frameworks!

Re: React: The Perils of Rehydration

#13

Could this happen in sveltekit?

It seems somewhat unlikely for a number of reasons. The article was quite long, so I didn't read it all, but a key takeaway seemed to be "Gatsby only uses the server-side rendering APIs when building for production". SvelteKit does SSR rendering in development as well, so you wouldn't have the issue of dev and production being different in that way. Also, Svelte's hydration works a bit differently than React's.

Re: React: The Perils of Rehydration

#14
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't the token/cookies/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?

Re: React: The Perils of Rehydration

#15

Honestly, it's a very frustrating aspect of modern web development that developers still have to care about this client/server split for initial render. 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.

Nobody has yet stepped up and delivered a WASM PHP client side renderer. I bet it would even be size competitive with modern JS frameworks!

This is a hilarious idea, bonus points if you somehow wrap it in electron with its own local sql lite instance and pitch it as a cross platform desktop app development toolkit.

Re: React: The Perils of Rehydration

#16

Earlier quoted context omitted.

Nobody has yet stepped up and delivered a WASM PHP client side renderer. I bet it would even be size competitive with modern JS frameworks!

This is a hilarious idea, bonus points if you somehow wrap it in electron with its own local sql lite instance and pitch it as a cross platform desktop app development toolkit.

You laugh, but I'll bet you there's someone pitching this very product to room full of enthralled VCs right now.

Re: React: The Perils of Rehydration

#17
post #7

Earlier quoted context omitted.

Personally, and I totally recognize that I'm likely arguing a moot point, I don't conflate static-site generation and server-side rendering and I don't think they can or should be used interchangeably as the author indicates. If my site can be hosted by Nginx alone, it's not server-side rendering to me. On the other hand, if I am paying for the overhead of running a node server to host my site, but it doesn't support…

In the Next.js/Vercel world, this hybrid architecture is primarily (I believe) an issue of cost savings (for them and you). For $20/mo Vercel will host your hybrid Next.js side, yet do all of the backend configuration and maintenance on your behalf, configuring not just NPM but Lambda and Cloudflare Workers, along with nginx and caching and CDN mirroring and invalidations, all seamlessly. So as a dev you can just cod…

I completely get that this ease of configuration is a huge selling point. Yet I don't think that precludes the possibility of pre-loading information and injecting it at runtime. My main qualm here is probably one where the meaning behind terms like "server-side rendering" are drifting to favor artificial limitations imposed by framework providers.

> Next.js was designed around Vercel specifically (sadly) and there's a lot of vendor-specific lock-in features.

I ran into this while playing around with their middleware. It surprised me that native Node APIs weren't supported which significantly diminishes its utility.

Re: React: The Perils of Rehydration

#18
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.

Also, Gatsby. If Gatsby is hiding the React warnings when your SSR diverges from client side, then that's on Gatsby. It's hard enough to debug when you know what's going on. This is like going in blindfolded with both arms tied behind your back.

Luckily this issue only comes up a handful of times.

Re: React: The Perils of Rehydration

#19

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. Also, Gatsby. If Gatsby is hiding the React warnings when your SSR diverges from client side, then that's on Gatsby. It's hard eno…

Didn’t read the article, but I have to rant a little bit.

Working with `useEffect()` is so fucking miserable. It’s a bit like owning a car where the gaps between the panels are just slightly too far apart; there’s always the possibility that some data is out of sync because React inexplicably decided to run a thing a tick later than you expected. “Effects” don’t actually mix with with the old class component methods, insofar as you’ll never be able to get an effect to run before component methods, so you end up having to gasp do side-effects in render against a bunch of “refs” to achieve some semblance of object permanence.

The implication behind the naming of “synchronous effects” as `useLayoutEffect()` is laughable, as though the only time you would ever want to run some code synchronously is for “layout” purposes. My guy, JavaScript’s security model is based on execution, you can’t copy to the clipboard, request full-screen/picture-in-picture, do countless privileged operations outside the synchronous execution of a native click handler, for instance, and we’re going to place all these use-cases under the umbrella term “layout?”

React applications are weird, shuddering messes, where callbacks fire senselessly based on “dependency arrays.” Heaven forfend you turn off linting which helps you not violate “the rules of hooks,” and even when it’s on there are countless gotchas about default parameters and callback functions which are recreated every render. At no point will you ever be able to correctly source the initiator of a “render,” because someone in their infinite wisdom decided to unroll the JavaScript call stack as a queue. Stepping out of a component in a debugger always places you in the same `while` loop and you’re left wondering where on Earth did this execution start. I don’t understand how programmers could be so ignorant of how useful a call stack is, and the React team essentially has to recreate call stacks in error messages and Devtools. Seasoned React developers have all seen “React minified error #185,” or “Maximum update depth exceeded.” This is essentially a stack overflow error, except of course they did away with the stack. It’s not normal for stack overflow errors to be happening as frequently as happens in React applications, and this is just when you’re lucky enough to get a warning; a lot of times the page will just hang and no one except your poor users will know.

I find it truly disturbing how professionals can make their and everyone’s lives so difficult, how deeply disconnected React is from the actual practice of programming, which is all about understanding how your code executes. My mind is boggled by 5 by 5 zoom calls of well-paid “staff engineers” chatting about React and writing tutorial upon tutorial like any of this normal. And these are the loud ones. I pray for the entry-level programmers, the contractors, the voiceless, who aren’t beefing on Twitter, who do not have a sense of how strange this kind of development is and don’t have the courage to speak up.

Re: React: The Perils of Rehydration

#20

Earlier quoted context omitted.

In the Next.js/Vercel world, this hybrid architecture is primarily (I believe) an issue of cost savings (for them and you). For $20/mo Vercel will host your hybrid Next.js side, yet do all of the backend configuration and maintenance on your behalf, configuring not just NPM but Lambda and Cloudflare Workers, along with nginx and caching and CDN mirroring and invalidations, all seamlessly. So as a dev you can just cod…

I completely get that this ease of configuration is a huge selling point. Yet I don't think that precludes the possibility of pre-loading information and injecting it at runtime. My main qualm here is probably one where the meaning behind terms like "server-side rendering" are drifting to favor artificial limitations imposed by framework providers. > Next.js was designed around Vercel specifically (sadly) and there's…

> Yet I don't think that precludes the possibility of pre-loading information and injecting it at runtime.

Can you explain?

Post reply on HN