fix(visual-editing-csm): decode all-numeric _key as a key, not an array index - #3564
Open
voidhrithik wants to merge 2 commits into
Open
fix(visual-editing-csm): decode all-numeric _key as a key, not an array index#3564voidhrithik wants to merge 2 commits into
voidhrithik wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 819c8a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@voidhrithik is attempting to deploy a commit to the Sanity Sandbox Team on Vercel. A member of the Team first needs to authorize it. |
…ay index pathToUrlString serialises an array index and a _key to the same form, and RE_SEGMENT_WITH_INDEX matched any run of digits, so a _key like 342330179449 decoded back as a number. decodeSanityString then stringified it to sections[342330179449], hasExplicitKey came out false, and drag-and-drop reorder ran remove(~~"342330179449"), which truncates to -1267204231 and matches no element. Cap the index pattern at 9 digits. A longer all-digit segment cannot index any real array, so it now falls through to RE_SEGMENT_WITH_KEY. Fixes sanity-io#3467
voidhrithik
force-pushed
the
fix/numeric-array-key-reorder
branch
from
July 29, 2026 18:10
883107a to
06e4a14
Compare
Author
|
@stipsan could you approve the CI run when you get a chance? It's behind the first-time-contributor gate, so nothing has run yet. I checked it against main too, where the all-digit keys come back with Not chasing a review, just the button. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3467.
An all-numeric
_keywas decoding as an array index, so reordering one of those items threwFound no matching array element to replace.The encode side writes an index and a
_keyidentically:which leaves
urlStringToPathto break the tie, andRE_SEGMENT_WITH_INDEXmatched any run of digits and got tested first. So the key came back a number,decodeSanityStringstringified it tosections[342330179449],getArrayItemKeyAndParentPathfound no_key, and the reorder ranremove(~~"342330179449"), which int32-truncates to-1267204231.The fix is the quantifier:
Nine digits max, so anything longer falls through to the key branch. That covers every
randomKeyoutput, since those are 12 characters. Leading-zero keys already worked. A short hand-authored key like12345stays ambiguous, and no magnitude rule fixes that one, so this keeps to therandomKeycase the issue reports.I started out with a
MAX_ARRAY_INDEX = 2 ** 32 - 2constant and a second condition in the loop. Same behaviour, four more lines and a second place to look, so I dropped it. Happy to put it back if you would rather have the bound spelled out than the regex short.Testing
Three cases added to
urlStringToPath.test.ts. The existingarray:123assertion still holds.I also ran the chain from the issue,
createDataAttribute(['sections', {_key}])throughdecodeSanityNodeDatatogetArrayItemKeyAndParentPath, against this branch and against main. On main:All six pass on this branch, and
['items', 0],['items', 5],['items', 999999999]decode as indexes either way.