Sanity Studio hang fix
Stops Sanity Studio customisations opening a listener per document, so Studio stays responsive.
Claude's review
8/10 Specific Sanity Studio listener budget guidance with detection and fixes.
We asked Claude the question you would ask: would I be glad I installed this? We only sell skills it rates 7 or higher.
In detail
Keep Sanity Studio customizations (custom tools, inputs, document views, structure and plugins) from opening a real-time listener per document, which fills the browser's shared connection to the Sanity API and makes Studio hang when editors have several tabs open. Use when writing or reviewing Studio code that shows live data, validation or permissions for many documents (lists, boards, tables, review queues, dashboards); when code calls useValidationStatus, useDocumentPairPermissions, documentStore.listenQuery, listenQuery, client.listen or useListeningQuery from sanity-plugin-utils; or when editors report Studio stuck on its loading spinner or "Trying to connect…", "Could not establish EventSource connection", or that closing other Studio tabs fixes it.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: sanity-studio-listeners
description: Keep Sanity Studio customizations (custom tools, inputs, document views, structure and plugins) from opening a real-time listener per document, which fills the browser's shared connection to the Sanity API and makes Studio hang when editors have several tabs open. Use when writing or reviewing Studio code that shows live data, validation or permissions for many documents (lists, boards, tables, review queues, dashboards); when code calls useValidationStatus, useDocumentPairPermissions, documentStore.listenQuery, listenQuery, client.listen or useListeningQuery from sanity-plugin-utils; or when editors report Studio stuck on its loading spinner or "Trying to connect…", "Could not establish EventSource connection", or that closing other Studio tabs fixes it.
---
# Studio listeners
Studio keeps data live with listeners: long-lived requests that stream changes from the Sanity
API. A browser runs at most 100 requests at a time on its connection to the API, and every Studio
tab shares that connection (on HTTP/1.1, browsers open only 6 connections per host). A listener
holds its slot for as long as it is open, and a Studio tab normally has 6 to 12 open.
Code that opens a listener for every item it renders multiplies by items, then by tabs. Once the
slots run out, every request in every tab waits: the newest tab hangs on its spinner, documents and
previews stop loading, and a tab that does load can show missing validation errors. The goal is
that your code adds a constant number of listeners, never one per item.
Studio already keeps one listener open that follows every document in the dataset. Read documents,
validation and permissions through it, and open a listener of your own only when it can't serve
the query.
## Workflow
1. **Find listeners opened per item.** Look in components rendered once per card, row, list item,
search result or preview for:
- `useValidationStatus(` or `useDocumentPairPermissions(` without `listener: 'global'`. By
default they load the document the way the editor does, which opens a listener for it.
- `documentStore.listenQuery(`, `listenQuery(`, `client.listen(`, `client.observable.listen(`.
Every call opens its own listener, even for a query another component already runs.
- `useListeningQuery(` from `sanity-plugin-utils`, and plugins built on it. Each call opens a
listener. As of 2.0.23, when the listener fails, its error handler throws "You provided an
invalid object where a stream was expected" and the hook stops updating.
Also look for the same query run by several components (a settings document read by the
structure, a tool and a badge).
2. **Check the Studio version.** `{listener: 'global'}` needs `sanity` 6.24.0 or later. On an
older version, propose the upgrade first (see the `sanity-studio-upgrade` skill).
3. **Replace each one by what the item needs:**
| Per item you need | Use | Listeners added |
...From sanity-io's repository, MIT licence.
Related skills
-
Checked
Website cloner
Rebuilds an existing web page as working local code that matches its content, assets, layout and interactions.
8/101 credit -
Checked
Immersive website design
Designs immersive, award level websites with bold type, scroll storytelling and purposeful motion.
7/101 credit -
Checked
Website structure planner
Plans the pages your site needs, its navigation, URLs and internal links, including for site migrations.
7/101 credit -
Checked
Netlify forms setup
Adds contact, signup and upload forms to a Netlify site with no backend, and fixes lost or spammed entries.
9/101 credit -
Checked
Web design builder
Builds polished web pages, dashboards and prototypes in HTML, CSS and React, then checks them in a browser.
8/101 credit -
Checked
AI search optimiser
Audits your site's code and makes changes so ChatGPT, Perplexity and AI Overviews can find and quote it.
7/101 credit