Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why Next.js Navigation Feels Slow Even When the Server Is Fast

I used Next.js for a while before I could explain why clicking a link sometimes did nothing for a moment. The server was not doing anything especially expensive. The browser already had plenty of JavaScript. Yet the next screen still waited for a network round trip. The missing piece was the React Server Component payload for the destination route. Understanding when Next.js fetches that payload,…

When clicking a link in a Next.js application, the navigation can sometimes feel slow, even if the server is fast. The issue lies in the browser's handling of React Server Component (RSC) payloads. RSC payloads are serialized representations of the component tree sent from the server to the browser, but they do not simply contain HTML or the source code of the Server Components.

In a client-rendered application, the browser can render a destination screen immediately after receiving JavaScript, even if the data is still loading. However, with RSC, the browser receives the rendered output through the RSC payload, along with references to Client Components and the props needed by those components. This payload is not HTML or source code.

The navigation delay occurs when the browser waits for the required payload to arrive before navigating to the next screen. The prefetching process can mitigate this delay, but its effectiveness depends on the route type. For statically rendered routes, the full route can be prefetched, while for dynamically rendered routes, prefetching happens only down to the nearest loading.js boundary.

Partial Prefetching, available in Next.js 16.3 and later, changes the prefetching strategy. It focuses on the shared App Shell and requests reusable route content when the user clicks. This approach can reduce the wait after a click but also requires more server work beforehand.

Dynamic segments, such as posts/[slug], do not always mean request-time rendering. GenerateStaticParams can provide values for prerendering, and dynamic rendering occurs only when request-specific values like cookies() or headers() are used. In these cases, the route may no longer have a completely static response that can serve every request.

Understanding how Next.js fetches RSC payloads and which parts it can reuse is crucial to explaining and fixing the perceived navigation delay. Techniques like cacheComponents, partialPrefetching, and prefetching can help optimize navigation performance in Next.js applications.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 10 November →