Next.js revalidatePath('/', 'layout') expires every page on the site
In Next.js, revalidatePath('/', 'layout') does not mean "refresh the homepage". It invalidates the root layout, and every route on the site sits under the root layout, so every cached page becomes stale in one call. If a CMS webhook passes the root path through with a default type of 'layout', each homepage edit forces the whole site to re-render on the next visits. Map / to 'page' and let shared chrome such as menus and footers refresh through their own cache tags.
Where the root path came from
The site is a decoupled Drupal back end with a Next.js 16 front end on the App Router. When an editor saves content, Drupal calls a revalidation route handler on the front end with a path and an optional type. The handler did the obvious thing:
if (type === "page") {
revalidatePath(path, "page");
} else {
revalidatePath(path, "layout");
}
Defaulting to 'layout' is reasonable for most paths. A section landing page at /services often has child pages that show its title or list its children, so expiring the whole /services subtree is a fair trade. The trouble is the one path where the subtree is the entire site.
Why the root layout reaches every route
The revalidatePath docs say it plainly: revalidatePath('/', 'layout') revalidates all data. Under the hood, Next.js gives each cached route implicit tags for the path segments above it, one per layout from the root down, plus one for the page itself. revalidatePath(path, 'layout') invalidates the layout tag for that path, and with it everything that carries it. Every route carries the root layout's tag, so revalidating / as a layout reaches all of them.
Nothing is rebuilt at the moment you call it. Entries are marked stale and regenerated as visitors arrive. On a small site that's invisible. On a large one with a decoupled back end, every page's first visit afterwards renders from scratch, and each render asks the CMS to resolve the path and fetch the content. The Drupal side of the same project was under heavy load at the time, with a flood of path-resolution requests from the decoupled router, and a site-wide expiry is precisely the pattern that produces them. I can't say it was the only cause, so treat this as a risk to remove, not a post-mortem.
What actually needs to change when the homepage changes
When an editor edits the homepage, the homepage needs rebuilding. The question is whether anything else does. The header, footer, menus and sidebars on this site are fetched through cached functions with their own tags: one for global settings, and one for each menu. When a menu changes, Drupal revalidates those tags, and every page using that menu picks up the change. So the root layout doesn't have to be revalidated to keep shared chrome fresh. Tags already cover it.
That makes the fix small: never send 'layout' for the root.
// lib/revalidate-scope.ts
export function revalidateScope(
path: string,
type: string | null,
): "page" | "layout" {
return type === "page" || path === "/" ? "page" : "layout";
}
// app/api/revalidate/route.ts
import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server";
import { revalidateScope } from "@/lib/revalidate-scope";
export async function GET(request: NextRequest) {
const path = request.nextUrl.searchParams.get("path");
const type = request.nextUrl.searchParams.get("type");
if (path) {
revalidatePath(path, revalidateScope(path, type));
}
return NextResponse.json({ revalidated: Boolean(path) });
}
A secret check and any CDN purge belong in that handler too. I've left them out to keep the example to the point.
Testing the rule rather than the framework
Pulling the decision into a pure function makes it cheap to pin with a unit test, without starting Next.js:
import { describe, expect, it } from "vitest";
import { revalidateScope } from "../revalidate-scope";
describe("revalidateScope", () => {
it("never revalidates the root as a layout", () => {
expect(revalidateScope("/", "layout")).toBe("page");
expect(revalidateScope("/", null)).toBe("page");
});
it("keeps a layout revalidation below the root", () => {
expect(revalidateScope("/services", "layout")).toBe("layout");
expect(revalidateScope("/services", null)).toBe("layout");
});
});
The second case matters as much as the first. The aim is to remove one dangerous input, not to quietly narrow every revalidation to a single page and leave child pages stale.
When a site-wide revalidation is the right call
Sometimes you do want everything fresh: a site-wide banner baked into the root layout, a change to a global setting that isn't behind a tag, or a deploy-time reset. Make that a deliberate action instead of a side effect of saving the homepage. A separate, authenticated endpoint or an admin-only button is enough. You can then run it in a quiet period, and you know the back end will see a burst of renders when you do.
If your shared chrome isn't behind tags yet, that's the change to make first. Wrap the menu and settings fetches in cached functions, tag them, and have the CMS revalidate those tags when they change. Until then, narrowing the root to 'page' means a menu edit won't show until something else expires the pages that use it.
Key takeaways
revalidatePath('/', 'layout')marks every route on a Next.js site stale, because every route sits under the root layout.- A webhook that defaults the revalidation type to
'layout'needs a special case for/, or a homepage edit becomes a site-wide cache flush. - Keep headers, footers and menus behind their own cache tags, so the root path only needs its page rebuilt.
- After a site-wide expiry, each page's first visit renders from scratch, and on a decoupled CMS that means a burst of back-end requests.
- Put the path-to-scope rule in a small pure function, so a unit test can pin both the root case and the subtree case.