Read-your-own-writes
What you need to know
Read-your-own-writes is a consistency requirement: after a successful edit, the editing user should be able to read the committed revision. Refreshing a view is different from invalidating the data that supplies it.
By the end, you can: commit mutation then invalidate; compare server refresh and invalidation.
Express post-commit ordering in a testable helper
async function saveThenExpire(commit: () => Promise<number>, expire: () => void) { const revision = await commit(); expire(); return revision;}Expected behavior: The expiration callback runs only after commit resolves. If expiration throws, the caller must distinguish committed-but-not-refreshed from an unsuccessful write.
How it works
A robust mutation first authenticates, checks permission and validates the expected revision. Commit the source-of-truth change, then expire the affected public tags when the editor needs immediate confirmation. If the write fails, do not invalidate or display a success. If the write commits but invalidation fails, report the partial outcome truthfully and arrange a bounded retry or durable invalidation event; do not retry the entire non-idempotent write blindly. updateTag handles the cache expiration step in a Server Action. refresh from next/cache refreshes the client router from a Server Action; router.refresh from next/navigation requests a fresh rendering of the current route from a Client Component. Neither is a general server data cache purge. A cached query can still return the same data after a render refresh. A lagging database replica can also violate the requirement even after a cache miss; route immediate verification to an appropriately consistent source.
Refresh current client view without claiming a purge
'use client';import { useRouter } from 'next/navigation';export function RefreshButton() { const router = useRouter(); return <button type="button" onClick={() => router.refresh()}>Refresh view</button>;}Expected behavior: The router asks for the current route again. Server data caches may still supply the same result.
Common mistake
Invalidating before commit can allow a concurrent reader to repopulate the old value. Calling router.refresh after a write is not a substitute for invalidating a stale server data dependency.
Practice and verification
Test success, failed commit and successful commit with failed expiration in the independent model. Then stage a Server Action integration test with two browser contexts and a primary data read. Explain the difference between freshness and durability.
Scope: App Router, proposed Next.js 16.x and React 19, Cache Components enabled in a separate fixture. Framework snippets are staged and not executed; local pure models are not framework evidence. Exact patched dependencies and platform contracts are pending.
Further reading: Update Tag · Refresh · Router · Mutating