-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
Description
Description
When adding items to an array field in a Global config, the UI crashes with:
Error in queued function: TypeError: Cannot read properties of null (reading 'id')
This does not occur with array fields in Collections - only Globals.
Payload Version
3.68.3
Steps to Reproduce
- Create a Global with an array field:
export const GlobalSettings: GlobalConfig = {
slug: "global-settings",
fields: [
{
name: "alternateName",
type: "array",
label: "Alternate Names",
fields: [
{
name: "name",
type: "text",
label: "Name",
},
],
},
],
};- Navigate to
/admin/globals/global-settings - Click "Add Alternate Name" to add an array item
- Error occurs immediately
Root Cause
The bug is in @payloadcms/ui/dist/views/Edit/index.js in the handleDocumentLocking callback (around line 186-187):
if (lockedState) {
const lockedUserID = typeof lockedState.user === 'string' || typeof lockedState.user === 'number'
? lockedState.user
: lockedState.user.id; // BUG: crashes if lockedState.user is nullThe code checks if lockedState is truthy, but assumes lockedState.user is also defined. For Globals, lockedState can exist while lockedState.user is null, causing the crash.
Suggested Fix
Add null checking for lockedState.user:
if (lockedState && lockedState.user != null) {
const lockedUserID = typeof lockedState.user === 'string' || typeof lockedState.user === 'number'
? lockedState.user
: (lockedState.user && typeof lockedState.user === 'object' ? lockedState.user.id : null);
if (lockedUserID == null) return;
// ... rest of the function
}Workaround
Apply a patch to @payloadcms/ui with the fix above using pnpm's patchedDependencies or similar.
Environment
- Node: 20.x
- Database: PostgreSQL (via @payloadcms/db-postgres)
- OS: Linux