@sanity/assist 1.0.1 → 1.0.2

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/assist",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -7,7 +7,7 @@ import {
7
7
  AssistField,
8
8
  instructionParam,
9
9
  } from '../../types'
10
- import {useEffect, useMemo} from 'react'
10
+ import {useEffect, useMemo, useRef} from 'react'
11
11
  import {
12
12
  FormCallbacksProvider,
13
13
  FormCallbacksValue,
@@ -39,6 +39,9 @@ export function AssistDocumentForm(props: ObjectInputProps) {
39
39
  const id = value?._id
40
40
  const fields = value?.fields
41
41
 
42
+ // need this to not fire onChange twice in React strict mode
43
+ const onChangeCalled = useRef(false)
44
+
42
45
  const targetDocumentType = useMemo(() => {
43
46
  if (!id) {
44
47
  return undefined
@@ -88,8 +91,9 @@ export function AssistDocumentForm(props: ObjectInputProps) {
88
91
  }
89
92
  }, [title, documentSchema, onChange, id])
90
93
 
94
+ const fieldMissing = fields?.find((f) => f._key !== pathKey)
91
95
  useEffect(() => {
92
- if (activePath || !pathKey) {
96
+ if (onChangeCalled.current || !fieldMissing || activePath || !pathKey) {
93
97
  return
94
98
  }
95
99
  onChange([
@@ -106,7 +110,8 @@ export function AssistDocumentForm(props: ObjectInputProps) {
106
110
  ['fields', -1]
107
111
  ),
108
112
  ])
109
- }, [activePath, onChange, pathKey])
113
+ onChangeCalled.current = true
114
+ }, [activePath, onChange, pathKey, fieldMissing])
110
115
 
111
116
  const {onPathOpen, ...formCallbacks} = useFormCallbacks()
112
117