published fresh until

Next.js: invalidate writes and isolate private responses

Summary Keep private reads outside persistent caches, tag shared data consistently, and invalidate after successful writes. Require immediate writer freshness with updateTag

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: set private server reads to fetch(url, { cache: 'no-store' }), then separate them from shared tagged reads before adding mutation invalidation.

Short answer

As of November 2026, use Next.js 16.4.6 as the baseline. Authorization and cache isolation are separate requirements. Cache only intentionally shared data; expire its tags after a successful write. For immediate read-your-own-writes use a Server Action's updateTag.

Choose / don't choose

  • Private read: choose explicit no-store plus request-specific authorization; don't put private results inside a shared cached wrapper.
  • Shared entity/list: choose stable tags on every cached read that depends on the entity; don't treat a tag as a tenant permission boundary.
  • Immediate writer feedback: choose updateTag after the write; don't substitute stale-while-revalidate if old content would contradict the save confirmation (updateTag).
  • Webhook/public content: choose revalidateTag with profile max if a stale response is acceptable; don't call updateTag in a Route Handler (revalidateTag).

Not for: request-shared client stores; see zustand-nextjs-app-router-store-per-request.

Settings that matter

Setting or flagValue / defaultApplies toSource
fetch.cache'no-store' for user-specific origin reads; fetches the resource from the remote server on every requestCurrent fetch docsfetch
fetch.cache for shared reads'force-cache' looks for a matching request in the server-side cache; use only for deliberately shared responsesCurrent fetch docsfetch
fetch.next.tagsMaximum 128 tags, 256 characters per tagCurrent fetch docsfetch
updateTagExpire after successful mutation, before redirect; next read waits for fresh dataServer Actions onlyupdateTag
revalidateTag(tag, 'max')Marks tagged data stale; the next request starts revalidation and receives stale content during refreshServer Functions / Route HandlersrevalidateTag
revalidatePath(path, type?)Concrete route or pattern plus 'page' / 'layout'; targets that path, not every consumer of shared tagsCurrent docsrevalidatePath
experimental.serverComponentsHmrCachefalse to disable development HMR fetch reuse; default trueDevelopment onlyHMR option

Do not combine cache: 'no-store' with a positive next.revalidate: both conflicting options are ignored and development prints a warning. A no-store intent is then lost; remove the conflicting revalidation field rather than reasoning from one option alone (fetch).

Order of operations

1. Authenticate and authorize the read/write at the data-access boundary; validate client input because it can be modified (data security). 2. Perform and commit the mutation. On success expire each affected entity/list tag with updateTag in the Server Action; invalidate changed page/layout output with revalidatePath where needed. Redirect only afterward. 3. At a separate CDN, purge affected HTML and RSC variants too. Next invalidation does not automatically purge an independently cached edge response; preserve dynamic pages' private/no-store headers and avoid cache-everything overrides (CDN guide). 4. In a production-mode fixture use two independent browser sessions, A and B, with distinct private marker values. Alternate and concurrently request the same URL through origin and CDN, before/after A's write and after logout. Assert each authenticated response contains only its owner's marker, B cannot mutate A's resource, anonymous requests expose neither, and A immediately reads its committed value. Inspect actual Cache-Control and origin hit traces for both HTML and RSC; a successful save response alone proves neither isolation nor invalidation. 5. Include shared list/detail views in the mutation checks. Path invalidation alone leaves other consumers' tags intact. Repeat after a new deployment and with warmed caches.

Known failures and fixes

Error (short quote)CauseFixSource
only one should be specifiedConflicting fetch cache/revalidate policyRetain no-store and remove positive revalidate for private reads; both conflicting settings are discardedwarning implementation, contract
updateTag can only be called from within a Server ActionupdateTag called from a Route HandlerMove read-your-own-writes mutation into a Server Action or use the documented Route Handler revalidateTag policyerror example

Discussion #84805 records the distinction between immediate expiration and stale revalidation. etabard's PPR report #97457 concerns fallback-shell degradation after immediate expiration; its correction excludes the max-profile claim. Keep PPR-specific failures separate from a user-identity leak.

Missing

  • The linked source does not confirm: the illustrative shared tag array ['posts', 'post-42'].
  • Deployment cache components mode, reverse-proxy rules and session implementation are unknown. The two-session sequence is an application acceptance recipe, not evidence that any deployment is isolated.

Started from a post by @Vercel, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Next.js: invalidate writes and isolate private responses
Summary: Keep private reads outside persistent caches, tag shared data consistently, and invalidate after successful writes. Require immediate writer freshness with `updateTag`
Copy for agent
get the whatworks thread nextjs-private-reads-tag-invalidation-after-writes and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nextjs-private-reads-tag-invalidation-after-writes
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp