Skip to content

fix(ui): resolve globals correctly in copyDataFromLocale - #16334

Open
robinvandenb wants to merge 1 commit into
payloadcms:mainfrom
robinvandenb:fix-copy-to-locale-global
Open

robinvandenb wants to merge 1 commit into
payloadcms:mainfrom
robinvandenb:fix-copy-to-locale-global

Conversation

@robinvandenb

Copy link
Copy Markdown

The bug

Calling the server function copyDataFromLocaleHandler with a globalSlug (triggered by the admin UI's "Copy to locale" button on any Global) crashes with:

TypeError: Cannot read properties of undefined (reading 'config')
    at copyDataFromLocale (packages/ui/src/utilities/copyDataFromLocale.ts:208)

The same button works fine for Collections. For Globals it is 100% broken. Reproducible on current main and released versions up to at least v3.83.0.

Repro steps

  1. In any config with localization enabled and ≥ 2 locales, define a Global (e.g. { slug: 'homescreen-layout', fields: [...] }).
  2. Edit the Global in one locale, save.
  3. Switch to another locale, open the "Copy to locale" menu, pick the source locale, click "Copy".
  4. Observe the error above in server logs; the admin toast shows "Cannot read properties of undefined (reading 'config')".

Root cause

copyDataFromLocale destructured globals off req.payload and then looked up globals[globalSlug].config.fields, assuming payload.globals is a slug-keyed map the way payload.collections is. It isn't. Per packages/payload/src/index.ts, payload.globals always has shape { config: SanitizedGlobalConfig[] }. Every other place in the codebase (e.g. packages/payload/src/globals/operations/local/findOne.ts, update.ts, restoreVersion.ts, findVersions.ts, findVersionByID.ts, countVersions.ts, utilities/handleEndpoints.ts, utilities/getRequestEntity.ts) resolves a global via payload.globals.config.find((c) => c.slug === globalSlug). copyDataFromLocale was the only offender, so globals[globalSlug] was always undefined for a real slug and .config threw.

The fix

  • Look up the global via payload.globals.config.find((c) => c.slug === globalSlug), matching the rest of Payload.
  • Throw APIError("The global with slug X can't be found.", 404) if the slug is missing (mirrored the same guard on the collection branch so a bad collectionSlug no longer crashes on undefined.config.fields either).
  • Removed the unused globals destructure.

Public signatures of copyDataFromLocale / copyDataFromLocaleHandler are unchanged.

Tests

Added under test/localization/int.spec.ts, inside the existing Copying To Locale block:

  • copies undefined fields from a source locale to a target locale on a global — seeds en, clears es, calls copyDataFromLocaleHandler with globalSlug, asserts title and group.subtitle are copied on the es draft. This would have failed on main with the original TypeError.
  • throws a clear error when the global slug does not exist — asserts the new APIError path.

Introduced a minimal localized-global-for-copy global in test/localization/config.ts for the round-trip.

Run locally with:

pnpm test:int --filter localization

@denolfe denolfe added the v3 label Apr 23, 2026
@github-actions github-actions Bot added the stale label May 26, 2026
Filip-Ermenkov added a commit to Filip-Ermenkov/Service-Calculator that referenced this pull request Oct 23, 2026
… bug (#115)

* docs: record the live AWS checks and the upstream Payload copy-locale bug

Everything here was read from the live account or reproduced on 2026-10-23.

Payload's "Copy to locale" crashes on every global. The client hit it four
times on 2026-10-17 (French to English, on Company Info or Legal Info), and
the CloudFront 5xx alarm was the only thing that noticed. The bug is upstream:
@payloadcms/ui's copyDataFromLocale reads payload.globals[slug].config, but
payload.globals is { config: [...] } with no per-slug keys. It reproduces
against the local database with the identical log line, it is still present
in Payload 3.92.0, and two fixes are open upstream (payloadcms/payload#16334,
#17072). It is deliberately not patched here; PROGRESS records it with the
check that says when to delete the entry, and FUNCTIONALITY §6 tells the
client the workaround, which is the intended workflow anyway: write in
English and let French and German be generated.

Corrections from the live account:
- Lambda's account limit is already 400, not the default 10 that PROGRESS
  and an sst.config.ts comment claimed. AWS raises it on its own. A request
  for 1000 is open.
- SES production access was requested. AWS's first response can take up to
  96 hours (PROGRESS said ~24h), and the review reads DENIED until the
  requested details are sent. Testing after approval needs an address that
  is not a verified identity, or it proves nothing.
- Monitoring is proven: all twelve alarms OK, both SNS subscriptions
  confirmed, and a forced ALARM in each region was delivered with no failures.
- Visitors make no request to Google for fonts. They are served from the
  build. The build-time dependency on Google's font CDN is still real.
- New housekeeping item: pg v9 will give sslmode=require libpq semantics,
  which skip certificate verification. Move the Neon URLs to
  sslmode=verify-full first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: the SES reputation alarms are applied

Applied from main on 2026-10-23. The plan was exactly 2 to add, 0 to change,
0 to destroy with no drift, and a follow-up plan shows no changes. Both alarms
sit in INSUFFICIENT_DATA because the account has sent no mail in weeks. That
is the designed "watching nothing" state, not a fault. What remains is reading
the metric's publishing cadence once mail flows after SES production access.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: track the DPA check, Search Console and the deploy-role tightening

Three pre-launch and post-launch items that existed only elsewhere, or
nowhere:

- Data processing agreements (new step 6). The published Privacy Policy says
  every processor acts under a DPA, and TECHSPEC §7A says that has to be
  confirmed, not assumed. PROGRESS never listed it.
- Google Search Console in the launch flip, with the trap spelled out:
  workspace-mail.tf owns the whole root TXT set, so a verification value
  added by hand in Route 53 is replaced by the next terraform apply.
- IAM Access Analyzer for the deploy role. infra/aws/README.md has said it
  was "tracked in PROGRESS → What is left" while it wasn't.

The launch flip and housekeeping steps move from 6/7 to 7/8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

2 participants