Skip to content

[ai-assist] Studio crashes ("Expected path segment to be an object with a _key property") after opening instructions for a nested field: dotted _key in pane path param #2026

Description

@dutsik

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):

  1. 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.
  2. 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

  1. Schema with an object field, e.g. title: {type: 'object', fields: [{name: 'de', type: 'string'}, {name: 'en', type: 'string'}]}.
  2. 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.
  3. Close the inspector.
  4. Click the ✨ button on any top-level field (e.g. a boolean).
  5. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions