diff --git a/raw/upload__storage-adapters.md b/raw/_processed/upload__storage-adapters.md similarity index 100% rename from raw/upload__storage-adapters.md rename to raw/_processed/upload__storage-adapters.md diff --git a/wiki/_master-index.md b/wiki/_master-index.md index 8c43e11..c194e6b 100644 --- a/wiki/_master-index.md +++ b/wiki/_master-index.md @@ -35,7 +35,7 @@ This 3-hop pattern works for hundreds of articles without vector search. | [[wiki/reports/_index\|reports/]] | Weekly and monthly summaries — generate: `uv run python scripts/report-generator.py --weekly` | 1 | | [[wiki/infrastructure/_index\|infrastructure/]] | Server inventory: all 10 SSH hosts — optical, optical-dev, optical-prod, baic, librechat, modocmms, box-cli, aimpress, pve | 12 | | [[wiki/testing/_index\|testing/]] | Web app testing: functional, performance, security, UI types; TDD/BDD/Agile methodologies; Selenium/Cypress/Playwright/JMeter/OWASP ZAP tools | 1 | -| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, ecommerce, production deploy, TypeScript, migration guides, i18n, localization, hierarchy, trash/soft-delete, troubleshooting | 143 | +| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts/autosave, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, storage adapters (S3/R2/GCS/Azure/Vercel Blob), ecommerce, production deploy, TypeScript, migration guides, i18n, localization, hierarchy, trash/soft-delete, troubleshooting | 145 | | [[wiki/shared-patterns/_index\|shared-patterns/]] | Oliver Agency standard library patterns: httpx, structlog, pydantic-settings, alembic — reuse before writing from scratch | 4 | | [[wiki/mistakes/_index\|mistakes/]] | Anti-patterns extracted from sessions — per-stack running lists (fastapi, react, docker, postgres, general) — injected at session start | 5 | diff --git a/wiki/payloadcms/_index.md b/wiki/payloadcms/_index.md index 0053fad..153313d 100644 --- a/wiki/payloadcms/_index.md +++ b/wiki/payloadcms/_index.md @@ -18,6 +18,7 @@ | [[wiki/payloadcms/custom-components\|Custom Components]] | Root slots, dashboard widgets, edit/list view slots, document views, custom views, providers | raw/custom-components__*.md | 2026-05-15 | | [[wiki/payloadcms/upload\|Upload & Media]] | Upload config, imageSizes, focal point, storage adapters (S3/R2/GCS/Azure/Vercel Blob), access control, gotchas | raw/upload__*.md | 2026-05-15 | +| [[wiki/payloadcms/storage-adapters\|Storage Adapters]] | All 6 cloud storage adapters (Vercel Blob/S3/Azure/GCS/Uploadthing/R2), R2+Node.js via S3 API, prefix composition, access control proxy, custom adapter interface | raw/upload__storage-adapters.md | 2026-05-15 | | [[wiki/payloadcms/features\|Features — Email, Folders, Trash, Query Presets]] | Email adapters (Nodemailer/Resend), folder grouping (beta), soft-delete trash workflow, saved query presets | raw/email/folders/trash/query-presets | 2026-05-15 | | [[wiki/payloadcms/folders\|Folders — Content Organization]] | Folder grouping for collections (beta): global config, per-collection opt-in, nesting, browse-by-folder view | raw/folders__overview.md | 2026-05-15 | | [[wiki/payloadcms/email\|Email — Adapters, SMTP, Resend, Attachments]] | Full email reference: Nodemailer (SMTP/SendGrid/dev), Resend (serverless), sendEmail API, attachments (Buffer/path/Base64/URL), media collection attachments | raw/email__overview.md | 2026-05-15 | @@ -144,3 +145,4 @@ | [[wiki/payloadcms/trash-soft-delete\|Trash — Soft Delete]] | `trash: true` on a collection enables soft delete via `deletedAt` timestamp; dedicated Trash admin view; `trash` query param for all APIs; access control differentiates trash vs permanent delete via `data.deletedAt` | raw/trash__overview.md | 2026-05-15 | | [[wiki/payloadcms/troubleshooting\|Troubleshooting Common Issues]] | Dependency mismatches (duplicate packages, monorepos), "Unauthorized" cookie debug, --experimental-https HMR WebSocket fix, DB password encoding | raw/troubleshooting__troubleshooting.md | 2026-05-15 | | [[wiki/payloadcms/typescript-plugin\|TypeScript Plugin (Experimental)]] | `@payloadcms/typescript-plugin` — IDE path validation, export validation, autocomplete, go-to-definition for PayloadComponent import strings; VS Code workspace TS setup | raw/typescript__ts-plugin.md | 2026-05-15 | +| [[wiki/payloadcms/versions-autosave\|Versions — Autosave]] | Autosave config (interval/showSaveDraftButton), single-version upsert storage strategy, `autosave` arg on Local API update, requires versions+drafts | raw/versions__autosave.md | 2026-05-15 | diff --git a/wiki/payloadcms/versions-autosave.md b/wiki/payloadcms/versions-autosave.md new file mode 100644 index 0000000..8fe1bab --- /dev/null +++ b/wiki/payloadcms/versions-autosave.md @@ -0,0 +1,93 @@ +--- +title: "Versions — Autosave" +aliases: [autosave, payload-autosave, draft-autosave] +tags: [payloadcms, versions, drafts, autosave, admin-ui] +sources: [raw/versions__autosave.md] +created: 2026-05-15 +updated: 2026-05-15 +--- + +## Overview + +Autosave extends [[wiki/payloadcms/admin-preview|Draft]] functionality — the Admin UI periodically saves changes as draft versions while editing, so work is never lost. Publishing to live happens only when explicitly triggered. + +> **Requires:** `versions.drafts` must be enabled on the collection or global. + +## Config + +Set `versions.drafts.autosave` to `true` (minimal) or an options object: + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `interval` | `number` (ms) | `800` | Debounce interval for autosave writes | +| `showSaveDraftButton` | `boolean` | `false` | Show manual "Save as draft" button alongside autosave | + +```ts +import type { CollectionConfig } from 'payload' + +export const Pages: CollectionConfig = { + slug: 'pages', + access: { + read: ({ req }) => { + if (req.user) return true + return { _status: { equals: 'published' } } + }, + }, + versions: { + drafts: { + autosave: { + interval: 1500, + showSaveDraftButton: true, + }, + }, + }, +} +``` + +## How Autosaves Are Stored + +- Payload does **not** create a new version record per autosave tick. +- Instead, **one** autosave version is created, then **updated in-place** on every subsequent autosave. +- This keeps the `_versions` collection tidy even at 800 ms intervals. + +## Admin UI Behaviour + +- Sidebar shows a "last saved" timestamp indicator while autosave is active. +- The document publishes only when the user clicks "Publish" — autosaves remain as drafts. + +## Autosave API Argument + +All `update` operations expose an `autosave` boolean argument. When `true`, Payload treats the update as an autosave and applies the single-version-upsert behaviour instead of creating a new version. + +```ts +await payload.update({ + collection: 'pages', + id: doc.id, + data: { title: 'Draft title' }, + draft: true, + autosave: true, // <-- reuses existing autosave version +}) +``` + +Primarily used by the Admin UI, but available for custom frontends implementing their own autosave loop. + +## Key Takeaways + +- Autosave requires both `versions` and `drafts` enabled — it cannot work standalone. +- Default interval is 800 ms with debounce; tune with `interval`. +- Only **one** autosave version is kept per document — subsequent saves update that single record. +- `showSaveDraftButton: true` lets editors manually save a named draft alongside the running autosave. +- Access control on reads should gate on `_status: 'published'` for unauthenticated users to avoid leaking draft content. +- The `autosave: true` flag on Local API `update` calls triggers the upsert behaviour — useful when building custom editors. + +## Related + +- [[wiki/payloadcms/live-preview-server|Live Preview — Server-Side]] — mentions Autosave integration with `RefreshRouteOnSave` +- [[wiki/payloadcms/hooks-collections|Collection Hooks]] — `afterChange` fires on autosave updates too +- [[wiki/payloadcms/local-api|Local API]] — `update` operation with `autosave` argument +- [[wiki/payloadcms/custom-components-edit-view|Custom Components — Edit View]] — `SaveDraftButton` slot relevant when `showSaveDraftButton: true` + +## Sources + +- `raw/versions__autosave.md` — compiled 2026-05-15 +- Official docs: https://payloadcms.com/docs/versions/autosave