Trouble publishing data on deployed Sanity studio, solved by adding production environment variables
This is a frustrating issue, but the good news is it's usually solvable! The symptoms you're describing - drafts saving but publish hanging without a toast - typically point to one of a few common deployment configuration issues.
Most Likely Cause: CORS Origins
The most common reason for this behavior is that your deployed Studio's domain hasn't been added to your project's CORS (Cross-Origin Resource Sharing) origins. When your Studio tries to publish, it needs permission to make authenticated API requests to Sanity's servers. Without proper CORS configuration, the publish mutation gets blocked by the browser.
To fix this:
- Go to manage.sanity.io
- Select your project
- Navigate to Settings → API → CORS Origins
- Click Add CORS origin
- Enter your deployed Studio's full URL (e.g.,
https://your-studio.vercel.app) - Important: Check the "Allow credentials" box
- Save
The "Allow credentials" checkbox is crucial - without it, authenticated requests (like publishing) will fail even if the domain is whitelisted.
Other Potential Issues to Check
1. Configuration File Issues
Verify your sanity.config.js (or .ts) has the correct projectId and dataset properly defined. According to the configuration documentation, these should be set in your config file:
import { defineConfig } from 'sanity'
export default defineConfig({
projectId: 'your-project-id',
dataset: 'production',
// ... rest of config
})If you're using environment variables for these values, make sure they're prefixed with SANITY_STUDIO_ (as explained in the environment variables documentation) and are properly set in your hosting platform (Vercel, Netlify, etc.) - not just in local .env files.
2. Build vs Runtime Configuration
Since drafts are saving but not publishing, your Studio is partially connected to Sanity (it can write drafts) but something is blocking the publish mutation specifically. This often happens when:
- The Studio was built with correct config but CORS wasn't set up for the deployed domain
- Authentication headers are being blocked due to missing "Allow credentials" in CORS settings
3. Check Browser Console
Open your browser's developer console on the deployed Studio and try to publish. Look for:
- CORS errors mentioning "Access-Control-Allow-Origin"
- Network requests to
*.api.sanity.iothat are failing - Any mutation errors in the console
These will give you specific clues about what's failing.
Why It Works Locally
Your local Studio works because http://localhost:3333 (or whatever port you're using) is likely already in your CORS origins, or the browser treats localhost differently for security purposes.
Try adding the CORS origin first - this solves the issue in about 90% of cases with these exact symptoms. If that doesn't work, check the browser console for specific error messages and come back with those details for more targeted troubleshooting!
Sanity – Build the way you think, not the way your CMS thinks
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.