React Performance with Server Components

Optimizing Speed and Interactivity with React Components

Optimizing the performance of web applications is crucial for enhancing user experience. React components offer powerful tools to achieve this, particularly when combined with server-side rendering. While server components provide benefits like reduced JavaScript payloads, they can also introduce challenges such as slow initial load times. Addressing these issues requires thoughtful strategies to balance performance metrics.

One effective approach is to implement suspense boundaries. These allow applications to render fallbacks while waiting for server components to load. This strategy unblocks the page, improving navigation speed and interactivity. By streaming components as they complete, users can interact with the application without waiting for all data to load, significantly enhancing the user experience.

Utilizing Parallel Data Fetching

Fetching data in parallel is another technique to optimize application performance. Often, data fetches can be independent of each other. Running them sequentially increases load times unnecessarily. By leveraging asynchronous patterns like Promise.all, applications can initiate multiple data requests simultaneously, reducing the overall waiting time for users.

However, even with parallel fetching, initial load times may remain suboptimal if data is awaited at the layout level. A more effective strategy is to push data fetching to the component level. This approach allows each component to manage its data independently, making them more composable and responsive. By utilizing suspense boundaries around these components, applications can start rendering parts of the UI while other components are still loading.

Improving User Feedback and Navigation

Providing immediate feedback to users during interactions, such as searching or navigating tabs, is essential for a smooth user experience. Implementing a transition mechanism can help achieve this. By marking transitions as non-blocking, developers can show users that an action is pending, such as displaying a loading spinner during data fetches.

This approach also applies to search functionality. By using onChange handlers and state management techniques, developers can ensure that search interactions provide instant feedback. This enhances usability and keeps users informed about the application's state.

Enhancing Components with Progressive Enhancement

Progressive enhancement is a valuable concept in web development. It involves building a base experience that works without JavaScript and then layering additional functionalities when JavaScript is available. This strategy ensures that applications remain functional on devices with limited processing power.

Incorporating client-side components selectively allows developers to add interactive features where needed, without overloading the application with JavaScript. This approach not only maintains a responsive user interface but also ensures that the core functionality is preserved across different environments.

Optimizing Data Fetching and Caching

Efficient data fetching is crucial for reducing load times. Duplication of data requests can hinder performance and lead to unnecessary server load. Implementing caching mechanisms can help avoid repeated requests for the same data.

React's caching API provides a solution by reusing return values of data-fetching functions. By wrapping data-fetching logic in a cache, developers can deduplicate requests during the same render cycle. This not only reduces network overhead but also improves application speed by minimizing redundant operations.

Implementing Optimistic UI Updates

Optimistic UI updates are a powerful way to enhance interactivity. This technique allows applications to update the user interface immediately, anticipating the outcome of a server request. If the request fails, the UI can revert to its previous state.

React's useOptimistic hook facilitates this pattern by creating an optimistic client state. This state is temporary and is replaced by actual data once the server request completes. By using this approach, developers provide a seamless user experience where interactions feel instant and responsive, regardless of network delays.

Final Thoughts on Performance Enhancement

Improving web application performance requires a combination of techniques. By leveraging React components, developers can enhance speed, interactivity, and user experience. Implementing suspense boundaries, optimizing data fetching, and providing immediate user feedback are key strategies in achieving these goals.

Through progressive enhancement and caching, applications become robust and resilient, providing consistent performance across different environments. Optimistic UI updates further contribute to a smooth user experience, ensuring interactions are responsive and engaging. Together, these techniques create a well-rounded approach to building fast, interactive, and user-friendly web applications.

Watch full talk with demos and examples:

Watch video on a separate page
Rate this content
Bookmark

This talk has been presented at React Summit US 2024, check out the latest edition of this React Conference.

FAQ

Aurora uses a progressive enhancement with an on-change handler and React 18 transitions to manage state and enable loading spinners during search.

The initial load is slow because data fetches are intentionally slowed down and server components are rendered on the server before being shown.

The useOptimistic hook allows for instant state updates without network dependency, creating a more interactive experience for users.

Aurora uses suspense to unblock the page and render a fallback, allowing navigation while waiting for server components to stream in.

Aurora focused on improving the first Contentful Paint, largest Contentful Paint, speed index, and maintaining a cumulative layout shift of zero.

Aurora faced challenges because a client component cannot be async, so she had to adjust the handling of promises and server data.

Aurora is speaking remotely at React Summit US about elevating speed, interactivity, and user experience with React components.

Aurora improved scores by incrementally showing content, managing suspense boundaries, and maintaining a low total blocking time with minimal JavaScript.

