diff --git a/dev/test-studio/schema/debug/patchOnMount.tsx b/dev/test-studio/schema/debug/patchOnMount.tsx new file mode 100644 index 00000000000..1595b5317bb --- /dev/null +++ b/dev/test-studio/schema/debug/patchOnMount.tsx @@ -0,0 +1,30 @@ +import {defineType} from '@sanity/types' +import {useEffect, useRef} from 'react' +import {set} from 'sanity' + +export const patchOnMountDebug = defineType({ + type: 'document', + name: 'patchOnMountDebug', + fields: [ + { + type: 'string', + name: 'title', + }, + ], + components: { + // eslint-disable-next-line func-name-matching + input: function PatchOnMountInput(props) { + const {onChange} = props + const mounted = useRef(false) + + useEffect(() => { + if (!mounted.current) { + onChange(set(`${Math.random()}`, ['title'])) + mounted.current = true + } + }, [onChange]) + + return props.renderDefault(props) + }, + }, +}) diff --git a/dev/test-studio/schema/index.ts b/dev/test-studio/schema/index.ts index b579539513f..ebc53f54904 100644 --- a/dev/test-studio/schema/index.ts +++ b/dev/test-studio/schema/index.ts @@ -53,6 +53,7 @@ import localeString from './debug/localeString' import manyFieldsTest from './debug/manyFieldsTest' import notitle from './debug/notitle' import {objectsDebug} from './debug/objectsDebug' +import {patchOnMountDebug} from './debug/patchOnMount' import poppers from './debug/poppers' import presence, {objectWithNestedArray} from './debug/presence' import previewImageUrlTest from './debug/previewImageUrlTest' @@ -238,6 +239,7 @@ export const schemaTypes = [ recursiveObjectTest, recursiveObject, recursivePopover, + patchOnMountDebug, simpleArrayOfObjects, simpleReferences, reservedFieldNames, diff --git a/dev/test-studio/structure/constants.ts b/dev/test-studio/structure/constants.ts index ffcdea6447a..75b4b5ba8e5 100644 --- a/dev/test-studio/structure/constants.ts +++ b/dev/test-studio/structure/constants.ts @@ -55,6 +55,7 @@ export const DEBUG_INPUT_TYPES = [ 'fieldsetsTest', 'fieldValidationInferReproDoc', 'focusTest', + 'patchOnMountDebug', 'formInputDebug', 'initialValuesTest', 'inspectorsTest',