
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou're absolutely right that this is related to how GitHub Codespaces handles port forwarding! This is a common issue when running Sanity Studio (which uses Vite) in Codespaces.
The problem occurs because the dev server binds to localhost by default, which doesn't work well with Codespaces' port forwarding mechanism. Here are the solutions:
Modify your dev command to bind to all network interfaces:
sanity dev --host 0.0.0.0Or update your package.json:
{
"scripts": {
"dev": "sanity dev --host 0.0.0.0"
}
}For a more robust solution, create or update your sanity.cli.ts file to configure Vite's server and HMR (Hot Module Replacement) settings:
import {defineCliConfig} from 'sanity/cli'
import {type UserConfig} from 'vite'
export default defineCliConfig({
vite(viteConfig: UserConfig): UserConfig {
return {
...viteConfig,
server: {
...viteConfig.server,
host: '0.0.0.0',
hmr: {
clientPort: 443,
host: process.env.CODESPACE_NAME
? `${process.env.CODESPACE_NAME}-3333.app.github.dev`
: 'localhost'
}
}
}
}
})This configuration:
0.0.0.0 so it accepts connections from Codespaces' proxy443 (HTTPS){codespace-name}-{port}.app.github.dev)Sanity Studio uses Vite as its build tooling, and Vite's dev server needs to be accessible through Codespaces' port forwarding system. By default, it only listens on localhost, which isn't accessible through the forwarded ports. The --host 0.0.0.0 flag tells Vite to listen on all network interfaces, making it accessible through Codespaces' proxy.
The HMR configuration is important because without it, hot module replacement might try to connect to the wrong URL, causing the infinite loading you're experiencing.
.devcontainer/devcontainer.json file with "forwardPorts": [3333]The --host 0.0.0.0 flag is usually sufficient for most cases, but the full Vite configuration ensures HMR works properly too!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store