Skip to content

feat!: add upload file versioning - #18548

Merged
nathanlentz merged 64 commits into
mainfrom
feat/file-versioning-core
Oct 7, 2026
Merged

nathanlentz merged 64 commits into
mainfrom
feat/file-versioning-core

Conversation

@nathanlentz

@nathanlentz nathanlentz commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Written by AI

What?

This is part 2 of the two-PR file versioning stack. It adds the Payload and storage adapter implementation for the behavior defined in #18547.

Versioned upload documents now retain their original source and every stored representation needed by current or historical versions. Restore, pruning, replacement, rename, and deletion preserve referenced objects and remove objects after their final reference is removed.

Why?

Payload document versions previously retained upload metadata without managing the corresponding stored files. Historical versions could therefore reference replaced or deleted objects.

How?

  • Stores location data with the current file, original, and each configured variant.
  • Stages storage writes before document writes and delays cleanup until the surrounding operation succeeds.
  • Archives outgoing local and cloud objects when versions retain them.
  • Restores stored files without replaying transformations.
  • Adds safe copy operations to first-party storage adapters.
  • Uses the retained original as the image editor source while keeping normal previews on the processed file.
  • Adds Local API, REST, and GraphQL support for file rename operations.

⚠️ Breaking changes

  • Custom cloud storage adapters must implement the required GeneratedAdapter.copyFile operation.
  • New uploads retain their source using an -original filename. Code and infrastructure that depend on the previous filename, URL, or object key must account for the new location.
  • Upload collections gain stored original, prefix, and _objectKey fields. Relational database projects must generate and apply the corresponding schema migration.

API

Applications can rename an upload and its stored representations through payload.renameFile, the REST rename endpoint, or the generated GraphQL mutation. Existing upload create, update, delete, draft, and restore operations manage file history automatically.

