From 9411f1c747735f856c6d216e50e350532dda82f6 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Fri, 13 Dec 2024 19:34:40 +0100 Subject: [PATCH] fix(PaneContainer): remove unsafe ref access during render --- .../structure/panes/documentList/PaneContainer.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx b/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx index 92d18add010..1c3091bfdd2 100644 --- a/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx +++ b/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx @@ -1,6 +1,6 @@ import {Card, Code} from '@sanity/ui' import {isEqual} from 'lodash' -import {memo, useMemo, useRef} from 'react' +import {memo, useMemo, useState} from 'react' import { EMPTY_ARRAY, type GeneralDocumentListLayoutKey, @@ -49,11 +49,12 @@ const addSelectedStateToMenuItems = (options: { } export function useShallowUnique(value: ValueType): ValueType { - const valueRef = useRef(value) - if (!shallowEquals(valueRef.current, value)) { - valueRef.current = value + const [current, setCurrent] = useState(value) + if (!shallowEquals(current, value)) { + setCurrent(value) + return value } - return valueRef.current + return current } /**