This repository was archived by the owner on Feb 3, 2026. It is now read-only.
fix: initialize array fields with empty array to prevent insert patch error#105
Merged
stipsan merged 3 commits intosanity-io:mainfrom Oct 13, 2025
Merged
fix: initialize array fields with empty array to prevent insert patch error#105stipsan merged 3 commits intosanity-io:mainfrom
stipsan merged 3 commits intosanity-io:mainfrom
Conversation
- Fix document-level add locale button for Portable Text fields - Detect array-type fields and initialize with [] instead of undefined - Add paste operation support for empty internationalized fields - Field-level and unstable_fieldAction buttons remain unchanged Resolves 'Attempt to apply insert patch to non-array value' error that occurred only with document-level locale addition buttons.
…edInput - Ensure wrapped onChange handler correctly processes both single and multiple patch operations. - Add checks for empty or uninitialized Portable Text fields to prevent errors during paste operations. - Improve patch transformation logic to handle nested structures more robustly. This update addresses issues related to applying insert patches to non-existent structures, ensuring a smoother user experience when interacting with internationalized fields.
Contributor
Author
|
@SimeonGriggs @thebiggianthead can you take a look at the issue and PR? thanks. |
stipsan
approved these changes
Sep 26, 2025
Member
stipsan
left a comment
There was a problem hiding this comment.
Looks good, fix those linter errors and I'll merge and release 👍
* Initial plan * Initial progress report - linting errors identified Co-authored-by: wiiiimm <179761+wiiiimm@users.noreply.github.com> * fix: resolve all ESLint errors Co-authored-by: wiiiimm <179761+wiiiimm@users.noreply.github.com> * fix: add explicit return types and resolve all linter warnings Co-authored-by: wiiiimm <179761+wiiiimm@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wiiiimm <179761+wiiiimm@users.noreply.github.com>
Contributor
Author
|
@stipsan just fixed all lint errors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where pasting content into empty internationalized Portable Text fields causes an error: "Attempt to apply insert patch to non-array value".
The Problem
The bug only affects the document-level "Add translation" button when
buttonLocationsincludes'document'. Field-level buttons andunstable_fieldActionbuttons work correctly.When using the document-level button to add a new language entry for array-based fields (like Portable Text), the
valuefield was initialized asundefined. This causes Sanity's patch operations to fail when trying to insert content into what it expects to be an array.The Solution
The fix modifies two components:
1.
DocumentAddButtons.tsxgetInitialValueForTypefunction that uses theuseSchemahook to detect array-based fields[]instead ofundefinedjsonTypeis 'array'2.
InternationalizedInput.tsxwrappedOnChangehandler to intercept problematic insert patchesTesting
Tested locally with:
internationalizedArrayBodyfieldsRelated Issue
Fixes #104
Changes Made
src/components/DocumentAddButtons.tsxto detect array fields and initialize them properlysrc/components/InternationalizedInput.tsxto handle paste operations into empty fields