Why every click felt slow: the Next.js client router cache
Our CRM pages are client components that load their data through React Query. Since Next 15 the client router cache for dynamic pages defaults to zero seconds (it was 30 in Next 14), so every sidebar click asked the server for the page again, through the middleware proxy, before showing anything. The page had no server-rendered data to wait for, so that round trip bought us nothing.
The fix is a few lines in the Next config. Next documents `staleTimes` as experimental and subject to change, so treat it as a setting to re-check on every Next upgrade. It only skips the page-shell round trip. Data freshness is handled one layer down by React Query, so a 30-second router cache does not mean 30-second-old figures.
// next.config.js
experimental: {
// Reuse a visited dynamic route for 30s instead of
// asking the server for it again on every click.
staleTimes: { dynamic: 30 },
},React Query defaults for a screen that feels live but is not expensive
The client cache defaults sit in one provider, and the comment above them states the aim: freshness first, with minimal extra load.
Each option earns its place. A short stale time means returning to a screen re-validates it only if its data is older than 30 seconds. Refetching on focus and on reconnect covers most of what people mean by live, at the price of requests only for stale queries. `keepPreviousData` means a filter change or a refetch never blanks the table, which matters more for perceived speed than the request time does. We moved the stale time from five minutes down to 30 seconds. That trades a few more requests for fewer moments of wondering whether a screen is out of date, and screens that need more add a polling interval on top.
new QueryClient({
defaultOptions: {
queries: {
staleTime: 30_000, // was 5 minutes
gcTime: 10 * 60 * 1000, // keep unused cache for 10 minutes
refetchOnWindowFocus: true,
refetchOnReconnect: true,
retry: 1,
placeholderData: keepPreviousData, // old data stays until new arrives
},
},
});Loading skeletons that show the page's shape and do not flash
Each major section has a `loading.tsx` that renders a skeleton shaped like the page, inside the existing shell, so the sidebar and header stay where they are. It replaced a single spinner in the middle of an empty area, which gives no hint of what is coming.
A skeleton that flashes up and vanishes is worse than none. So the fallback is held back: it fades in 250 ms after the route change, and a load that finishes sooner never shows one. When someone clicks a link, the old page fades out for 140 ms while the next route is prefetched, so the click feels acknowledged without the destination arriving blank.
The page transition is deliberately small. The entrance animation runs once, on the elements present when the route commits, so a skeleton being replaced by real data does not restart it.
Route prefetching in the Next.js App Router
Sidebar entries are Next `Link` components and we leave prefetching at its default. Per the Next.js prefetching documentation, prefetching runs in production, and for a dynamic route the default prefetch covers the shared layout down to the nearest `loading.tsx` boundary. That is another reason each section has one: the skeleton can render the instant a link is clicked.
Where we animate the old page out before navigating, we call `router.prefetch(href)` ourselves at click time, so the next route is already on its way during the 140 ms fade. A modifier-click, a link to the page you are already on and users who prefer reduced motion all fall through to Next's normal behaviour.
Splitting the bundle by route and by interaction with next/dynamic
Most dashboard route files are thin wrappers that load the real page with `next/dynamic`, using the same skeleton as the loading state.
`ssr: false` is a trade-off. The CRM sits behind a login, so server-rendered HTML for these pages has no search value, and our reasoning is that the user is better served by the skeleton at once and the page when its chunk arrives. For a public, indexable page we would not do this.
Splitting also happens inside pages. The create-task modal on a contact page loads only when Add task is pressed, and the navigation badge imports its service modules inside its polling callback, so they stay out of the shell's first load.
const LeadsPage = dynamic(
() => import("@/components/leads/LeadsPage")
.then((m) => ({ default: m.LeadsPage })),
{ loading: () => <TablePageSkeleton />, ssr: false }
);The cost of code splitting: stale tabs after a deploy
Splitting has a price that shows up after a release. A tab opened before a deploy still holds the old build's chunk names, so the next lazy import in it can fail. We handle that in two layers.
Each build carries an id, and a small watcher checks the server's current id every five minutes and whenever the tab regains focus. When the ids differ it shows a reload prompt, and the next navigation to a different page reloads onto the new build, which is a natural moment because nothing is half-typed on the page being left. Separately, a chunk load error or a failed static asset triggers a reload, at most once a minute, so an asset that is genuinely broken cannot put a tab into a reload loop.
Avoiding request waterfalls in client components
A waterfall is a request that waits for another it does not depend on. Because our pages are client components, the easy mistake is a chain of effects, each starting its fetch only after the last has rendered. We avoid it in two ways:
- Independent requests start together. The navigation badge needs three endpoints, so it issues them in parallel with `Promise.allSettled` and combines whatever succeeds.
- Shared data is fetched once. The profile request is shared by the header, the walkthrough and the page, and the caller's permissions use one cached query key with a five-minute stale time, so many components asking the same question make one request.
Where this fits in Propily
We have not published Core Web Vitals figures for the app, so none are quoted here. These changes are aimed at how navigation feels, and the honest way to judge them is to click through a real screen on a real connection.
This is the front end of Propily, the CRM we build for UK estate and letting agencies, where an agent moves between leads, viewings, deals and the inbox all day. The real estate CRM page covers what the product does, and a demo is the quickest way to judge how it feels.
Questions people ask
What does staleTimes do in Next.js?
It sets how long the client-side router cache keeps a visited page before asking the server again. Since Next 15 the default for dynamic pages is zero, so we set `dynamic: 30` to reuse a route for 30 seconds. Next documents the option as experimental, so re-check it when you upgrade.
How do I stop loading skeletons flashing?
Delay the fallback. We fade ours in after 250 ms, so a load that finishes sooner never shows one, and we render a skeleton shaped like the page rather than a spinner.
Does ssr: false hurt a Next.js app?
It removes server-rendered HTML for that component, which matters for public, indexable pages and not for a signed-in app. It also splits the component into its own chunk. Use it page by page, not as a default.
How do I make a Next.js dashboard feel faster without changing the backend?
Reuse client caches (the router cache and a short React Query stale time), keep old data on screen with keepPreviousData, show page-shaped skeletons after a short delay, split heavy pages, and start independent requests in parallel.