Skip to content

Commit ea76ca0

Browse files
fix(ui): prevent globals crash with arrays fields when lock state user is undefined in handleDocumentLocking (#15259)
### What Fixes crash when adding items to array fields in Globals that throws "Cannot read properties of null (reading 'id')". ### Why When a locked document's user relationship isn't populated (deleted user, etc.), `lockedState.user` can be `undefined`. The code tried to access `.id` on this without checking, causing the crash. ### How - Made `user` field optional in `LockedState` type - Added null check before accessing `lockedState.user.id` in `handleDocumentLocking` - Only process lock state when a valid user exists Closes #14915 --------- Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
1 parent 7043e3f commit ea76ca0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/ui/src/utilities/buildFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { handlePreview } from './handlePreview.js'
2222
export type LockedState = {
2323
isLocked: boolean
2424
lastEditedAt: string
25-
user: ClientUser | number | string
25+
user?: ClientUser | number | string
2626
}
2727

2828
type BuildFormStateSuccessResult = {

packages/ui/src/views/Edit/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function DefaultEditView({
209209
? documentLockState.current?.user?.id
210210
: documentLockState.current?.user
211211

212-
if (lockedState) {
212+
if (lockedState && lockedState.user) {
213213
const lockedUserID =
214214
typeof lockedState.user === 'string' || typeof lockedState.user === 'number'
215215
? lockedState.user

0 commit comments

Comments
 (0)