@sanity/ui 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -119,7 +119,7 @@
119
119
  "@sanity/color": "^3.0.6",
120
120
  "@sanity/icons": "^3.7.4",
121
121
  "csstype": "^3.1.3",
122
- "framer-motion": "^12.23.12",
122
+ "framer-motion": "^12.23.15",
123
123
  "react-compiler-runtime": "19.1.0-rc.3",
124
124
  "react-refractor": "^4.0.0",
125
125
  "use-effect-event": "^2.0.3"
@@ -10,6 +10,7 @@ import {
10
10
  MouseEvent,
11
11
  ReactNode,
12
12
  Ref,
13
+ startTransition,
13
14
  useCallback,
14
15
  useEffect,
15
16
  useImperativeHandle,
@@ -191,7 +192,16 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
191
192
  const inputElementRef = useRef<HTMLInputElement | null>(null)
192
193
  const listBoxElementRef = useRef<HTMLDivElement | null>(null)
193
194
  // Element refs that need to be accessed during render
194
- const [inputElement, setInputElement] = useState<HTMLInputElement | null>(null)
195
+ const [inputElement, _setInputElement] = useState<HTMLInputElement | null>(null)
196
+ /**
197
+ * The startTransition wrapper here is to avoid an issue when on React 18 where this error can happen:
198
+ * >Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
199
+ * This doesn't happen on React 19 due to automatic batching of all state updates, the startTransition wrapper here gives a type of batching for 18 users in a way that still works with 19.
200
+ * NOTE: The startTransition wrapper is not needed in UI v4, since the baseline there is React 19.
201
+ */
202
+ const setInputElement = useCallback((node: HTMLInputElement | null) => {
203
+ startTransition(() => _setInputElement(node))
204
+ }, [])
195
205
 
196
206
  // Value refs
197
207
  const listFocusedRef = useRef(false)
@@ -1,6 +1,6 @@
1
1
  import {ToggleArrowRightIcon} from '@sanity/icons'
2
2
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
3
- import {useCallback, useEffect, useId, useMemo, useRef, useState} from 'react'
3
+ import {startTransition, useCallback, useEffect, useId, useMemo, useRef, useState} from 'react'
4
4
  import {styled} from 'styled-components'
5
5
 
6
6
  import {Box, BoxProps, Flex, Text} from '../../primitives'
@@ -65,7 +65,17 @@ export function TreeItem(
65
65
  weight,
66
66
  ...restProps
67
67
  } = props
68
- const [rootElement, setRootElement] = useState<HTMLLIElement | null>(null)
68
+ const [rootElement, _setRootElement] = useState<HTMLLIElement | null>(null)
69
+ /**
70
+ * The startTransition wrapper here is to avoid an issue when on React 18 where this error can happen:
71
+ * >Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
72
+ * This doesn't happen on React 19 due to automatic batching of all state updates, the startTransition wrapper here gives a type of batching for 18 users in a way that still works with 19.
73
+ * NOTE: The startTransition wrapper is not needed in UI v4, since the baseline there is React 19.
74
+ */
75
+ const setRootElement = useCallback((node: HTMLLIElement | null) => {
76
+ startTransition(() => _setRootElement(node))
77
+ }, [])
78
+
69
79
  const treeitemRef = useRef<HTMLDivElement | null>(null)
70
80
  const tree = useTree()
71
81
  const {path, registerItem, setExpanded, setFocusedElement} = tree