# payload-revalidate — Agent usage Configure a coding agent for @nexload-sdk/payload-revalidate. **Topic:** agents **Package:** `@nexload-sdk/payload-revalidate` v1.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/payload-revalidate/agents/ ## Install matching skills Install the skills whose triggers match the task. ### payload-revalidate [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/payload-revalidate/SKILL.md) ```text Use when wiring, reviewing, or testing Payload CMS to Next.js cache revalidation with @nexload-sdk/payload-revalidate, configuring createRevalidator, composing hooks() or globalHooks(), designing tag/path rules, handling bulk skipRevalidate + send() jobs, or mounting createRevalidateHandler. Decides signed vs allowUnsigned receiver security, locale-scoped tags, custom isPublic predicates, flush() boundaries, and createTestRevalidator setup. Do not use for top-level Payload preset or collection audit logging (use payload-preset or payload-hooks/auditPlugin), general logging (use logger), Persian normalization/search keys (use persian), or standalone Next.js ISR without Payload. ``` ```bash npx skills add gecut/nexload-sdk --skill payload-revalidate ``` ## Project AGENTS.md ```markdown For @nexload-sdk/payload-revalidate, load payload-revalidate when its trigger matches. Read the package bundle and check public exports against the installed version before editing. ``` ## Package context [Scoped Markdown bundle](/nexload-sdk/packages/payload-revalidate/llms.txt). ## Prompts ```text Wire @nexload-sdk/payload-revalidate for my products collection and Next.js /api/revalidate route using payload-revalidate. Inspect the installed version and show a minimal typed example. ``` ```text Review my @nexload-sdk/payload-revalidate integration against the optimization page. Identify the relevant source for each finding and one test using createTestRevalidator. ``` --- # API Reference & Compatibility Public exports, wire format, logging events, and runtime constraints. **Topic:** api **Package:** `@nexload-sdk/payload-revalidate` v1.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/payload-revalidate/api/ The inventory is generated from the package source exports across `.`, `./next`, and `./testing`. ## Functions ### `createRevalidateHandler` ```ts createRevalidateHandler(options: ReceiverOptions) => (request: Request) => Promise ``` **Exported from:** `@nexload-sdk/payload-revalidate/next` Creates a Next.js App Router POST handler that verifies and applies cache revalidation requests. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/next/index.ts#L12) ### `createRevalidator` ```ts createRevalidator(options: RevalidatorOptions) => Revalidator ``` **Exported from:** `@nexload-sdk/payload-revalidate` Creates a Payload revalidator that normalizes, chunks, and POSTs cache invalidations. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/revalidator.ts#L513) ### `createTestRevalidator` ```ts createTestRevalidator(options?: Partial) => { revalidator: Revalidator; calls: WireBatch[]; clear(): void; } ``` **Exported from:** `@nexload-sdk/payload-revalidate/testing` Creates an in-memory test revalidator that records dispatched batches. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/testing.ts#L13) ### `signRevalidateRequest` ```ts signRevalidateRequest(input: { body: string; secret: string; timestamp?: number; }) => { timestamp: string; signature: string; } ``` **Exported from:** `@nexload-sdk/payload-revalidate` Signs a revalidation request body with an HMAC-SHA256 base64url signature. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L22) ### `verifyRevalidateRequest` ```ts verifyRevalidateRequest(input: { body: string; timestamp: string | null; signature: string | null; secret: string | readonly string[]; now?: number; }) => boolean ``` **Exported from:** `@nexload-sdk/payload-revalidate` Verifies a revalidation request signature and timestamp window using timing-safe comparison. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L39) ## Constants ### `MAX_BODY_BYTES` ```ts MAX_BODY_BYTES: 8192 ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L7) ### `MAX_TARGETS` ```ts MAX_TARGETS: 50 ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L6) ### `REVALIDATE_ENDPOINT` ```ts REVALIDATE_ENDPOINT: "/api/revalidate" ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L5) ### `SIGNATURE_HEADER` ```ts SIGNATURE_HEADER: "x-revalidate-signature" ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L10) ### `TIMESTAMP_HEADER` ```ts TIMESTAMP_HEADER: "x-revalidate-timestamp" ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L9) ### `TIMESTAMP_WINDOW_SECONDS` ```ts TIMESTAMP_WINDOW_SECONDS: 60 ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public constant exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/wire.ts#L8) ## Types ### `Ctx` ```ts type Ctx = { doc: D; previousDoc?: D; locale: TypedLocale | null; locales: TypedLocale[]; operation: "create" | "update" | "delete"; req: PayloadRequest; }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L23) ### `PathTarget` ```ts type PathTarget = string | { path: string; type?: "layout" | "page" }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L15) ### `ReceiverOptions` ```ts type ReceiverOptions = ( | { secret: string | readonly string[]; allowUnsigned?: never } | { allowUnsigned: true; secret?: never } ) & { logger?: Logger }; ``` **Exported from:** `@nexload-sdk/payload-revalidate/next` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/next/handler.ts#L15) ### `Revalidator` ```ts type Revalidator = { hooks( slug: S, rules: Rules>, ): { afterChange: CollectionAfterChangeHook[]; afterDelete: CollectionAfterDeleteHook[]; }; globalHooks( slug: S, rules: Rules>, ): { afterChange: GlobalAfterChangeHook[]; }; send(targets: Targets): Promise; flush(): Promise; }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L56) ### `RevalidatorOptions` ```ts type RevalidatorOptions = { url: string | undefined; secret?: string; enabled?: boolean; logger?: Logger; endpoint?: string; timeoutMs?: number; retries?: number; }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L38) ### `Rules` ```ts type Rules = { tags?: string[] | ((ctx: Ctx) => string[]); paths?: PathTarget[] | ((ctx: Ctx) => PathTarget[]); isPublic?: (doc: D) => boolean; }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L32) ### `Targets` ```ts type Targets = { tags?: string[]; paths?: PathTarget[] }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L19) ### `WireBatch` ```ts type WireBatch = { tags: string[]; paths: WirePath[] }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L21) ### `WirePath` ```ts type WirePath = { path: string; type?: "layout" | "page" }; ``` **Exported from:** `@nexload-sdk/payload-revalidate` Public type exported by @nexload-sdk/payload-revalidate. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/types.ts#L17) ## Entrypoints and Runtime Constraints * **Module format:** Dual ESM (`import`) and CJS (`require`). * **`@nexload-sdk/payload-revalidate`:** Runs in Node.js on the Payload CMS server and never imports `next` or `next/*`. * **`@nexload-sdk/payload-revalidate/next`:** Uses `next/cache` (`revalidateTag(tag, "max")`, `revalidatePath`) and requires the Next.js Node.js runtime. Do not configure `runtime = "edge"`. * **`@nexload-sdk/payload-revalidate/testing`:** Exports `createTestRevalidator(options?)` returning `{ revalidator, calls, clear }` for zero-network in-memory tests. ## Wire Format Requests are sent as `POST {url}{endpoint}` with `content-type: application/json`, `x-revalidate-timestamp` (`TIMESTAMP_HEADER`), `x-revalidate-signature` (`SIGNATURE_HEADER`, base64url HMAC-SHA256 over `` `${timestamp}.${rawBody}` `` in signed mode), and `x-trace-id`. Limits: `MAX_TARGETS = 50` per request, `MAX_BODY_BYTES = 8192` UTF-8 bytes, and `TIMESTAMP_WINDOW_SECONDS = 60`. ## Logging Events All logs use `@nexload-sdk/logger` with child bindings `{ module: "payload-revalidate" }`: `revalidate.client.disabled` (`debug`), `revalidate.batch.flushed` (`info`), `revalidate.batch.dropped` (`warn`), `revalidate.target.dropped` (`warn`), `revalidate.hook.failed` (`error`), `revalidate.request.sent` (`info`), `revalidate.request.retried` (`warn`), `revalidate.request.failed` (`error`), `revalidate.request.handled` (`info`), and `revalidate.request.rejected` (`warn`). --- # Production Guides & Recipes Sender setup, hook composition, visibility rules, batching, receiver security, testing, and limitations. **Topic:** guides **Package:** `@nexload-sdk/payload-revalidate` v1.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/payload-revalidate/guides/ ## Sender setup Create a single `revalidator` instance in your Payload server and share it across collections, globals, and jobs: ```ts import { createRevalidator } from "@nexload-sdk/payload-revalidate"; const secret = process.env.WEB_REVALIDATION_SECRET; if (!secret) { throw new Error("WEB_REVALIDATION_SECRET is required"); } export const revalidator = createRevalidator({ url: process.env.WEB_URL, secret, }); ``` When `enabled` is not `false` and `url` is `undefined` or empty, `createRevalidator` throws `TypeError` at creation time. Because `secret` is optional on the sender, a missing or empty `WEB_REVALIDATION_SECRET` silently sends unsigned requests that a signed receiver rejects with `401` (hooks only log the failure), so fail fast at startup in signed mode before passing `secret`. Omit `secret` only when the receiver uses `allowUnsigned: true`. Set `enabled: false` to disable revalidation without removing hooks (`hooks()`, `globalHooks()`, `send()`, and `flush()` become no-ops and one debug log is emitted at creation). | Option | Type | Default | Description | | --- | --- | --- | --- | | `url` | `string \| undefined` | — | Base URL of the Next.js app (required when `enabled !== false`) | | `secret` | `string` | `undefined` | Shared HMAC-SHA256 secret (omit only with `allowUnsigned: true` behind a private network) | | `enabled` | `boolean` | `true` | When `false`, hooks, `send()`, and `flush()` are no-ops | | `logger` | `Logger` | `@nexload-sdk/logger` default | Custom logger instance; a child `{ module: "payload-revalidate" }` is created | | `endpoint` | `string` | `"/api/revalidate"` | Receiver path appended to `url` | | `timeoutMs` | `number` | `3000` | Per-attempt HTTP request timeout in milliseconds | | `retries` | `number` | `2` | Retry count after initial failure (up to 3 total attempts on network errors, aborts, `408`, `429`, `5xx`) | ## Collection and global hooks Hooks resolve public snapshots, enqueue targets into a per-transaction batch, and return `doc` immediately without awaiting HTTP requests or throwing on network errors. Spread `hooks(slug, rules)` alongside your existing collection hooks: ```ts import type { CollectionConfig } from "payload"; import { revalidator } from "../lib/revalidator"; const productHooks = revalidator.hooks("products", { tags: ({ doc }) => ["products", `product:${doc.slug}`], paths: ({ doc }) => [`/shop/${doc.slug}`], }); export const Products: CollectionConfig = { slug: "products", hooks: { afterChange: [myExistingAfterChangeHook, ...productHooks.afterChange], afterDelete: [...productHooks.afterDelete], }, // ...fields }; ``` Use `globalHooks(slug, rules)` for Payload globals: ```ts import type { GlobalConfig } from "payload"; import { revalidator } from "../lib/revalidator"; const settingsHooks = revalidator.globalHooks("site-settings", { tags: ["site-settings"], paths: [{ path: "/", type: "layout" }], }); export const SiteSettings: GlobalConfig = { slug: "site-settings", hooks: { afterChange: [...settingsHooks.afterChange], }, // ...fields }; ``` ### Locale-scoped tags `Ctx` provides `locales` (all configured locale codes, or `[]` when localization is off) and `locale` (the active request locale, default locale when omitted, or `null` when localization is off; `"all"` is passed through as-is, in which case localized fields on `doc` are locale maps). Because a save in one locale can stale other locales via non-localized fields, emit tags across `locales`: ```ts const productHooks = revalidator.hooks("products", { tags: ({ doc, locales }) => [ "products", ...locales.map((l) => `product:${l}:${doc.id}`), ], }); ``` Keep tag builders in a shared `as const` `CACHE_TAGS` object so Payload hooks and Next.js `"use cache"` / `cacheTag()` calls stay aligned. ## Visibility and `isPublic` By default, `isPublic(doc)` returns `doc.deletedAt == null && doc._status !== "draft"` (collections without drafts count as public unless trashed). | Change | Resolved snapshots | | --- | --- | | Draft save or autosave, including over a live doc | none | | Create published, publish, restore from trash | new doc | | Update of a public doc (incl. rename, category move) | new doc and previous doc | | Unpublish, trash, hard delete of a public doc | last public doc | Rules run once per resolved snapshot with `doc` set to that snapshot; results are unioned and deduplicated. When `previousDoc` is a draft (for example, publishing after a renamed draft or unpublishing after saving a draft), the hook performs one extra version lookup (`findVersions` or `findGlobalVersions` within the same transaction) to recover the prior published snapshot. Collections or globals configured with `versions: { maxPerDoc: 1 }` retain only the latest version, so older published snapshots cannot be recovered. Override `isPublic` in `Rules` for flag-based visibility (such as `isActive`) or collections with `localizeStatus: true`: ```ts const postHooks = revalidator.hooks("posts", { isPublic: (doc) => doc.deletedAt == null && doc.isActive === true, tags: ({ doc }) => [`post:${doc.slug}`], }); ``` ## Batching, bulk jobs, and `flush()` Targets collected by hooks are batched per `req` and `transactionID`, deduplicated, and sent after the transaction commits. How the package learns about the commit depends on your config: | Setup | When the batch is sent | Long transactions | Rollback | | --- | --- | --- | --- | | `afterCommitPlugin()` installed (default in `nexloadPreset()`) | Exactly on commit, from a `runAfterCommit` callback | No cap | Batch is discarded | | Plugin not installed | When polling sees the transaction end | Batch is dropped after 5000 ms with `revalidate.batch.dropped` | Batch is sent anyway | Install the plugin from `@nexload-sdk/payload-hooks` for production: ```ts import { afterCommitPlugin } from "@nexload-sdk/payload-hooks"; export default buildConfig({ plugins: [afterCommitPlugin()], // ... }); ``` For bulk operations, pass `context: { skipRevalidate: true }` to skip per-document hooks, then call `await revalidator.send(...)` only after the owning transaction has committed (when a top-level Local API call without an open-transaction `req` returns, or after `await commitTransaction(req)` if you opened the transaction with `initTransaction`): ```ts await payload.update({ collection: "products", where: { category: { equals: categoryId } }, data: { discountPercent: 10 }, context: { skipRevalidate: true }, }); await revalidator.send({ tags: ["products", `category:${categorySlug}`], }); ``` Never call `revalidator.send(...)` from inside a hook or someone else's transaction (such as a job step sharing `req`): unlike hooks, `send()` posts immediately before commit and throws on failure (`TypeError` on invalid targets or request errors on HTTP/network failure). `await revalidator.flush()` waits for in-flight HTTP sends. Without `afterCommitPlugin()` it also waits for pending transaction waiters (bounded by the 5000 ms wait cap). With the plugin, a batch whose transaction has not committed yet is not waited for, so call `flush()` after the write returns. Use it in tests, CLI scripts, or Next.js `after()` / `waitUntil()`. Never call `flush()` from inside a hook: without the plugin the database commit waits on the hook while `flush()` waits on the transaction, which hits the 5000 ms cap and drops the batch; with the plugin it returns before anything was sent. ## Receiver (signed and unsigned) Mount `createRevalidateHandler` at `app/api/revalidate/route.ts` in your Next.js App Router app (Node.js runtime; do not set `runtime = "edge"`). ```ts // Signed mode (publicly reachable Next.js or separate hosts) import { createRevalidateHandler } from "@nexload-sdk/payload-revalidate/next"; export const POST = createRevalidateHandler({ secret: process.env.WEB_REVALIDATION_SECRET!, }); ``` During secret rotation, pass `secret: [newSecret, oldSecret]`; the receiver accepts a valid signature from any listed key. For private Docker-internal deployments where `/api/revalidate` is blocked at the public reverse proxy: ```ts import { createRevalidateHandler } from "@nexload-sdk/payload-revalidate/next"; export const POST = createRevalidateHandler({ allowUnsigned: true }); ``` `createRevalidateHandler` throws `TypeError` at creation if neither `secret` nor `allowUnsigned: true` is provided (including `secret: undefined`), or if both are specified. The receiver validates in order before calling `revalidateTag(tag, "max")` or `revalidatePath(path, type)`: 1. `POST` method (`405`) 2. `content-type: application/json` (`415`) 3. Request body present (`400`) and `<= 8192` bytes UTF-8 (`413`, enforced while streaming) 4. HMAC signature and `±60` s timestamp window when signed (`401`) 5. Valid JSON schema, `1..50` targets, and safe tag/path patterns (`400`) A batch with even one invalid target is rejected with `400` and triggers zero cache calls. ## Proxy blocking for unsigned mode In `allowUnsigned: true` mode, anyone who can reach `/api/revalidate` can trigger cache invalidation. Block public access to `/api/revalidate` at your reverse proxy while keeping the internal container URL reachable from Payload: ```yaml # Traefik http: routers: web-block-revalidate: rule: "Host(`example.com`) && PathPrefix(`/api/revalidate`)" priority: 100 service: block-service middlewares: - deny-revalidate middlewares: deny-revalidate: ipAllowList: sourceRange: - "127.0.0.1/32" ``` ```nginx # Nginx location ^~ /api/revalidate { return 403; } ``` ```txt # Caddy example.com { @revalidate path /api/revalidate /api/revalidate/* respond @revalidate 403 reverse_proxy web:3000 } ``` Verify that a public `POST https://example.com/api/revalidate` returns `403` or `404` while the CMS container can still reach the internal service URL. ## Testing Use `createTestRevalidator` from `@nexload-sdk/payload-revalidate/testing` to capture dispatched `WireBatch` objects in memory with zero network calls, then await `revalidator.flush()`: ```ts import { createTestRevalidator } from "@nexload-sdk/payload-revalidate/testing"; const { revalidator, calls, clear } = createTestRevalidator(); // Run collection operations using `revalidator`, then: await revalidator.flush(); ``` ## Limitations * **`versions.maxPerDoc: 1`:** Recovering the prior published snapshot when `previousDoc` is a draft requires at least two retained versions. * **`localizeStatus: true`:** `_status` reaches hooks as a string on single-locale requests and as a per-locale map when locale is `"all"`. Custom `isPublic` must handle both shapes; snapshot resolution and published-version recovery are not guaranteed in v1. After unpublishing or publishing a renamed draft, call `await revalidator.send({ tags, paths })` with old targets after the owning transaction commits. * **No durable delivery:** Batches live in memory per transaction with bounded retries; process crashes or exhausted retries drop and log the batch. * **No multi-target fan-out:** Each `createRevalidator` targets a single `url`. * **5-second transaction wait cap (only without `afterCommitPlugin()`):** Transactions open longer than 5000 ms after a hook runs drop the batch with a `revalidate.batch.dropped` warning; use `context: { skipRevalidate: true }` and `send()` after commit for long jobs. --- # Overview & Quick Start Per-transaction Payload CMS cache revalidation hooks and Next.js route handler. **Topic:** overview **Package:** `@nexload-sdk/payload-revalidate` v1.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/payload-revalidate/ **Package:** `@nexload-sdk/payload-revalidate` **Workspace version:** `1.0.0` Per-transaction Payload CMS cache revalidation hooks and Next.js route handler. [npm](https://www.npmjs.com/package/@nexload-sdk/payload-revalidate) · [Source](https://github.com/gecut/nexload-sdk/tree/main/packages/payload-revalidate) `@nexload-sdk/payload-revalidate` wires per-transaction Payload CMS collection and global hooks (`hooks()`, `globalHooks()`), bulk `skipRevalidate` + `send()` jobs, and a Next.js App Router route handler (`createRevalidateHandler`). It ships dual ESM and CJS builds; the root entry never imports `next`, and `./next` runs in the Next.js Node.js runtime. ## Installation ```bash pnpm add @nexload-sdk/payload-revalidate @nexload-sdk/logger payload ``` ## Quick Start Create a single shared `revalidator` on your Payload server, compose its hooks onto collections or globals, and mount `createRevalidateHandler` in Next.js: ```ts // lib/revalidator.ts (Payload CMS server) import { createRevalidator } from "@nexload-sdk/payload-revalidate"; const secret = process.env.WEB_REVALIDATION_SECRET; if (!secret) { throw new Error("WEB_REVALIDATION_SECRET is required"); } export const revalidator = createRevalidator({ url: process.env.WEB_URL, secret, }); ``` ```ts // collections/Products.ts (Payload CMS server) import type { CollectionConfig } from "payload"; import { revalidator } from "../lib/revalidator"; const productHooks = revalidator.hooks("products", { tags: ({ doc }) => ["products", `product:${doc.slug}`], paths: ({ doc }) => [`/shop/${doc.slug}`], }); export const Products: CollectionConfig = { slug: "products", hooks: { afterChange: [...productHooks.afterChange], afterDelete: [...productHooks.afterDelete], }, // ...fields }; ``` ```ts // app/api/revalidate/route.ts (Next.js App Router, Node.js runtime) import { createRevalidateHandler } from "@nexload-sdk/payload-revalidate/next"; export const POST = createRevalidateHandler({ secret: process.env.WEB_REVALIDATION_SECRET!, }); ``` See [guides](./guides/) for hook composition, visibility rules, batching, proxy blocking, and testing, and the [API reference](./api/) for exports and wire limits. ## Next steps [Optimization](./optimization/) [Agent usage](./agents/) --- # payload-revalidate — Optimization Production choices for @nexload-sdk/payload-revalidate. **Topic:** optimization **Package:** `@nexload-sdk/payload-revalidate` v1.0.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/payload-revalidate/optimization/ ## Keep hooks non-blocking Hooks enqueue targets per transaction and return immediately. Never call `flush()` or `send()` inside a collection or global hook; `flush()` deadlocks until the 5000 ms wait cap expires, and `send()` posts before transaction commit and throws on failure. ## Batch bulk updates with skipRevalidate For bulk updates or deletes, pass `context: { skipRevalidate: true }` to suppress per-document hooks and the 5000 ms transaction wait cap, then call `await revalidator.send({ tags, paths })` once after the owning transaction commits. ## Scope tags across locales Because a save in one locale can stale other locales via non-localized fields, emit tags across `ctx.locales` using a non-localized identifier such as `doc.id`, and share a single `as const` `CACHE_TAGS` map between Payload and Next.js. ## Avoid maxPerDoc: 1 on versioned collections Recovering the prior published snapshot when `previousDoc` is a draft requires at least two retained versions. Keep `versions.maxPerDoc` above `1` on collections and globals that use drafts. ## Sources [Package guidance](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/README.md) · [Implementation](https://github.com/gecut/nexload-sdk/blob/main/packages/payload-revalidate/src/index.ts) · [Matching skill](https://github.com/gecut/nexload-sdk/blob/main/skills/payload-revalidate/SKILL.md).