Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sanity): throw a better error if onChange called during initial render #8165

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ export function TestForm(props: TestFormProps) {
}, [setFocusPath])

const patchRef = useRef<(event: PatchEvent) => void>(() => {
throw new Error('Nope')
throw new Error(
'Attempted to patch the Sanity document during initial render. Input components should only call `onChange()` in an effect or a callback.',
)
})

patchRef.current = (event: PatchEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export function useTasksFormBuilder(options: TasksFormBuilderOptions): TasksForm

const {patch} = useDocumentOperation(documentId, documentType)
const patchRef = useRef<(event: PatchEvent) => void>(() => {
throw new Error('Nope')
throw new Error(
'Attempted to patch the Sanity document during initial render. Input components should only call `onChange()` in an effect or a callback.',
)
})
useEffect(() => {
patchRef.current = (event: PatchEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
)

const patchRef = useRef<(event: PatchEvent) => void>(() => {
throw new Error('Nope')
throw new Error(
'Attempted to patch the Sanity document during initial render. Input components should only call `onChange()` in an effect or a callback.',
)
})
useEffect(() => {
patchRef.current = (event: PatchEvent) => {
Expand Down
Loading