Skip to content

Commit

Permalink
fix(core): skip updating focusPath state if unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 19, 2024
1 parent 4729e84 commit 26bde34
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 26bde34

Please sign in to comment.