fix(sanity): support runtime staging flag for auto-updating deploys#12563
fix(sanity): support runtime staging flag for auto-updating deploys#12563
Conversation
When studios are deployed with `SANITY_INTERNAL_ENV=staging` but load modules from the production CDN, the build-time `__SANITY_STAGING__` constant gets tree-shaken away. Add a `globalThis.__SANITY_STAGING__` runtime check that survives bundling, and centralize all staging detection into a single `isStaging()` function. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📦 Bundle Stats —
|
| Metric | Value | vs main (611e177) | vs v5.19.0 |
|---|---|---|---|
| Internal (raw) | 4.41 MB | -34 B, -0.0% | -64 B, -0.0% |
| Internal (gzip) | 1.01 MB | +33 B, +0.0% | +25 B, +0.0% |
| Bundled (raw) | 12.09 MB | -34 B, -0.0% | -33.9 KB, -0.3% |
| Bundled (gzip) | 2.72 MB | +26 B, +0.0% | -7.0 KB, -0.3% |
| Import time | 1.41s | -5ms, -0.3% | +42ms, +3.1% |
bin:sanity
| Metric | Value | vs main (611e177) | vs v5.19.0 |
|---|---|---|---|
| Internal (raw) | 7.1 KB | - | - |
| Internal (gzip) | 2.9 KB | - | - |
| Bundled (raw) | 7.1 KB | - | - |
| Bundled (gzip) | 2.8 KB | - | - |
| Import time | 5ms | +0ms, +0.6% | +1ms, +10.8% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
🧪 E2E Preview environment🔑 Environment Variables for Local TestingThis is the preview URL for the E2E tests: https://e2e-studio-e4zugld17.sanity.dev To run the E2E tests locally, you can use the following environment variables, then run 💬 Remember to build the project first with |
📊 Playwright Test ReportThis report contains test results, including videos of failing tests. |
📚 TypeDoc Generation Result✅ TypeDoc generated successfully!
The TypeDoc JSON file has been generated and validated. All documentation scripts completed successfully. |
The staging environment does not change at runtime, so evaluate it once at module load time instead of on every call. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
⚡️ Editor Performance ReportUpdated Fri, 03 Apr 2026 17:00:26 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
When auto-updating studios are deployed with
SANITY_INTERNAL_ENV=staging, they load thesanitypackage from the production CDN (sanity-cdn.com). The production bundle has the bare__SANITY_STAGING__identifier statically replaced withfalseby Vite and tree-shaken away, so the staging check never fires - causing the studio to hitapi.sanity.ioinstead ofapi.sanity.work.This PR:
globalThis.__SANITY_STAGING__runtime check that survives tree-shaking (property access onglobalThiscan't be statically eliminated by Vite'sdefine)isStagingconstant incore/environment/isStaging.ts, evaluated once at module load (matching theisDev/isProdpattern)__SANITY_STAGING__checks acrosscreateAuthStore,fetchCreateCompatibleAppId, andfetchLatestVersionsThe companion CLI change will inject
<script>globalThis.__SANITY_STAGING__ = true</script>into the HTML before module scripts when deploying in staging mode.What to review
packages/sanity/src/core/environment/isStaging.ts- the new centralized constant with three detection strategies (build-time constant, runtime global, import map URL)isStaginginstead of duplicating the check inlineTesting
Unit tests in
isStaging.test.tscovering all three detection paths and their combinations. Tests usevi.resetModules()+ dynamic imports to re-evaluate the constant for each scenario.Notes for release
N/A - Internal staging infrastructure only.