The app uses Next.js app router, Prisma as the ORM, an Azure SQL database, and Tailwind for CSS.

Aurora is a web developer from Norway who works as a consultant at Enmeta in Oslo.

Aurora Scharff
Aurora Scharff
20 min
22 Nov, 2024

Comments

Sign in or register to post your comment.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Simplifying Server Components
React Advanced 2023React Advanced 2023
27 min
Simplifying Server Components
Top Content
Watch video: Simplifying Server Components
React server components simplify server-side rendering and provide a mental model of components as pure functions. Using React as a library for server components allows for building a basic RSC server and connecting it to an SSR server. RSC responses are serialized virtual DOM that offload code from the client and handle interactivity. The client manifest maps serialized placeholders to real components on the client, enabling dynamic rendering. Server components combine the best of classic web development and progressive enhancement, offering the advantage of moving logic from the client to the server.
A Guide to React Rendering Behavior
React Advanced 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
Routing in React 18 and Beyond
React Summit 2022React Summit 2022
20 min
Routing in React 18 and Beyond
Top Content
Routing in React 18 brings a native app-like user experience and allows applications to transition between different environments. React Router and Next.js have different approaches to routing, with React Router using component-based routing and Next.js using file system-based routing. React server components provide the primitives to address the disadvantages of multipage applications while maintaining the same user experience. Improving navigation and routing in React involves including loading UI, pre-rendering parts of the screen, and using server components for more performant experiences. Next.js and Remix are moving towards a converging solution by combining component-based routing with file system routing.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
Exploring React Server Component Fundamentals
React Day Berlin 2023React Day Berlin 2023
21 min
Exploring React Server Component Fundamentals
Top Content
Watch video: Exploring React Server Component Fundamentals
This Talk introduces React Server Components (RSC) and explores their serialization process. It compares RSC to traditional server-side rendering (SSR) and explains how RSC handles promises and integrates client components. The Talk also discusses the RSC manifest and deserialization process. The speaker then introduces the Waku framework, which supports bundling, server, routing, and SSR. The future plans for Waku include integration with client state management libraries.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
AI for React Developers
React Advanced 2024React Advanced 2024
142 min
AI for React Developers
Featured Workshop
Eve Porcello
Eve Porcello
Knowledge of AI tooling is critical for future-proofing the careers of React developers, and the Vercel suite of AI tools is an approachable on-ramp. In this course, we’ll take a closer look at the Vercel AI SDK and how this can help React developers build streaming interfaces with JavaScript and Next.js. We’ll also incorporate additional 3rd party APIs to build and deploy a music visualization app.
Topics:- Creating a React Project with Next.js- Choosing a LLM- Customizing Streaming Interfaces- Building Routes- Creating and Generating Components - Using Hooks (useChat, useCompletion, useActions, etc)
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Tracing: Frontend Issues With Backend Solutions
React Summit US 2024React Summit US 2024
112 min
Tracing: Frontend Issues With Backend Solutions
Featured WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
Frontend issues that affect your users are often triggered by backend problems. In this workshop, you’ll learn how to identify issues causing slow web pages and poor Core Web Vitals using tracing.
Then, try it for yourself by setting up Sentry in a ready-made Next.js project to discover performance issues including slow database queries in an interactive pair-programming session.
You’ll leave the workshop being able to:- Find backend issues that might be slowing down your frontend apps- Setup tracing with Sentry in a Next.js project- Debug and fix poor performance issues using tracing
This will be a live 2-hour event where you’ll have the opportunity to code along with us and ask us questions.
Mastering React Server Components and Server Actions in React 19
React Summit US 2024React Summit US 2024
150 min
Mastering React Server Components and Server Actions in React 19
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Calling all React developers! Join us for an immersive 4-hour workshop diving deep into React Server Components and Server Actions. Discover how these game-changing technologies are revolutionizing web development and learn how to harness their full potential to build lightning-fast, efficient applications.

Explore the world of React Server Components, seamlessly blending server-side rendering with client-side interactivity for unmatched performance and user experience. Dive into React Server Actions to see how they combine client-side interactivity with server-side logic, making it easier to develop interactive applications without traditional API constraints.

Get hands-on experience with practical exercises, real-world examples, and expert guidance on implementing these technologies into your projects. Learn essential topics such as the differences between Server and Client Components, optimizing data fetching, passing data effectively, and maximizing performance with new React hooks like useActionState, useFormStatus and useOptimistic.

Whether you're new to React or a seasoned pro, this workshop will equip you with the knowledge and tools to elevate your web development skills. Stay ahead of the curve and master the cutting-edge technology of React 19. Don't miss out - sign up now and unleash the full power of React!
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.