Skip to content

fix(streaming): use emitted Vite IIFE asset URL - #789

Merged
harlan-zw merged 6 commits into
mainfrom
fix/streaming-contracts
Jun 29, 2026
Merged

harlan-zw merged 6 commits into
mainfrom
fix/streaming-contracts

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

What this fixes

In Vite production builds, emitFile() returns a Rollup asset reference id, not the final file name. The async streaming plugin was putting that ref into the injected IIFE script tag, so the built HTML could point at /<ref> instead of /assets/unhead-streaming.[hash].js.

Changes

  • Resolve the emitted unhead-streaming.js file from Vite's bundle context, with getFileName() as a fallback, before injecting the async script.
  • Keep virtual:@unhead/streaming-iife.js scoped to the Vite adapter; webpack, rspack, and rollup do not resolve or load that Vite-only module.
  • Preserve the unhead/stream/iife named export contract in stub builds by bundling the source IIFE before writing streamingIifeCode and streamingIifeSize.

Tests

  • Adds coverage for production Vite script injection using the emitted asset path.
  • Adds coverage that non-Vite adapters do not expose the Vite-only IIFE virtual module.
  • Verified both unbuild --stub and the normal unhead package build produce importable streamingIifeCode exports.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@harlan-zw, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e8993f7-045e-4354-b794-dd65315dbf6b

📥 Commits

Reviewing files that changed from the base of the PR and between 68033f9 and 14a18c7.

📒 Files selected for processing (1)
  • packages/unhead/build.config.ts
📝 Walkthrough

Walkthrough

SolidJS stream wrapping now buffers inner chunks until shell readiness, then flushes the shell and buffered output while coordinating cancellation and error settling. Unhead’s streaming plugin now treats the async IIFE as Vite-only, resolves emitted asset paths during HTML transformation, and updates related tests and build guards.

Changes

SolidJS stream wrapping

Layer / File(s) Summary
Buffered flush and settle
packages/solid-js/src/stream/server.ts
wrapStream buffers inner chunks before shell flush, then prepares the shell, emits buffered output, and settles or fails the stream.
Stream behavior tests
packages/solid-js/test/streaming.test.ts
The streaming tests decode bytes and cover error timing, cancellation propagation, buffered flush, and reader release.

Unhead streaming plugin

Layer / File(s) Summary
State and build guards
packages/unhead/src/stream/unplugin.ts, packages/unhead/build.config.ts
InternalState tracks Vite status and emitted asset ids, and the build hooks skip async IIFE work for stubbed or non-Vite paths.
Virtual IIFE path resolution
packages/unhead/src/stream/unplugin.ts
resolveId, load, and transformIndexHtml now use Vite-only IIFE handling and derive the emitted script path from the bundle context.
Adapter coverage
packages/unhead/test/streaming/unplugin.test.ts, packages/vue/test/vite-plugin.test.ts
The tests cover Vite and non-Vite virtual-module resolution and production HTML injection for the streaming IIFE path.

Sequence Diagram(s)

SolidJS wrapStream

sequenceDiagram
  participant wrapStream
  participant shellReadyPromise
  participant innerReader
  participant cancelInner
  wrapStream->>innerReader: read chunks into buffer
  wrapStream->>shellReadyPromise: wait for shellReady or settlement
  shellReadyPromise-->>wrapStream: shellState
  wrapStream->>wrapStream: flush shell and buffered chunks
  wrapStream->>cancelInner: cancel(reason)
Loading

Unhead async IIFE emission

sequenceDiagram
  participant buildStart
  participant emitFile
  participant resolveEmittedIifePath
  participant transformIndexHtml
  participant ctx.bundle
  buildStart->>emitFile: emit async IIFE asset
  emitFile-->>buildStart: emittedIifeFileId
  transformIndexHtml->>resolveEmittedIifePath: resolve emitted filename
  resolveEmittedIifePath->>ctx.bundle: read emitted asset name
  ctx.bundle-->>resolveEmittedIifePath: file name
  resolveEmittedIifePath-->>transformIndexHtml: asset path
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • unjs/unhead#707: Also changes packages/unhead/build.config.ts in the streaming IIFE build pipeline.
  • unjs/unhead#751: Also updates packages/unhead/src/stream/unplugin.ts and its streaming hook wiring.
  • unjs/unhead#752: Also changes packages/solid-js/src/stream/server.ts around streaming template handling.

Poem

A bunny hopped through streamed-up light,
buffering crumbs till shell felt right.
Vite found paths with a whisker twist,
and the async breeze went pop-fizz-hiss. 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is informative, but it omits the template’s Linked issue and Type of change sections. Add the linked issue, check all applicable type-of-change boxes, and format the body with the repository template sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise, conventional, and matches the main change: using the emitted Vite IIFE asset URL.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/streaming-contracts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle Size

✅ No notable changes

All bundles (12)
Bundle Gzipped Raw
Core
Client (Minimal) 4.7 kB 11.7 kB ✅
Client (Full) 7.9 kB 20.6 kB ✅
Server (Minimal) 4.5 kB 11.4 kB ✅
Vue
Vue Client (Minimal) 5.2 kB 12.8 kB ✅
Vue Client (Full) 8.7 kB 22.5 kB ✅
Vue Server (Minimal) 5 kB 12.3 kB ✅
React
React Client (Minimal) 5.1 kB 12.7 kB ✅
React Client (Full) 8.5 kB 22.1 kB ✅
React Server (Minimal) 4.8 kB 12 kB ✅
Schema.org
Schema.org (Minimal) 9.5 kB 26.3 kB ✅
Schema.org Imports 0.1 kB 0.1 kB ✅
Schema.org Vue Meta 0.4 kB 0.8 kB ✅

⚡ Performance (directional)

⚠️ 1 slower · past the per-metric noise gate

Benchmark base → PR Δ
SSR allocated / render 317.9 KiB → 330.7 KiB 🔴 +12.8 KiB (+4.0%)
All benchmarks (6)
Benchmark PR Δ RME
SSR render (CPU) 0.465 ms ~ noise ±9.3%
SSR render (wall) 0.294 ms ~ noise ±4.7%
SSR allocated / render 330.7 KiB 🔴 +12.8 KiB (+4.0%) —
CSR DOM mutations / nav 38 ~ noise —
CSR re-render (CPU) 0.803 ms ~ noise ±5.5%
CSR re-render (wall) 0.451 ms ~ noise ±2.4%

Baseline: main @ e9808d8 · 2026-06-29 · gzipped is the headline size metric · perf is directional (shared-runner, gated)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/unhead/build.config.ts`:
- Around line 18-20: The stub-mode early return in build:done is skipping the
post-build rewrite that populates the stream IIFE exports, so the stub artifact
no longer provides streamingIifeCode and streamingIifeSize for unplugin.ts.
Update the build flow in the build config so the rewrite still runs in stub
mode, or otherwise ensure dist/stream/iife and its matching type files export
those symbols before packages/unhead/src/stream/unplugin.ts imports them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0bf0bab7-5301-4ec3-8ef3-aac322181310

📥 Commits

Reviewing files that changed from the base of the PR and between 2df22b1 and 68033f9.

📒 Files selected for processing (6)
  • packages/solid-js/src/stream/server.ts
  • packages/solid-js/test/streaming.test.ts
  • packages/unhead/build.config.ts
  • packages/unhead/src/stream/unplugin.ts
  • packages/unhead/test/streaming/unplugin.test.ts
  • packages/vue/test/vite-plugin.test.ts

Comment thread packages/unhead/build.config.ts Resolved
@harlan-zw harlan-zw mentioned this pull request Jun 29, 2026
1 of 6 tasks
# Conflicts:
#	packages/solid-js/src/stream/server.ts
#	packages/solid-js/test/streaming.test.ts
@harlan-zw harlan-zw changed the title fix(streaming): resolve emitted IIFE asset path and add explicit Vite detection fix(streaming): use emitted Vite IIFE asset URL Jun 29, 2026
@harlan-zw
harlan-zw merged commit 4e368bc into main Jun 29, 2026
7 checks passed
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.

1 participant