---
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
