Skip to content

sanity-plugin-media: alt text search returns nothing when locales are configured #1699

Description

@skezo

Which plugin is affected?

sanity-plugin-media

Describe the bug

When the locales option is set, searching by alt text returns nothing. It affects both the "Alt text" search filter and the main search field, and the same goes for title, description and creditLine.

With locales configured the plugin stores these fields as per-locale objects (altText: { en: "...", "zh-CN": "..." }), but search still queries the bare altText field. GROQ match against an object never matches, so you always get zero results.

To reproduce

  1. Configure the plugin with a locale, for example media({ locales: [{ id: 'en', title: 'English' }] }).
  2. Upload an image and set its English alt text to something like "brass faucet".
  3. In the media browser, add the "Alt text" filter, choose "includes" and type "faucet". No results.
  4. Type "faucet" in the main search field. Also nothing, since it only matches filename, id and url.

Expected behavior

Alt text search finds the image using the value stored for a configured locale.

Screenshots or recordings

Not applicable, it is reproducible from the query alone.

Environment

  • Sanity Studio version: 6.5.0
  • Plugin version: 5.0.13, and still present on current main (6.0.5)
  • Browser: any
  • Operating system: any

Additional context

The cause is in plugins/sanity-plugin-media/src/utils/constructFilter.ts. The "Alt text" facet builds altText match '*query*', and the main search adds altText to the match array [_id, altText, creditLine, description, ...] match '*query*'. Both treat altText as a string, but with locales set it is an object, so neither matches.

The search path (searchFacets plus constructFilter) has no locale awareness, unlike the edit form which reads locales from ToolOptionsContext. A fix would thread the configured locales in so the localized string facets and the main search target altText[<locale>] for each configured locale. Happy to open a PR if that direction works for you.

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