From 26bde34cf0631d36aae586c9e20ff60457427b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 19 Sep 2024 10:41:36 +0200 Subject: [PATCH] fix(core): skip updating focusPath state if unchanged --- .../structure/panes/document/DocumentPaneProvider.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx index f15f16fffcf..eca850ea758 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx @@ -8,7 +8,7 @@ import { type SanityDocumentLike, } from '@sanity/types' import {useToast} from '@sanity/ui' -import {fromString as pathFromString, resolveKeyedPath} from '@sanity/util/paths' +import {fromString as pathFromString, pathFor, resolveKeyedPath} from '@sanity/util/paths' import {omit, throttle} from 'lodash' import {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react' import deepEquals from 'react-fast-compare' @@ -609,10 +609,11 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { ) const handleFocus = useCallback( - (nextFocusPath: Path, payload?: OnPathFocusPayload) => { - setFocusPath(nextFocusPath) - if (!deepEquals(focusPathRef.current, nextFocusPath)) { - setOpenPath(nextFocusPath.slice(0, -1)) + (_nextFocusPath: Path, payload?: OnPathFocusPayload) => { + const nextFocusPath = pathFor(_nextFocusPath) + if (nextFocusPath !== focusPathRef.current) { + setFocusPath(pathFor(nextFocusPath)) + setOpenPath(pathFor(nextFocusPath.slice(0, -1))) focusPathRef.current = nextFocusPath onFocusPath?.(nextFocusPath) }