@nathanlentz
nathanlentz added this pull request to stack #18549 October 6, 2026 16:33
@nathanlentz nathanlentz changed the title feat: add upload file versioning feat!: add upload file versioning Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
packages/next/meta_index.json esbuild/index.js 242.21 KB 🆕 Added
packages/payload/meta_index.json esbuild/index.js 1.95 MB 🆕 Added
packages/payload/meta_shared.json esbuild/exports/shared.js 564.16 KB 🆕 Added
packages/richtext-lexical/meta_client.json esbuild/exports/client_optimized/index.js 296.20 KB 🆕 Added
packages/ui/meta_client.json esbuild/exports/client_optimized/index.js 1.31 MB 🆕 Added
packages/ui/meta_shared.json esbuild/exports/shared_optimized/index.js 18.98 KB 🆕 Added
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: packages/next/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████████▋ }}}$ 98.9%, 237.09 KB
dist/adapters/router.js ${{\color{Goldenrod}{ }}}$ 0.3%, 718 B
dist/adapters/server.js ${{\color{Goldenrod}{ }}}$ 0.2%, 533 B
dist/adapters/layout.js ${{\color{Goldenrod}{ }}}$ 0.2%, 529 B
dist/adapters/views.js ${{\color{Goldenrod}{ }}}$ 0.1%, 324 B
dist/utilities/initAdminContext.js ${{\color{Goldenrod}{ }}}$ 0.1%, 315 B
dist/utilities/selectiveCache.js ${{\color{Goldenrod}{ }}}$ 0.1%, 263 B
dist/esbuildEntry.js ${{\color{Goldenrod}{ }}}$ 0.0%, 0 B

Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▎ }}}$ 69.2%, 1.34 MB
dist/collections/operations ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 66.60 KB
dist/fields/hooks ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 46.25 KB
dist/uploads/fileVersioning ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 22.30 KB
dist/globals/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 18.30 KB
dist/auth/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 17.10 KB
dist/utilities/configToJSONSchema.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 16.04 KB
dist/queues/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 14.32 KB
dist/fields/config ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 13.77 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 11.96 KB
dist/utilities/telemetry ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 11.93 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 10.29 KB
dist/cli/commands ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 9.93 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 8.78 KB
dist/uploads/fetchAPI-multipart ${{\color{Goldenrod}{ }}}$ 0.4%, 8.39 KB
dist/config/sanitize.js ${{\color{Goldenrod}{ }}}$ 0.4%, 8.16 KB
dist/database/migrations ${{\color{Goldenrod}{ }}}$ 0.4%, 8.16 KB
dist/uploads/generateFileData.js ${{\color{Goldenrod}{ }}}$ 0.4%, 7.97 KB
dist/collections/endpoints ${{\color{Goldenrod}{ }}}$ 0.4%, 7.85 KB
dist/uploads/transformers ${{\color{Goldenrod}{ }}}$ 0.4%, 7.82 KB
(other) ${{\color{Goldenrod}{ ███████▋ }}}$ 30.8%, 596.69 KB

Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ██████████████████████▏ }}}$ 88.7%, 495.80 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 10.26 KB
dist/fields/config ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 5.83 KB
dist/utilities/traverseFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 4.34 KB
dist/utilities/deepCopyObject.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.52 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.44 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.13 KB
dist/fields/baseFields ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 2.79 KB
dist/config/client.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 2.58 KB
dist/auth/cookies.js ${{\color{Goldenrod}{ }}}$ 0.3%, 1.55 KB
dist/utilities/flattenTopLevelFields.js ${{\color{Goldenrod}{ }}}$ 0.3%, 1.42 KB
dist/utilities/getVersionsConfig.js ${{\color{Goldenrod}{ }}}$ 0.2%, 1.04 KB
dist/globals/config ${{\color{Goldenrod}{ }}}$ 0.2%, 957 B
dist/uploads/generatePayloadFileURL.js ${{\color{Goldenrod}{ }}}$ 0.2%, 864 B
dist/utilities/unflatten.js ${{\color{Goldenrod}{ }}}$ 0.2%, 850 B
dist/utilities/flattenAllFields.js ${{\color{Goldenrod}{ }}}$ 0.1%, 798 B
dist/errors/ValidationError.js ${{\color{Goldenrod}{ }}}$ 0.1%, 773 B
dist/utilities/sanitizeUserDataForEmail.js ${{\color{Goldenrod}{ }}}$ 0.1%, 713 B
dist/auth/extractJWT.js ${{\color{Goldenrod}{ }}}$ 0.1%, 696 B
dist/utilities/getFieldPermissions.js ${{\color{Goldenrod}{ }}}$ 0.1%, 681 B
(other) ${{\color{Goldenrod}{ ██▊ }}}$ 11.3%, 63.42 KB

Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/features/blocks ${{\color{Goldenrod}{ ███▋ }}}$ 14.6%, 42.78 KB
dist/lexical/plugins ${{\color{Goldenrod}{ ██▉ }}}$ 11.8%, 34.51 KB
dist/lexical/ui ${{\color{Goldenrod}{ ██▊ }}}$ 11.4%, 33.54 KB
dist/features/table ${{\color{Goldenrod}{ ██▎ }}}$ 9.4%, 27.46 KB
dist/features/link ${{\color{Goldenrod}{ █▋ }}}$ 6.5%, 18.92 KB
dist/features/toolbars ${{\color{Goldenrod}{ █▌ }}}$ 6.3%, 18.41 KB
dist/features/upload ${{\color{Goldenrod}{ █▏ }}}$ 4.9%, 14.28 KB
dist/features/textState ${{\color{Goldenrod}{ ▉ }}}$ 3.8%, 11.08 KB
dist/lexical/utils ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 10.02 KB
dist/features/relationship ${{\color{Goldenrod}{ ▊ }}}$ 3.2%, 9.43 KB
dist/features/converters ${{\color{Goldenrod}{ ▋ }}}$ 2.9%, 8.41 KB
dist/utilities/fieldsDrawer ${{\color{Goldenrod}{ ▋ }}}$ 2.8%, 8.12 KB
dist/features/debug ${{\color{Goldenrod}{ ▋ }}}$ 2.5%, 7.40 KB
dist/lexical/config ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 5.14 KB
dist/features/indent ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 4.19 KB
dist/features/lists ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 3.67 KB
dist/lexical/LexicalEditor.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.33 KB
dist/features/format ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.28 KB
dist/features/horizontalRule ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.18 KB
dist/field/Field.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 3.06 KB
(other) ${{\color{Goldenrod}{ █████████████████████▎ }}}$ 85.4%, 250.21 KB

Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ███████▎ }}}$ 29.4%, 382.61 KB
dist/elements/Hierarchy ${{\color{Goldenrod}{ ▉ }}}$ 3.8%, 49.37 KB
dist/elements/BulkUpload ${{\color{Goldenrod}{ ▌ }}}$ 2.3%, 30.54 KB
dist/elements/Table ${{\color{Goldenrod}{ ▌ }}}$ 2.2%, 28.85 KB
dist/views/Version ${{\color{Goldenrod}{ ▌ }}}$ 2.1%, 27.83 KB
dist/views/Edit ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 22.15 KB
dist/views/HierarchyList ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 21.51 KB
dist/views/Dashboard ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 19.60 KB
dist/elements/WhereBuilder ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 17.66 KB
dist/providers/Auth ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 17.38 KB
dist/fields/Relationship ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 16.23 KB
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 16.02 KB
dist/fields/Upload ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 14.94 KB
dist/fields/Blocks ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 14.91 KB
dist/elements/Popup ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.33 KB
dist/views/List ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.22 KB
dist/elements/ReactSelect ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 12.99 KB
dist/elements/QueryPresets ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.82 KB
dist/elements/FileManager ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.42 KB
dist/widgets/RecentlyViewed ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.02 KB
(other) ${{\color{Goldenrod}{ █████████████████▋ }}}$ 70.6%, 919.97 KB

Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js

