feat(cli): add --experimental-bundle opt-in for Vite bundled dev mode#1413
Draft
stipsan wants to merge 5 commits into
Draft
feat(cli): add --experimental-bundle opt-in for Vite bundled dev mode#1413stipsan wants to merge 5 commits into
stipsan wants to merge 5 commits into
Conversation
Adds a typed `experimental.bundledDev` option to the CLI config type and zod schema so `sanity.cli.ts` can opt into Vite's bundled dev mode without the value being stripped on parse.
Adds a `--experimental-bundle` flag to `sanity dev` and honors `experimental.bundledDev` from sanity.cli.ts. The flag wins when set (including `--no-experimental-bundle`), otherwise the config value is used, defaulting to off. When enabled, `experimental.bundledDev` is set on the inline Vite config before user vite config is applied.
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (3801bd7) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 1.0 KB | - |
| Bundled (raw) | 11.16 MB | +93 B, +0.0% |
| Bundled (gzip) | 2.10 MB | +15 B, +0.0% |
| Import time | 875ms | +3ms, +0.3% |
bin:sanity
| Metric | Value | vs main (3801bd7) |
|---|---|---|
| Internal (raw) | 782 B | - |
| Internal (gzip) | 423 B | - |
| Bundled (raw) | 9.87 MB | - |
| Bundled (gzip) | 1.78 MB | - |
| Import time | 2.27s | -6ms, -0.3% |
🗺️ 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.
📦 Bundle Stats — @sanity/cli-core
Compared against main (3801bd7e)
| Metric | Value | vs main (3801bd7) |
|---|---|---|
| Internal (raw) | 106.8 KB | +93 B, +0.1% |
| Internal (gzip) | 26.7 KB | +37 B, +0.1% |
| Bundled (raw) | 21.72 MB | +85 B, +0.0% |
| Bundled (gzip) | 3.46 MB | +20 B, +0.0% |
| Import time | 777ms | -0ms, -0.0% |
🗺️ 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.
📦 Bundle Stats — create-sanity
Compared against main (3801bd7e)
| Metric | Value | vs main (3801bd7) |
|---|---|---|
| Internal (raw) | 908 B | - |
| Internal (gzip) | 483 B | - |
| Bundled (raw) | 931 B | - |
| Bundled (gzip) | 491 B | - |
| Import time | ❌ ChildProcess denied: node | - |
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.
Contributor
Coverage Delta
Comparing 4 changed files against main @ Overall Coverage
|
Vite bundled dev mode bundles from an HTML entry, defaulting to `<root>/index.html`. Sanity serves a virtual document (rewritten to `.sanity/runtime/index.html`), so without an explicit entry the bundle fails with UNRESOLVED_ENTRY. Set `build.rolldownOptions.input` to the runtime HTML when bundled mode is enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an opt-in for Vite 8.1's experimental bundled dev mode to
sanity dev. When enabled, Vite serves a Rolldown-bundled app during development instead of the unbundled per-module ESM dev server.Because
sanity devbuilds its Vite config programmatically (configFile: false), the option can't be set via a uservite.config.*. This exposes it two ways:sanity dev --experimental-bundle(and--no-experimental-bundleto force off).experimental: { bundledDev: true }insanity.cli.ts(persistent across runs).Resolution is flag-first, then config, then off (mirrors how host/port/basePath resolve). The
sanity.cli.tsoption required addingexperimental.bundledDevto theCliConfigtype and the zodcliConfigSchemain@sanity/cli-core— otherwise the parser strips unknown keys before the value reaches the dev server.Two things are set on the inline dev config when enabled (before user
viteconfig is merged, so a user override keeps final say):experimental.bundledDev = truebuild.rolldownOptions.input = <root>/.sanity/runtime/index.html— bundled mode bundles from an HTML entry and defaults to<root>/index.html, which doesn't exist in a Sanity project (the studio HTML is virtual, served from.sanity/runtime/index.html). Pointing the bundler at the real runtime HTML is the intended integration per Vite's bundled-dev design doc. Without it, bundled mode fails immediately withUNRESOLVED_ENTRY.What to review
@sanity/cli-core: newexperimental.bundledDevfield in theCliConfigtype andcliConfigSchema.@sanity/cli: new--experimental-bundleflag onDevCommand; resolution ingetDevServerConfig(flag → config → off) with an info notice; application ofexperimental.bundledDev+build.rolldownOptions.inputinstartDevServer.Testing
Automated:
@sanity/cli-core:experimental.bundledDevsurvives config parse instead of being stripped.getDevServerConfig: flag → config → off resolution,--no-experimental-bundleoverride, info notice.devServer.test.ts:createServerreceivesexperimental.bundledDev: trueand the runtime-HTML entry only when enabled, preserves other experimental options, and still applies user vite config afterward.pnpm check:types,pnpm check:lint,pnpm check:depspass (onvite@8.1.2after merging main). Scoped suites pass except 2 pre-existingformatDocumentValidationsnapshot failures that also fail onorigin/main.Manual (
fixtures/basic-studio):sanity.cli.ts) print the notice and serve a bundled/assets/index.jsRolldown bundle instead of the unbundled/.sanity/runtime/app.js.sanity devis unaffected (serves/@vite/client+ unbundledapp.js) and the studio renders correctly.Normal sanity dev renders the studio (no regression)
Upstream status (Vite 8.1.2)
Branch merged with
main, so this now runs onvite@8.1.2. Bundled mode still crashes at runtime withReferenceError: allConstants is not defined(/assets/index.js:69382) — identical to 8.1.0. Root cause is Rolldown mis-compiling a pure-ESMimport * asnamespace import (focus-lock, a transitive dep of@sanity/ui) in bundled-dev mode; the same fixture renders fine unbundled, confirming it's upstream and not Sanity's setup.There is no newer version to move to:
vite@8.1.2androlldown@1.1.3are the newest published releases (npm has nothing>8.1.2/>1.1.3; thebeta/nightly/canarydist-tags point to older versions, and rolldown has nopkg.pr.newbuild for its latestmain). This is one of several tracked Vite 8.1 bundled-dev bugs (vitejs/vite#22756, rolldown#9512) whose documented workaround is to disable the flag — consistent with Vite labeling the feature "highly experimental". The opt-in is wired so users can try it and it will start working as Rolldown ships the fix, with no further CLI changes needed.Bundled mode still crashes on vite 8.1.2 (upstream Rolldown bug)
optin_bundled_vs_normal_evidence.log
To show artifacts inline, enable in settings.