SIGN IN SIGN UP
payloadcms / payload UNCLAIMED

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

0 0 16 TypeScript

fix(ui): prevent data loss in copy-to-locale with drafts (#16073)

## Summary

Fixes two related bugs in copyDataFromLocale that cause data loss when
using the "Copy to Locale" feature with drafts/autosave enabled:

1. 500 error with draft-only documents: When a document only exists as a
draft (never published), copy-to-locale failed with "Error fetching data
from locale" because findByID without draft: true can't find draft-only
documents.
2. Published content overwritten: When the source locale has both
published and draft versions with different content, copying to another
locale would overwrite the source locale's published content with the
draft content.

### Root Cause

The copyDataFromLocale function was:
- Fetching documents without draft: true, failing on draft-only docs
- Calling update() without draft: true, which creates a new published
version that snapshots all locales - but using draft data instead of
published data for the source locale

### Fix

Added draft: true to:
- All findByID/findGlobal calls (4 places) - allows finding draft-only
documents
- All update/updateGlobal calls (2 places) - creates draft instead of
published, preserving existing published content

### Behavior Change

Copy-to-locale now creates a draft in the target locale instead of
immediately publishing. This is arguably better UX since users can
review translations before publishing.

## Test Plan

- Added integration tests for copy-to-locale with autosave/drafts
- Added integration test for draft-only documents
- Added integration test verifying published content isn't overwritten
- Added e2e test for full UI flow
J
Jarrod Flesch committed
43b8de6f30b3b01c5e825e75f0ef9650e5daf094
Parent: b2a8917
Committed by GitHub <noreply@github.com> on 3/30/2026, 4:24:30 PM