Path Size
dist/graphics/Logo ${{\color{Goldenrod}{ ███████▋ }}}$ 30.7%, 5.61 KB
../../node_modules ${{\color{Goldenrod}{ ███▌ }}}$ 14.5%, 2.65 KB
dist/graphics/Icon ${{\color{Goldenrod}{ ██ }}}$ 8.3%, 1.51 KB
dist/utilities/formatDocTitle ${{\color{Goldenrod}{ █▊ }}}$ 7.2%, 1.32 KB
dist/providers/TableColumns ${{\color{Goldenrod}{ █▏ }}}$ 4.7%, 866 B
dist/utilities/getGlobalData.js ${{\color{Goldenrod}{ █ }}}$ 4.2%, 762 B
dist/utilities/api.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 756 B
dist/utilities/groupNavItems.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 745 B
dist/elements/Translation ${{\color{Goldenrod}{ ▋ }}}$ 2.7%, 493 B
dist/utilities/handleTakeOver.js ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 440 B
dist/utilities/traverseForLocalizedFields.js ${{\color{Goldenrod}{ ▌ }}}$ 2.3%, 419 B
dist/elements/withMergedProps ${{\color{Goldenrod}{ ▍ }}}$ 1.9%, 339 B
dist/utilities/getNavGroups.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 338 B
dist/utilities/getVisibleEntities.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 329 B
dist/elements/WithServerSideProps ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 232 B
dist/layouts/Root ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 230 B
dist/utilities/handleGoBack.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 180 B
dist/fields/mergeFieldStyles.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 158 B
dist/forms/Form ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
dist/utilities/handleBackToDashboard.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
(other) ${{\color{Goldenrod}{ █████████████████▎ }}}$ 69.3%, 12.68 KB
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

@nathanlentz
nathanlentz force-pushed the feat/file-versioning-core branch from ddaa0af to b4ec8d9 Compare October 6, 2026 17:46
@nathanlentz
nathanlentz force-pushed the feat/file-versioning-core branch from b4ec8d9 to 9d32910 Compare October 6, 2026 17:57
@nathanlentz
nathanlentz force-pushed the feat/file-versioning-core branch from 521fbdb to 5746cb4 Compare October 6, 2026 19:12
@nathanlentz
nathanlentz requested review from paulpopus and r1tsuu and removed request for DanRibbens, denolfe and jacobsfletch October 6, 2026 19:51

@paulpopus paulpopus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written with AI

}

// Server-owned key segment; hidden from the API and admin, read internally via showHiddenFields.
// Server-owned key segment. Field-level `hidden` would remove it before the URL hooks can read it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep object keys available during selected reads

Positive selections can remove prefix and _objectKey before the URL hook runs. Admin list and relationship requests select filename and URL fields, so the hook regenerates direct URLs without the UUID folder and returns 404. Keep these internal fields available to URL hooks regardless of selection, and add tests for selected top-level, original, and variant URLs.

@nathanlentz nathanlentz Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0adbb5b. Fixed there for top-level and original URLs. Variant URLs look like they are affected by a transformer-order bug (for third party adapters) which I think should be handled in a fast follow/smaller PR.

const isDuplicatingAnOriginal =
isDuplicating && file.name === (originalDoc as FileData | undefined)?.original?.filename

if (!fileWasTransformed && !retainedOriginal && !providerOriginal && !isDuplicatingAnOriginal) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve provider filenames for references without receipts

A provider reference without a signed receipt reaches this branch and renames photo.png to photo-original.png. The cloud hook skips files with uploadReference, so the saved document points to a file that was never uploaded. Preserve the provider filename or copy the object, and test the documented uploadReference: {} flow.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0adbb5b. Fixed with tests for both a text file and a png.

relative: true,
})
}
if (doc.url !== (await expectedURL({ filename: doc.filename }))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recognise legacy files with changing URLs

hasLegacyFile regenerates the provider URL and requires exact equality with the stored URL. Signed or time-limited URLs change, so Payload does not migrate the object and later historical versions cannot resolve it. Identify legacy files from stable storage data, and test replacement after the URL signature changes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0adbb5b. Fixed with a test that covers main and variant URLs

@nathanlentz
nathanlentz requested a review from paulpopus October 7, 2026 16:50
paulpopus
paulpopus previously approved these changes Oct 7, 2026
@nathanlentz
nathanlentz removed this pull request from stack #18549 October 7, 2026 18:25
@nathanlentz
nathanlentz changed the base branch from feat/file-versioning-tests to main October 7, 2026 18:26
@nathanlentz
nathanlentz dismissed paulpopus’s stale review October 7, 2026 18:26

The base branch was changed.

@nathanlentz
nathanlentz merged commit ec3d99e into main Oct 7, 2026
557 of 572 checks passed
@nathanlentz
nathanlentz deleted the feat/file-versioning-core branch October 7, 2026 18:27
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🚀 This is included in version v4.0.0-canary.39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants