@sanity/assist 1.0.1 → 1.0.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/assist",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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 fieldExists = fields?.some((f) => f._key === pathKey)
91
95
  useEffect(() => {
92
- if (activePath || !pathKey) {
96
+ if (onChangeCalled.current || fieldExists || 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, fieldExists])
110
115
 
111
116
  const {onPathOpen, ...formCallbacks} = useFormCallbacks()
112
117
 
@@ -75,6 +75,18 @@ describe('serializeSchema', () => {
75
75
  ])
76
76
  })
77
77
 
78
+ test('should not serialize slug type', () => {
79
+ const schema = Schema.compile({
80
+ name: 'test',
81
+ types: mockStudioTypes,
82
+ })
83
+
84
+ const serializedTypes = serializeSchema(schema, {leanFormat: true})
85
+
86
+ //everything excluded directly or indirectly
87
+ expect(serializedTypes).toEqual([])
88
+ })
89
+
78
90
  test('should not serialize excluded fields or types or types with every member excluded', () => {
79
91
  const options: AssistOptions = {aiWritingAssistance: {exclude: true}}
80
92