Skip to content

fix(cli-build): silence mixed async/defer warning in bundled Vite dev#1515

Draft
stipsan wants to merge 2 commits into
mainfrom
cursor/async-script-tags-bundled-dev-1109
Draft

fix(cli-build): silence mixed async/defer warning in bundled Vite dev#1515
stipsan wants to merge 2 commits into
mainfrom
cursor/async-script-tags-bundled-dev-1109

Conversation

@stipsan

@stipsan stipsan commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description

With unstable_bundledDev: true, Vite logs:

Mixed async and defer script modules … Every script, including inline ones, need to be marked as async …

That warning came from mixing:

  1. Sanity’s async bridge module script
  2. Non-async studio/app entry module scripts
  3. @vitejs/plugin-react’s non-async react-refresh preamble (injected under bundledDev)

This change:

  • Marks the entry <script type="module"> tags async in DefaultDocument / BasicDocument
  • Adds a Vite plugin that ensures every type="module" script (including the react-refresh preamble) is marked async after HTML transforms

Verified locally that sanity dev with unstable_bundledDev: true no longer prints the warning.

What to review

  • Entry script async on default studio/app documents
  • sanityAsyncModuleScriptsPlugin placement after viteReact() so it rewrites the react-refresh inject
  • Unit coverage for documents, bridge decorator, plugin, and vite config plugin count

Testing

  • Unit tests for the new/changed document templates, bridge decorator, async-module plugin, and getViteConfig
  • Manual smoke: sanity dev with unstable_bundledDev: true — ready message appears without the mixed async/defer warning

Notes for release

Silence Vite mixed async/defer script warning when using unstable_bundledDev

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 15, 2026 09:48
Vite warns when module scripts mix async and defer under
experimental.bundledDev. Mark studio/app entry scripts async and add a
Vite plugin that also async-aligns the react-refresh preamble so every
module script stays async.
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (bb7ea815)

@sanity/cli

Metric Value vs main (bb7ea81)
Internal (raw) 2.2 KB -
Internal (gzip) 838 B -
Bundled (raw) 11.16 MB -
Bundled (gzip) 2.10 MB -
Import time 866ms -1ms, -0.1%

bin:sanity

Metric Value vs main (bb7ea81)
Internal (raw) 782 B -
Internal (gzip) 423 B -
Bundled (raw) 9.87 MB -
Bundled (gzip) 1.78 MB -
Import time 2.24s -2ms, -0.1%

🗺️ 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 (bb7ea815)

Metric Value vs main (bb7ea81)
Internal (raw) 108.1 KB -
Internal (gzip) 27.0 KB -
Bundled (raw) 21.72 MB -
Bundled (gzip) 3.46 MB -
Import time 775ms +1ms, +0.2%

🗺️ 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-build

Compared against main (bb7ea815)

@sanity/cli-build/_internal/build

Metric Value vs main (bb7ea81)
Internal (raw) 112.4 KB +1.4 KB, +1.3%
Internal (gzip) 28.4 KB +465 B, +1.6%
Bundled (raw) 17.94 MB +1.3 KB, +0.0%
Bundled (gzip) 3.60 MB +482 B, +0.0%
Import time 1.34s +2ms, +0.2%

@sanity/cli-build/_internal/env

Metric Value vs main (bb7ea81)
Internal (raw) 1.8 KB -
Internal (gzip) 644 B -
Bundled (raw) 1.31 MB -
Bundled (gzip) 332.9 KB -
Import time 121ms -1ms, -1.2%

@sanity/cli-build/_internal/extract

Metric Value vs main (bb7ea81)
Internal (raw) 8.6 KB -
Internal (gzip) 2.7 KB -
Bundled (raw) 151.2 KB -
Bundled (gzip) 38.3 KB -
Import time 242ms -0ms, -0.1%

🗺️ ./_internal/env · ./_internal/extract · @sanity/cli-build:./_internal/build treemap too large to embed · 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 (bb7ea815)

Metric Value vs main (bb7ea81)
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.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-build/src/actions/build/getViteConfig.ts 97.7% (±0%)
packages/@sanity/cli-build/src/actions/build/renderDocumentWorker/components/BasicDocument.tsx 75.0% (+ 50.0%)
packages/@sanity/cli-build/src/actions/build/renderDocumentWorker/components/DefaultDocument.tsx 100.0% (+ 60.0%)
packages/@sanity/cli-build/src/actions/build/vite/plugin-sanity-async-module-scripts.ts 100.0% (new)

Comparing 4 changed files against main @ bb7ea815ad818012b7139135b9109e54fcb43250

Overall Coverage

Metric Coverage
Statements 76.9% (+ 0.1%)
Branches 68.0% (+ 0.1%)
Functions 72.9% (+ 0.4%)
Lines 77.4% (+ 0.1%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants