Skip to content

docs: explain the swr cache option on GET actions; README omits cached GET reads #1148

Description

@vivek7405

Problem

The swr option of the export const cache config on GET server actions (#488) is never explained on any doc surface. Every occurrence is the same inline code comment, { maxAge, swr, public }, with no prose saying what swr does, what unit it takes, or when to use it. A developer who wants proper Cache-Control on a GET action can learn maxAge and the public safety rule from the docs, but has to read framework source to learn swr.

Separately, the README feature list undersells cached GET actions: it says "cache() for queries, HTTP Cache-Control for pages" but never mentions that GET server actions carry Cache-Control + ETag, which is a headline differentiator versus Next.js (whose actions are POST-only).

Design / approach

Document what the implementation actually does. Source of truth is cacheControlFor() in packages/server/src/action-config.js (L143-149): on a GET action with a cache config, the response header is <private|public>, max-age=<maxAge>, and when swr > 0 it appends , stale-while-revalidate=<swr>. So swr is seconds, and it lets the browser serve the stale cached response instantly after maxAge expires while revalidating in the background (pairs with the weak ETag, so the revalidation is usually a 304).

Add one or two sentences of swr prose next to each existing export const cache example, and one clause to the README feature list. No behaviour change, docs only.

Implementation notes (for the implementing agent)

Where to edit (each already shows the { maxAge, swr, public } comment; add the swr explanation adjacent):

  • website/app/docs/server-actions/page.ts L170 (example) and the caching paragraph at L177.
  • website/app/docs/data-fetching/page.ts L77 (example) and the behaviour paragraph at L84.
  • AGENTS.md L308, the **HTTP-verb actions via config exports (#488)** paragraph: extend the export const cache = 60 parenthetical with a short swr clause. Keep it lean; the full prose belongs in the skill reference.
  • .agents/skills/webjs/references/data-and-actions.md L129 (example) and the GET bullet near L142.
  • README.md L26: extend "cache() for queries, HTTP Cache-Control for pages" to also name cached GET server actions (Cache-Control + ETag on action reads).

Landmines / gotchas:

  • The scaffold templates ship their own copy of the skill reference at packages/cli/templates/.agents/skills/webjs/references/data-and-actions.md. If it carries the same { maxAge, swr, public } line, update it in lockstep with the repo-root copy (grep both).
  • Prose invariant release: bump core/server/cli versions, honest engines fields #11 (AGENTS.md): no em-dashes, no space-surrounded hyphens or semicolons as pause punctuation, and WebJs capitalized in prose. The .claude/hooks/block-prose-punctuation.sh hook blocks violations in NEW content.
  • llms.txt / llms-full.txt are generated live from the doc pages; do not hand-edit them.
  • The docs pages are .ts files rendering html templates: no backticks inside html template bodies (invariant feat(server): replace esbuild TS stripping with Node 24+ strip-types #9), and the pages are display-only so keep them free of client-side signals.
  • README.md L26 sits inside a sentence that continues onto the following lines (the setStore() clause); keep that sentence grammatical after the edit.

Invariants to respect: docs must describe cacheControlFor() truthfully (private default, swr appended only when > 0, GET only). Do not restate the public: true safety rule incorrectly; copy its existing framing.

Tests + docs surfaces: docs-only change, no test layer applies. Run webjs check for the touched doc pages under website/. All edited surfaces listed above ARE the doc-sync set for this change (verified via the webjs-doc-sync audit that produced this issue).

Acceptance criteria

  • Each surface above explains swr in prose: seconds, emits stale-while-revalidate=<n> in Cache-Control, serve-stale-then-revalidate semantics.
  • README names cached GET server actions in the feature list.
  • The scaffold template copy of the skill reference is in sync with the repo-root copy (or verified to not need it).
  • git grep -iE 'stale.while.revalidate' now hits prose (not just header examples) on the server-actions and data-fetching doc pages.
  • webjs check passes; prose-punctuation hook not violated.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions