Pre-rendering a personalised React app can mean rendering twice and paying more
Next.js and Gatsby have become the default answer to building a fast new site, yet for apps full of user-specific data, static generation brings double rendering, hydration mismatches and a stream of server requests someone has to pay for. Beth Swingler, a senior software engineer at YLD who has specialised in React and React Native for over five years, asks when server rendering actually earns its keep.
Learn a simple test for choosing server components, static generation or plain client-side React
Beth Swingler, a senior software engineer at YLD, argues that static generation and server components in frameworks like Next.js are not a default win: their benefits depend on whether an app's data is static and shared or dynamic and user-specific. She offers a "shades of state" mental model for that decision and highlights React 19 features beyond server components, such as the new use hook and auto-memoization.
“So the conceptual model that I was referring to, which is kind of the main point of my talk, is we should look at the shades of state that we're dealing with.”
“So, yeah, like, for example, if you are only showing data to logged in users and the data is specific to them, then that is probably one of the worst times.”
What you will learn
Distinguish static, shared data from dynamic, user-specific data before choosing a rendering strategy.
Explain why hydration mismatches and double rendering happen when dynamic content is pre-rendered.
Weigh the hidden server and request costs of server-side rendering for frequently changing data.
Identify content types, such as blogs and shops, where static generation and caching pay off.
Apply React 19 features like the use hook and auto-memoization to cut boilerplate.
Key takeaways from the speaker
The technical, performance issues with server-side rendering frameworks like Next.JS
The hidden costs of server-side rendering
The benefits of doing less work on users' devices or web browsers
Details
Level
Intermediate
Format
Tech talk
Technical depth
Practitioner
For
Early career, Mid-career, Senior individual contributor
Length
26:19
Published
May 2024
Questions this talk answers
Is server-side rendering always faster than client-side React?
No. It depends on the size of the initial bundle and, above all, on how much of the content is dynamic and user-specific.
Why does pre-rendering dynamic content cause problems?
Content that depends on the user cannot be compiled in advance, so the app renders twice and the hydrated DOM can mismatch, causing flicker and delayed interactivity.
When is static generation a good choice?
When content is static or shared between users, such as blogs or shops whose listings rarely change, because it can be cached and served to everyone.
What are the hidden costs of server rendering?
Live, frequently changing data can trigger many requests to the server, which costs money, and workarounds for mismatches can force extra renders after mount.
What else in React 19 is worth learning beyond server components?
The new use hook, which replaces useState and useEffect boilerplate for async data and can be called conditionally, and the compiler's auto-memoization, which reduces useMemo and useCallback.
About this talk
React is dead. Long live React? 2024 sees the first new public version of React since April 2022. Is React 19 worth the wait? We now have server components and an auto-caching compiler, so claims that React.JS is dead seem to be greatly exaggerated. But are meta-frameworks, such as Next or Remix, still needed to get the best new features?
A deep dive into the latest shifts in the world's largest open-source JS framework, and what these changes mean for developers, servers, and the people paying for them.
So to start with, I'm just going to introduce myself. So my name is Beth. I'm a senior software engineer and I specialize in React and React Native. I'm going to share my slides now. Okay. And basically, what is this talk? That is the question. It's going to be a little bit of an informal discussion about some ideas that I've had about, I guess, like the direction that React is going in, in light of mainly like Next.js and the increasing focus on like static side generation.
So, who here uses React? If you do, can you put an emoji or type the letter, yes, you know, or Y into the chat? Okay. Yeah, yeah. So we've got some React engineers as well. Great. And then how many of you use Next.js? Yeah. But like an, like a, yeah, yeah, yeah. Okay. So not, not that many people using Next yet. Interesting.
And who pays for Vercel? Anyone here currently like on the business side of things or like, I suppose, worried about the server costs? Okay. Cool. So that's just to kind of establish where we're at as a, as a group. So I've called this 50 Shades of State, and you will understand why shortly. I suppose to introduce some concepts. I'm going to define some terms, right? I'm a philosopher by training. So that's always a good place to start in my mind. Some definitions. So basically, a...
So basically, there are servers and clients. There's my computer and there's yours. So for example, if I was serving you a web app, there'd be two places where work could be done, where data could be stored and computations can happen. So for example, like if you request a form from me, I'll serve you the initial form. You interact with it. Some data is accumulated on your machine, which then gets sent to mine, and I give you back a success or failure response, for example.
And maybe like a new HTML file or some JSON or, you know, maybe just 200 response. And then, you know, your computer or the browser specifically can then render the appropriate UI given the response. It might even be a failure response. So there's basically two machines, like interacting, the request response, and then yours, the computer that does the request and response, and the computer, the client, the browser, basically.
So if you have a really bad or really underpowered browser, like, or a device that's very weak, then, you know, things can get really nasty. You can also now look at all the tabs in your browser and see how much memory they're using, which is like a nice new feature on Google Chrome, if you have it. And that's kind of an interesting way of seeing how much work you're doing by interacting with the web.
And that's kind of, you know, you can see how much, you know, it's kind of a new server that's not just the server. So you can also spin up a local server, like when you do Yarn Start, or NPM Start. And that actually is also on your computer. It's like a local host, it's literally hosting it locally.
But usually, you give this over to a hosting service, which may or may not also host your data and your backend. So I'm going to talk a little bit about the new trend, right, the promises of Next.js, static site generation. So Next.js and other static generation meta-frameworks like Gatsby as well, they're like becoming the norm. This is almost like the default go-to.
Like I find all the time people are like, I want to build a new site. I'll build it in Next or I'll build it in Gatsby. It's going to be lightning fast, right? And potentially for good reason. Like that can be the case. I won't go into things like the SEO benefits, but there really can be performance benefits.
Next.js in particular offers two types of pre-rendering. One is static generation. So you fetch, you pre-render the static pages at build time basically before you even serve them. These can also be cached on the edge servers, which can actually be close to the users that even are requesting them. Reducing that initial load time even more. There's also the fetch and render server side rendering of components that happens as well.
So you can fetch and render server components with the data in a single request and serve the data in the component directly, which is also essentially very quick. You can still build a very reactive react app using Next.js or similar frameworks. So they still allow for reactive interactions. After the initial load, the hydration will happen a bit like a normal app.
And then you'll have reconciliation. And basically all of the interactivity will load after the initial HTML has loaded, which is very similar to the lifecycle of any ordinary react app, except normally there's nothing to see basically during that initial load. So static generation gives you essentially something to look at during the initial load, which is great. It makes the user feel like they have the website instantly, potentially.
So service side rendering is a little bit different because that happens on your live production server in real time in response to every request. Whereas the compile time rendering happens like earlier as part of the build process. And that is where the initial load benefits come from. So basically with all these benefits, like why use react at all, you know, like just on its own is is this and should this be the future?
Like, should we just be always statically generating everything in advance? Like currently next JS has server side component support and react 19 is going to bring that to everyone, but next JS are really leveraging it right now. And when react 19 is in stable and out of the beta release, then you'll be able to do some of the things that next JS does, but not all of them.
They build in a lot of additional optimizations and they seem to just be really ahead of the game, right? So why not just have access to the latest features for statically optimizing your site like ahead of time? So to answer this question, we're going to look at how performance server side rendering is and static site generation compared with client side.
Because basically the question is how performance is your server side rendering compared with client side. And the answer to that depends on the size of your initial bundle. If you have a really small initial bundle, then potentially it won't actually matter that much, but most apps have quite a large initial bundle. And during that download, there's a wait time as well as during hydration.
If you use react for something like create react app, all of the rendering happens on the browser. And the browser still receives the initial HTML and injects the scripts, but it's a blank screen. So we might think that it's not that performant. But basically the question is, on initial load, how many times will you render a dynamic page on a statically generated app?
Have a think. Basically, the key word here is dynamic. And we're going to get to the mental model that I've been using a lot recently in a moment that's based around that word. Because the word dynamic basically means that it is something that varies, right? It can vary per user or per request. And the thing about dynamic content is that you won't know who the user is or what the product that someone wants to see is until you get that request.
And so what's interesting is that in that kind of situation, what happens is a double rendering. And this can lead to some really strange behaviors, actually. So when a react app hydrates, it assumes that the DOM structure, which has been put in place by the initial HTML, is going to match. And so when the react app runs on the client for the first time, it has an internal landscape, like an internal model of what it should look like, the page.
And so when it tries to fit these two together, it kind of does a spot the differences kind of game and then tries to handle future updates correctly. But if you are unaware of what content to show, for example, if you're trying to show straight off the bat, like a dashboard that shows the user's personal achievements in your domain or something, then that's not going to be something that you can actually compile in advance.
So there's always going to be a mismatch there. But even if there isn't a mismatch during that hydration process that you still, if you've statically compiled things, you still need to do this double rendering. So this kind of, yeah, this hydration process is meant to be really fast and meant to load things really quickly on the first mount, but mismatches are a huge problem there.
So if you have loads of non-personal content, then this can be fine because you might just have some small holes where the dynamic content is, like maybe it's a badge for the user's name. But even that badge can kind of flicker, right, because it won't be compiled in advance. It will only be able to be displayed after the amount of the component on the browser again.
So this is the new server-side model. Basically, render on the server, dehydrate it, as in all of the interactivity, all of the JavaScript, render it on the client, make it interactive. And from the Next.js docs, they tell you to think of the flow of the code as unidirectional from the server to the client rather than kind of the normal way of thinking about it, which is it's already on the client.
And if you need to access the server from the client, you send a new request to the server rather than reusing the same one. And this can lead to, like, really quite a lot of requests as well. So if the data changes a lot, for example, if you have, like, something that updates live, then you're making a hell of a lot of requests with different content.
And that can actually cost you quite a lot of money as well. It can also mean that you have to do really strange things to stop the mismatches that I was talking about earlier, where you have to check whether maybe even, like, a component or maybe even your entire application has mounted and then show nothing in order to stop, like, the flickering of changing content.
When the user is finally recognized, for example. This can really delay, like, the time to interactive, which is really important. And it can force a render, well, it will force a render directly after mount, which is considered kind of poor practice and has huge performance implications. So the real question is, like, do you have very small amounts of dynamic content or huge chunks of dynamic content?
Like, you only serve user-specific data. So then you'll miss out on loads of the benefits of pre-rendering by definition, and you might end up with a kind of uncomfortable mismatch situation as well. Whereas, you know, how many times are you going to render a client page on the initial load or application? Like, once, right? But that's with a load of caveats as well, because you might set a load of data after the initial mount, or you might be in strict mode in development or something, in which case it will render as well.
But that's going to be the case with your Next.js app as well. If you're doing those things, it will render more times as well. You can interleave some server-generated components. But if you have, like, a really fundamentally dynamic app, it is going to end up doing a little work on the client. So the conceptual model that I was referring to, which is kind of the main point of my talk, is we should look at the shades of state that we're dealing with.
And by state, I mean data, which can form -- which can be in loads of forms. Like, it can be in the parameters. It doesn't -- it's not always just stored, like, in your, you know, JSON, in your maybe Redux store, or, like, in your use state hook. So when we're thinking about whether to, like, try and do static generation or server render components, we want to look at basically whether you have static data or dynamic data.
So the common distinction is between, like, server components and client components. People talk about that all the time. And I think that's a really important distinction. So if you have -- this is stuff which is really interactive. And it's really important to keep your interactive client state separate from server state, which is APIs or whatever it is.
And that can be things that are -- these things that are shared between users. Whereas an individual user's, like, clicking history is reactive, right? And that's where, like, like buttons and things like that are very much on the client state side. But I think one of the interesting things to think about when you're trying to make an architectural decision is, are we dealing with static data or dynamic data?
Because dynamic data will change a lot. And it can be incredibly individualized. So server data can be updated often. But if it's shared, then you're going to benefit from things like caching. That can be a solution to the problem of whether or not to use a server component. Because if you can cache it but still share it between users, you don't have to, you know, completely regenerate that request every time.
But if things are very, very dynamic and can only be fetched and rendered at request time, then you're going to do a lot more work by trying to statically generate any of your React app. So this is kind of like one of the biggest risks and I think it's a really useful way of thinking about, yeah, state basically.
Trying to understand what your use case really is and what your fundamental data that you're displaying in your app really is. So looking a little bit at the kind of of next JS and React. Basically, the analogy that I keep thinking about is like when you get like primitives pairing up and they exchange genetic material, you have what's called the chiasma.
And this is a kind of crossover event. And I think we're kind of in a stage now where React and next JS are having a kind of chiasmic crossover event, which, you know, can produce really interesting things. But there's a huge focus now on server rendering and server components. And actually many of the people working on React have moved from meta to next, but they are still working on React itself, which is probably one of the reasons why they're so good at leveraging some of the React features so early.
But the fundamental point is that they're sharing a lot of their kind of genetic material, they are like co-evolving together, which is like just quite an interesting situation. Yeah, a stock exchange was a really good example there. So we don't know what the love child is going to look like exactly. But it's probably going to be sponsored by Vercel because so many features are only available if you use Vercel as your hosting platform whilst you're using Next.
And loads of React 19 features, for example, are only available in Next.js. So I think that's kind of just an interesting point that we should bear in mind about all of this focus on we should be server rendering everything. We should be statically generating everything. We should be thinking about when to serve. And obviously, to kind of reiterate the point I made earlier, if you have static content, if you have a really content heavy website, the classic examples are like blogs.
But even like shops can be very static content heavy unless your listings change every hour, which is unlikely. But also, yeah, shared content. If your content can be shared between users, this can be a really good time to serve things to all of them at the same time, which can then be cached and shared across the users.
So these are good times to serve. But they're also, as I mentioned, some really bad times. So, yeah, like, for example, if you are only showing data to logged in users and the data is specific to them, then that is probably one of the worst times. But to think about the future of React, I suppose, I think we should maybe also be focusing on some of the other things that I'm particularly excited about beyond just the server components.
I think perhaps there's been a little bit too much of an emphasis on server components and some of the other really cool stuff that I'm going to mention briefly, but which I really recommend you learn more about is, for example, the new hooks. And recently, I was hosting an event where someone gave a really good talk about the new hooks, which you can find on YouTube called Dara, who did a great 20 minute talk on it's called hooks old and new.
And the host is called ReactJS girl. So if you want to look that up, I can also post it in there in the thread in a minute. And yeah, she did a really good example of like live coding and basically managed to refactor like quite a lot of what I would call React D boilerplate, which is like, you know, use state, use state, use effect, updating the state using just the use hook.
So in this example here that I've kind of written down fetch stuff is like just an asynchronous call, which returns you some data, right? And instead of using state and use effect to do the asynchronous call and then setting the data in state, you can just use that stuff, you know, like with like const, you know, data equals, which is like, yeah, really exciting.
You can also conditionally use the use hook, unlike all of the other hooks, which is a relief. Because yeah, sometimes you just don't want to call your hook unless some conditions are true. There's also going to be less use memoing because of the new React forget compiler. And I did a talk on this a while ago, but basically the idea is auto memoization so that you don't have to keep using use callback and use memo everywhere in order to have like same reference.
You know, for example, like in your context provider, you always need because because the value is an object, you just always need to memorize the context value. You know, you're very unlikely to have a context provider that just has a string as the value. So, yeah, it's like auto memoization is going to change all of that strange repetitive behavior.
And just, yeah, basically do loads more caching, but caching on your client rather than on the server, for example, with your fetch requests. And I think there's, yeah, loads of great new developer tools. The DX is going to improve hugely. Like to summarize it, I think someone said something really good that I read a blog post a while ago.
It said basically the theme of React 19 seems to be write less code, do more. And I think that's quite a good summary actually. So, yeah, I would focus perhaps, especially if you have very dynamic data, very dynamic routes, very individualized content on perhaps some of the other things that are exciting about React 19. And yeah, consider quite carefully whether or not server components and static generation in particular is the right choice.
I think we can still write lots of really good React code with React 19. It's going to get even better. I'm really excited about the release. And I think, yeah, basically React is definitely not dead. Just, yeah, look at your data quite carefully before deciding to jump on the bandwagon of Next.js or Gatsby in particular as well.
So, yeah, I wanted to leave some time for Q&A. It looks like we have quite a bit. So if any of you have questions, feel free to ask them or put them in the chat now. Yeah, I will find the name of the talk. Basically, the event is called React.js.girls. Directed a talk on... I don't think the video is actually out yet, but keep an eye out for it.
It was really nice. Live. Live, live.
Transcribed automatically; names checked against the speaker record. Select a time to jump there.
Article based on this talk
When does server rendering actually make a React app faster?
Beth Swingler argues that the shape of your data, not the latest framework trend, should decide between static generation, server components and client-side React.
In short
Server rendering and static generation help most when content is static or shared between users, and help least when an app mostly shows dynamic, user-specific data. Beth Swingler, a senior software engineer at YLD, offers a "shades of state" mental model for making that call, and argues that React 19 has plenty to offer beyond server components.
Key takeaways
The technical performance issues with server-side rendering frameworks like Next.js
The hidden costs of server-side rendering
The benefits of doing less work on users' devices or web browsers
Why Next.js became the default
Beth opens with a poll of her audience (who uses React, who uses Next.js, who pays for Vercel) and then, as a philosopher by training, starts with definitions. There are servers and clients, two machines where data can be stored and computation can happen, and every architectural choice is about which one does the work.
She then turns to the trend she wants to question. Meta-frameworks such as Next.js and Gatsby have become the go-to choice for new sites, and for good reason: static generation pre-renders pages at build time, those pages can be cached on edge servers close to users, and server components can fetch and render data in a single request. As she puts it, "So static generation gives you essentially something to look at during the initial load, which is great." (6:20)
That raises her central question: if the benefits are so clear, should everything be statically generated in advance?
The trouble with dynamic content
Beth's answer hinges on one word. "Basically, the key word here is dynamic." (9:20) Dynamic content varies per user or per request, so it cannot be known until the request arrives and cannot be compiled ahead of time.
When a React app hydrates, it assumes the DOM built from the initial HTML matches its own internal model of the page. If the page shows something personal straight away, such as a dashboard of a user's achievements, there will always be a mismatch. Even a small badge with the user's name can flicker because it only appears after the component mounts in the browser. And even without a mismatch, pre-rendered pages still go through a double render during hydration.
The workarounds have their own costs. Beth describes teams checking whether a component, or even the whole application, has mounted and rendering nothing until it has, to stop content flickering. That delays time to interactive and forces a render straight after mount, which she notes is considered poor practice with real performance implications.
The hidden cost of the server-to-client model
Next.js encourages developers to think of code flowing one way, from server to client. When the client needs fresh data, it sends a new request. For data that updates live, that adds up quickly: "And that can actually cost you quite a lot of money as well." (13:15)
This is the part of the talk aimed at the people paying for servers as much as at engineers. Compared with a client-side app, which on initial load renders roughly once (with caveats such as strict mode in development), a heavily dynamic app built on server rendering can end up doing more work in more places.
Shades of state
The mental model is the heart of the talk. "So the conceptual model that I was referring to, which is kind of the main point of my talk, is we should look at the shades of state that we're dealing with." (14:52) By state, Beth means data in all its forms: route parameters, a Redux store, a useState hook, server APIs.
The familiar split between server components and client components matters, and interactive client state, such as a user's clicks or like buttons, should stay separate from server state. But Beth adds a second question: is the data static or dynamic? Server data that changes often but is shared between users can still benefit from caching, so it does not need to be regenerated for every request. Data that is highly individual and can only be fetched at request time is a different story: "But if things are very, very dynamic and can only be fetched and rendered at request time, then you're going to do a lot more work by trying to statically generate any of your React app." (17:36)
Good candidates for static generation include content-heavy sites like blogs, and even shops whose listings rarely change. The worst case is clear: "So, yeah, like, for example, if you are only showing data to logged in users and the data is specific to them, then that is probably one of the worst times." (20:53)
React and Next.js are evolving together
Beth compares the current moment to a genetic crossover event between React and Next.js. Many people working on React have moved from Meta to work on Next.js while still contributing to React, which she suggests helps explain why Next.js adopts new React features so early. She also points out that many features are only available when hosting on Vercel, and that many React 19 features are, for now, only available in Next.js. Her point is not to reject these tools but to keep that commercial context in mind when hearing that everything should be server rendered.
Beyond server components
Beth believes server components have drawn too much attention away from other React 19 changes. She highlights the new use hook, which can replace the familiar pattern of useState plus useEffect for async data and, unlike other hooks, can be called conditionally. She also points to the React Forget compiler's auto-memoization, which should reduce the need for useMemo and useCallback, for example when memoizing context provider values.
She sums up React 19 with a line from a blog post she read: "It said basically the theme of React 19 seems to be write less code, do more." (24:21) Her closing verdict is reassuring for React developers: "And I think, yeah, basically React is definitely not dead." (24:55) The condition is to look carefully at your data before following the crowd to a meta-framework.
Watch the talk
"What Next? The Future of React" by Beth Swingler, 26 minutes: https://www.womentech.net/video/beth-swingler-what-next-future-react
About the speaker
Beth Swingler is a Senior Software Engineer at YLD, a London technology consultancy, and has specialised in React and React Native for over five years. A diversity advocate who shares her insights at events such as ReactJS Girls London, she draws on a background in philosophy, neuroscience and digital communication to explain complex tech concepts to diverse audiences.
Questions this talk answers
Is server-side rendering always faster than client-side React?
Why does pre-rendering dynamic content cause problems?
When is static generation a good choice?
What are the hidden costs of server rendering?
What else in React 19 is worth learning beyond server components?
Drafted with AI from the talk transcript. Editor review pending.
Frameworks and ideas mentioned
Shades of state (static versus dynamic data)
Static site generation
Server-side rendering
React Server Components
Hydration and reconciliation
Resources mentioned
Hooks Old and New, a talk by Dara at ReactJS Girls (on YouTube)
Cite this talk
Beth Swingler. "What Next? The Future of React." WomenTech Network, 2024. https://www.womentech.net/video/beth-swingler-what-next-future-react