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
- Configure the plugin with a locale, for example
media({ locales: [{ id: 'en', title: 'English' }] }).
- Upload an image and set its English alt text to something like "brass faucet".
- In the media browser, add the "Alt text" filter, choose "includes" and type "faucet". No results.
- 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.
Which plugin is affected?
sanity-plugin-mediaDescribe the bug
When the
localesoption 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 barealtTextfield. GROQmatchagainst an object never matches, so you always get zero results.To reproduce
media({ locales: [{ id: 'en', title: 'English' }] }).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
main(6.0.5)Additional context
The cause is in
plugins/sanity-plugin-media/src/utils/constructFilter.ts. The "Alt text" facet buildsaltText match '*query*', and the main search addsaltTextto the match array[_id, altText, creditLine, description, ...] match '*query*'. Both treataltTextas a string, but withlocalesset it is an object, so neither matches.The search path (
searchFacetsplusconstructFilter) has no locale awareness, unlike the edit form which readslocalesfromToolOptionsContext. A fix would thread the configured locales in so the localized string facets and the main search targetaltText[<locale>]for each configured locale. Happy to open a PR if that direction works for you.