Repository navigation
Description
Describe the Bug
In next dev, after editing the Payload config (for example adding a field to a collection), the edit view sometimes keeps rendering the form from the previous config until the dev server is restarted. The new field does not show in the form, and the server log can show:
Cannot use 'in' operator to search for 'hidden' in undefined
The cause is the module-level caches in @payloadcms/ui:
packages/ui/src/utilities/getClientConfig.ts(client config per language)packages/ui/src/utilities/getSchemaMap.ts(field schema map per collection / global / widget)packages/ui/src/utilities/getClientSchemaMap.ts(client field schema map per language and entity)
They are not tied to the config they were built from. They are only invalidated through the global flags (global._payload_doNotCacheClientConfig, _payload_doNotCacheSchemaMap, _payload_doNotCacheClientSchemaMap) that reload() sets once. After a reload, a request that is still rendering with the previous config object can be the first to reach these functions: it consumes the flag and fills the cache with maps built from the old config. Every later request, which already passes the new config, then gets the stale cached entry. The form for the new field gets a client field map without that field, so the field is missing (and lookups such as 'hidden' in field hit undefined).
A related detail: reload() replaces global._payload_clientConfigs / _payload_schemaMap / _payload_clientSchemaMap, but the modules hold their own reference read at import time, so that reset does not reach them either; only the flags do.
Link to the code that reproduces this issue
(The branch contains the fix and unit tests in packages/ui/src/utilities/*.spec.ts. The new tests fail on main: they call each function with config A and then with a different config B and get A's result back.)
Reproduction Steps
- Start any project (e.g. the
_communitytest config) withnext devand open a document's edit view in the admin panel. - Add a new field to that collection in the config and save the file, so the config reloads.
- Reload the edit view (with more than one request in flight around the reload, e.g. the page plus a form-state server function, or two tabs open).
- The new field is sometimes missing from the form, and stays missing on further reloads until the dev server is restarted. The server log may show
Cannot use 'in' operator to search for 'hidden' in undefined.
The timing depends on which request reaches the cache first after the reload, so it does not happen on every edit; it is more frequent on larger configs where a render takes longer.
Unit-level reproduction (fails on main):
const previous = getSchemaMap({ collectionSlug: 'pages', config: configA, i18n })
const next = getSchemaMap({ collectionSlug: 'pages', config: configB, i18n }) // configB adds a field
expect(next.has('pages.summary')).toBe(true) // fails: returns the map built from configAWhich area(s) are affected?
area: ui
Environment Info
Payload: 4.x (main)
Next.js: 16 (next dev)
Node.js: 24
OS: Linux / macOS
Development mode only (config reload / HMR). Production builds load the config once, so the caches never see a second config.
Activity