Sanity Studio v3.53.0: Improved integration for TypeGen in Sanity Client + improvements and bugfixes

Install or upgrade Sanity Studio

To initiate a new Sanity Studio project or upgrade an existing one, please refer to our comprehensive guide on Installing and Upgrading Sanity Studio.

If you are updating from a version earlier than 3.37.0, you should also check out this article to ensure your dependencies are up to date.

Improved Sanity Client and TypeGen integration

With the new defineQuery utility it is no longer necessary to pass generics into client.fetch calls for the sanity typegen command to generate type definitions for query results. 🥳 Update @sanity/client to v6.21.0 or later, then add "overloadClientMethods": true to your sanity-typegen.json configuration file, and finally wrap your query strings in the new defineQuery utility method from groq:

import {createClient} from '@sanity/client'
-import groq from 'groq'
+import {defineQuery} from 'groq'
-import type { SettingsQueryResult } from "~/sanity.types";

const client = createClient({ /* ... */ })

-const settingsQuery = groq`
+const settingsQuery = defineQuery(`
*[_type == "settings"][0]
-`
+`)

-const settings = await client.fetch<SettingsQueryResult>(settingsQuery)
+const settings = await client.fetch(settingsQuery)

Huge thanks to @romeovs for championing this feature!

🐛 Notable bugfixes

Fixes default messaging in the environment variable file created by sanity init --env

Fixes an issue that could cause wrong list counts in the Portable Text Editor

Fixes an issue that could cause malformed strings to appear in documents passed to migration scripts

Fixes several issues that could cause "missing context" errors in certain environments

Fixes an issue causing the Presence avatar overlays on form fields not to appear when Sanity Studio is embedded in a React 19 app