Array fields in Globals crash with 'Cannot read properties of null (reading id)' in handleDocumentLocking
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 null
The 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
Same problem here – error is so generic it was impossible to debug...
I can take a look at this. The fix seems straightforward - adding a
null-check for lockedState.user before accessing .id.
Will reproduce locally and submit a PR.
🚀 This is included in version v3.74.0
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.