Skip to content

Commit 0f7d444

Browse files
authored
fix(next): safely checks user within useEffect (#8524)
1 parent ca90d2b commit 0f7d444

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/next/src/views/Edit/Default/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export const DefaultEditView: React.FC = () => {
319319
// Unlock the document only if we're actually navigating away from the document
320320
if (documentId && documentIsLocked && !isStayingWithinDocument) {
321321
// Check if this user is still the current editor
322-
if (documentLockStateRef.current?.user?.id === user.id) {
322+
if (documentLockStateRef.current?.user?.id === user?.id) {
323323
void unlockDocument(id, collectionSlug ?? globalSlug)
324324
setDocumentIsLocked(false)
325325
setCurrentEditor(null)
@@ -333,7 +333,7 @@ export const DefaultEditView: React.FC = () => {
333333
globalSlug,
334334
id,
335335
unlockDocument,
336-
user.id,
336+
user,
337337
setCurrentEditor,
338338
isLockingEnabled,
339339
documentIsLocked,

packages/next/src/views/LivePreview/index.client.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ const PreviewView: React.FC<Props> = ({
258258
// Unlock the document only if we're actually navigating away from the document
259259
if (documentId && documentIsLocked && !isStayingWithinDocument) {
260260
// Check if this user is still the current editor
261-
if (documentLockStateRef.current?.user?.id === user.id) {
261+
if (documentLockStateRef.current?.user?.id === user?.id) {
262262
void unlockDocument(id, collectionSlug ?? globalSlug)
263263
setDocumentIsLocked(false)
264264
setCurrentEditor(null)
@@ -272,7 +272,7 @@ const PreviewView: React.FC<Props> = ({
272272
globalSlug,
273273
id,
274274
unlockDocument,
275-
user.id,
275+
user,
276276
setCurrentEditor,
277277
isLockingEnabled,
278278
documentIsLocked,

0 commit comments

Comments
 (0)