Part 11 / Topic 5 of 6
updateTag — the Server-Action-only, no-stale-window sibling
updateTag does what section 4's { expire: 0 } does, but it's restricted to Server Actions, and it buys something revalidateTag never does on its own: the action's own response carries the freshly re-rendered page, in the same round trip — no second request needed to see the change. This course's actual proof of that lives in swiggy-menu/reviews/actions.ts (built as part of this harness's running example, exercised fully in Part 12):
// harness/app/swiggy-menu/reviews/actions.ts (the relevant two lines)
addReviewRecord({ name, rating, comment });
updateTag("swiggy-reviews"); // read-your-own-writes - see below
redirect("/swiggy-menu/reviews?posted=1");
Posting a review for real (a direct POST carrying the exact progressive-enhancement fields this form's own server-rendered HTML emits — the full mechanics of why a plain POST can invoke a Server Action with no JavaScript at all are Part 12's subject) and reading the response headers:
$ curl -s -D - -o /dev/null -X POST http://localhost:PORT/swiggy-menu/reviews -F ... (name=Rahul, rating=5, comment=...)
HTTP/1.1 303 See Other
Location: /swiggy-menu/reviews?posted=1
x-action-revalidated: 1
x-action-revalidated: 1 is this install's own confirmation, read directly from a real response header, of the mechanism the installed server-actions.md guide describes: "When a Server Action triggers an immediate revalidation, Next.js does the work inside one HTTP request: it runs the action, then re-renders the current route server-side... Your application code does not need a follow-up fetch to see the updated UI." Following the redirect shows Rahul's review already present — on the very first subsequent load, with no stale window to wait out, because updateTag (unlike revalidateTag("swiggy-reviews", "max")) never serves a stale copy in between.
💡 Why this isn't
revalidateTaginstead: the installedserver-actions.mdguide states the choice directly: "updateTag: immediate expiration of a tag. The next read... waits for fresh data... Use when the action needs read-your-own-writes...revalidateTag: stale-while-revalidate refresh... the action's own re-render does not wait for the new data." A reviewer posting their own review is exactly the read-your-own-writes case — they must see it land, not a stale pre-review snapshot.
Full files: examples/03-updateTag-review-action.ts (snapshot of the relevant lines; the complete Server Action, form, and validation flow is Part 12's own build).
Done here? The practice set for Part 11 — including the solutions — is on the part page.