{"success":true,"name":"revalidate-after-every-next-js-server-action-mutation","description":"A Next.js form saves data but pages keep showing old values","category":"ai-brimind","path":"ai-brimind/revalidate-after-every-next-js-server-action-mutation/SKILL.md","file":"SKILL.md","content":"---\nname: revalidate-after-every-next-js-server-action-mutation\ndescription: \"A Next.js form saves data but pages keep showing old values\"\n---\n\n# Revalidate After Every Next.js Server Action Mutation\n\n## When to use\nProject is Next.js App Router, and a Server Action (or handler) writes data, and lists or pages still show the pre-write state.\n\n## Example request\naction saves the post but the list page shows the old list → the cached route was never told; add revalidatePath('/posts') after the write. — Invalidate what you changed. | same data appears on home, list, and detail pages → tag the fetches and call revalidateTag once instead of listing every path. — Tags group related data. | router.refresh() sprinkled in the client to force updates → patching the symptom in the browser; the server cache is the thing that is stale. — Client refresh hides the cause. | update shows only after a full rebuild → the route was fully static with no revalidation at all. — Static route with no invalidation plan.\n\n## Instructions\nAct like a bookkeeper who never records a transaction without updating every ledger that mentions it. For every Server Action or handler that writes data in Next.js: 1) Before writing the mutation, list which pages and fetches DISPLAY the data being changed — that list is your invalidation checklist. 2) After the successful write, invalidate precisely: revalidatePath for a specific route, or better, put tags on the fetches (next: { tags: ['posts'] }) and call revalidateTag so every page using that data updates at once, wherever it lives. 3) Recognize the anti-patterns: router.refresh() calls scattered in components, timestamp query params, or turning routes force-dynamic — all of these hide the real issue, which is a write that never told the cache. 4) Pair the action with the built-in flow: redirect after create, revalidate then let the Server Component re-render — no hand-rolled client cache syncing. 5) If data still looks stale after invalidating, identify which cache layer is serving it (data cache vs client Router Cache) before adding more calls blindly. Only consider the mutation done when every displaying surface is on the invalidation list, and explain why each revalidate call covers which page — not just that one screen updated once in testing.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #501\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}