Which plugin is affected?
@sanity/assist
Describe the bug
Opening the AI Assist instructions inspector for a nested field (a field inside an object, e.g. description.de in a localeText-style wrapper) puts path=fields[_key=="description.de"] into the document pane URL. After closing the inspector and opening it again for any other field, the Studio crashes with:
Error: Expected path segment to be an object with a _key property
at getArrayFieldsetAndFieldGroupOperations
at getObjectFieldsetAndFieldGroupOperations
at getFieldsetAndFieldGroupOperations
at getExpandOperations
Root cause (two parts, both outside userland):
- The plugin uses the target field path (
description.de) as the _key of the entry in the fields[] array of the sanity.assist.schemaType.annotations document, and passes ["fields", {_key: "description.de"}] to the document pane's onPathOpen, so it is serialized into the pane path param.
fromString in @sanity/util/paths tokenizes on . before it recognizes [_key=="…"], so a key that contains a dot is split into plain string segments:
const {fromString} = require('@sanity/util/paths')
fromString('fields[_key=="description.de"]')
// => ["fields", "_key==\"description", "de\""] <-- broken
fromString('fields[_key=="title"]')
// => ["fields", {"_key": "title"}] <-- fine
When the stale path param is applied to the inspector form on remount, getArrayFieldsetAndFieldGroupOperations receives the string segment _key=="description where a key segment is expected and throws.
Top-level fields (keys without a dot, e.g. title, booleans) never hit this. Any schema with localized wrapper objects ({de, en, …}) hits it constantly.
I checked @sanity/util@6.16.0: the rePropName regex is unchanged, so the parser part is not fixed upstream either.
To reproduce
- Schema with an object field, e.g.
title: {type: 'object', fields: [{name: 'de', type: 'string'}, {name: 'en', type: 'string'}]}.
- Open a document, click the AI Assist ✨ button on the inner field
title.de (or description.de). The inspector opens; the URL now contains path=fields%5B_key%3D%3D%22title.de%22%5D.
- Close the inspector.
- Click the ✨ button on any top-level field (e.g. a boolean).
- Studio error boundary:
Expected path segment to be an object with a _key property.
Example resulting URL:
/structure/content;ch_shopping;poi_806389449,path=fields[_key=="description.de"],pathKey=description.en,inspect=ai-assistance
Expected behavior
Opening instructions for a nested field should not break subsequent inspector opens. Either the plugin should not use dotted paths as _keys that end up in the pane path param (e.g. use the existing patchableKey-style sanitized key, or don't call the pane's onPathOpen with inspector-internal paths), or fromString should respect quotes inside [_key=="…"].
Screenshots or recordings
Stack (Sanity 5.23.0 dev build):
Error: Expected path segment to be an object with a _key property
at getArrayFieldsetAndFieldGroupOperations (chunk-KDAJ5NE2.js:222732:11)
at getObjectFieldsetAndFieldGroupOperations (chunk-KDAJ5NE2.js:222725:73)
at getFieldsetAndFieldGroupOperations (chunk-KDAJ5NE2.js:222705:86)
at getExpandOperations (chunk-KDAJ5NE2.js:222701:8)
Environment
- Sanity Studio version: 5.23.0 (
@sanity/util 5.23.0)
- Plugin version:
@sanity/assist 6.0.5 (README/code of 6.2.1 shows the same _key handling)
- React 19.2.3
- Browser: Chrome
- Operating system: Linux (WSL2) / Windows
Additional context
Reproduced with a plain assist() plugin config (no translate options, no custom field components), so it is independent of any field-level translation setup.
Workaround for editors: remove the path=… part from the URL (or reopen the document from the list) after the crash, and avoid opening "Manage instructions" from an inner field of a localized object.
Which plugin is affected?
@sanity/assistDescribe the bug
Opening the AI Assist instructions inspector for a nested field (a field inside an object, e.g.
description.dein alocaleText-style wrapper) putspath=fields[_key=="description.de"]into the document pane URL. After closing the inspector and opening it again for any other field, the Studio crashes with:Root cause (two parts, both outside userland):
description.de) as the_keyof the entry in thefields[]array of thesanity.assist.schemaType.annotationsdocument, and passes["fields", {_key: "description.de"}]to the document pane'sonPathOpen, so it is serialized into the panepathparam.fromStringin@sanity/util/pathstokenizes on.before it recognizes[_key=="…"], so a key that contains a dot is split into plain string segments:When the stale
pathparam is applied to the inspector form on remount,getArrayFieldsetAndFieldGroupOperationsreceives the string segment_key=="descriptionwhere a key segment is expected and throws.Top-level fields (keys without a dot, e.g.
title, booleans) never hit this. Any schema with localized wrapper objects ({de, en, …}) hits it constantly.I checked
@sanity/util@6.16.0: therePropNameregex is unchanged, so the parser part is not fixed upstream either.To reproduce
title: {type: 'object', fields: [{name: 'de', type: 'string'}, {name: 'en', type: 'string'}]}.title.de(ordescription.de). The inspector opens; the URL now containspath=fields%5B_key%3D%3D%22title.de%22%5D.Expected path segment to be an object with a _key property.Example resulting URL:
Expected behavior
Opening instructions for a nested field should not break subsequent inspector opens. Either the plugin should not use dotted paths as
_keys that end up in the panepathparam (e.g. use the existingpatchableKey-style sanitized key, or don't call the pane'sonPathOpenwith inspector-internal paths), orfromStringshould respect quotes inside[_key=="…"].Screenshots or recordings
Stack (Sanity 5.23.0 dev build):
Environment
@sanity/util5.23.0)@sanity/assist6.0.5 (README/code of 6.2.1 shows the same_keyhandling)Additional context
Reproduced with a plain
assist()plugin config (notranslateoptions, no custom field components), so it is independent of any field-level translation setup.Workaround for editors: remove the
path=…part from the URL (or reopen the document from the list) after the crash, and avoid opening "Manage instructions" from an inner field of a localized object.