Skip to content

fix(ui): separate client schema map caches by auth state - #18168

Open
dvd233 wants to merge 1 commit into
payloadcms:3.xfrom
dvd233:fix/account-view-client-schema-cache
Open

dvd233 wants to merge 1 commit into
payloadcms:3.xfrom
dvd233:fix/account-view-client-schema-cache

Conversation

@dvd233

@dvd233 dvd233 commented Sep 13, 2026

Copy link
Copy Markdown

What?

Keep authenticated and unauthenticated client field schema maps in separate cache entries, with regression coverage for both request orders.

Why?

createUnauthenticatedClientConfig intentionally removes collection field schemas, but getClientSchemaMap cached maps only by collection/global/widget slug. A limited map cached before the authenticated account request could therefore be reused while building the Account form, leaving renderField without the client field it expects and causing the crash reported in #18162.

The reverse order could likewise return a map built from the wrong config shape. The cache needs to include the config's authentication state, not just the entity slug.

How?

  • Prefix each schema-map cache key with authenticated or unauthenticated.
  • Add unit tests built with the real createUnauthenticatedClientConfig helper.
  • Cover both limited-first and full-first cache orderings.

Fixes #18162

Testing

  • pnpm exec vitest run --project unit packages/ui/src --no-cache (11 files, 125 tests)
  • pnpm exec prettier --check packages/ui/src/utilities/getClientSchemaMap.ts packages/ui/src/utilities/getClientSchemaMap.spec.ts
  • pnpm exec eslint --flag v10_config_lookup_from_file packages/ui/src/utilities/getClientSchemaMap.ts
  • pnpm build:ui

The two new tests fail in both request orders without the cache-key change and pass with it.

nathanlentz pushed a commit that referenced this pull request Oct 7, 2026
### What?

Cache the client field schema map per admin language.

### Why?

`getClientSchemaMap` keyed its process-wide cache by entity slug only.
The map is built from the per-language client config and runs label
functions with the request's `i18n`, so whichever language filled the
cache first was served to everyone. That is why richText fields and
fields with a custom `Field` component (rendered through form state)
showed labels in another language (#18583).

While testing this I found a second piece: `buildClientFieldSchemaMap`
sets the translated password/confirm-password labels on a module-level
`baseAuthFields` array and puts those same objects into the map. With
per-language maps, building the French map would rename the password
fields in the cached English one.

### How?

- Add `i18n.language` to the cache key, the same way `getClientConfig`
caches per language.
- Build the auth fields as new objects on each call instead of mutating
the shared ones.

New `getClientSchemaMap.spec.ts`: both tests fail on `main`, and the
auth test still fails with only the cache key change.
`packages/ui/src/utilities` unit specs pass (149).

#18168 changes the same cache key for auth state; whichever lands second
needs a one-line rebase. The same cache key exists on `3.x`.

Fixes #18583

Co-authored-by: Claude Opus 5.5 <[email protected]>
@denolfe denolfe added the v3 label Oct 15, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants