Repository navigation
Description
Description
SSR frameworks that stream HTML serialize per-module URLs into the document itself, ahead of any client code:
<link rel="modulepreload" href="...">hints, so the browser fetches lazy route chunks in parallel with the entry bundle during HTML parse, and- a hydration module map (e.g.
_$HY.r["…_assets"] = { hydrationKey: url }) written by inline<script>chunks in the stream, which the client runtimeimport()s before resuming server-rendered DOM.
Concrete case: SolidStart on solid-js 2.0 / vite-plugin-solid. In (unbundled) dev, the framework's asset resolver answers "what URL serves module X?" by identity — the module's dev URL, e.g.:
/src/routes/(basic).tsx?pick=default&pick=$css
Under experimental.bundledDev (Vite 8.1) that contract breaks:
- The served HTML (200) still contains those source-path URLs in the modulepreload hints and the hydration module map — the SSR side has nothing else to emit.
- Requesting the URL itself returns 404: only bundled output files are served (
memoryFilesMiddlewarelooks upmemoryFiles.get(pathname.slice(1))and falls through for anything that isn't an outputfileName). - The client runtime's pre-hydration
import(url)therefore rejects, hydration falls back to a fresh client render, and the page ends up with duplicated DOM. In SolidStart's test app this is 18 failing e2e specs (apps/testse2e:bundled-dev) that all pass in normal dev.
The underlying gap: a server-side plugin has no API to translate a module id into its served URL in bundled dev.
BundledDev.memoryFilesmaps outputfileName → { source, etag }. There is no facade/module-id → fileName mapping exposed, so you can't go fromsrc/routes/(basic).tsx?pick=default&pick=$csstoassets/_basic_-DhY….js.- The lazy-compile endpoint
/@vite/lazy?id=…&clientId=…(triggerLazyBundlingMiddleware→devEngine.compileEntry(moduleId, clientId)) requires a live HMR clientId and returns compiled code, not a URL — unusable from an SSR render pass that must emit URLs into HTML before any client connects.
Put differently: in normal dev, module → URL is answerable by identity (the URL is the module path); in production builds it's answerable via manifest.json. Bundled dev is currently the only topology that provides neither.
We want to stress this is a correctness requirement for streamed SSR hydration in bundled dev, not an optimization: the URLs are fixed server-side and shipped in the HTML before any client code executes, so there is no client-side recovery — either the server can emit servable URLs or hydration of code-split routes fails. We understand bundledDev is experimental and evolving; if there's an intended pattern for this that we've missed, pointers welcome, and we're glad to help test an API.
Suggested solution
A stable server-side API — on the client Environment or the dev server — that, under bundledDev, maps module id → served URL(s) (the entry chunk for that module, ideally with its static import chain for complete preload hints), e.g.:
const urls = await server.environments.client.bundledDev.resolveModuleUrl(
"src/routes/(basic).tsx?pick=default&pick=$css"
);
// → ["/assets/_basic_-DhYx12ab.js", ...]Semantics we'd need: awaits the current build if one is in flight (like waitForInitialBuildFinish), and reflects lazy-compiled entries once they exist (or triggers compilation without requiring a browser clientId).
Alternative
For the client entry specifically, SolidStart already works around this by hardcoding the served path, assets/${basename(entry)}.js, which is only possible because the entry's entryFileNames is predictable. Hashed lazy route chunks have no equivalent workaround — their served names are only knowable from the bundle graph Vite holds. Emulating a manifest by watching memoryFiles doesn't work either, since there's no exposed mapping from output files back to the facade module ids the framework knows about.
Additional context
Reproduction:
- Full suite:
solidjs/solid-startrepo, branchupgrade-to-solid-2-beta,apps/tests,pnpm e2e:bundled-dev(playwright.bundled-dev.config.ts) — 18 hydration-related failures; the same specs pass withpnpm e2e(unbundled dev). - Minimal sketch: any Vite 8.1 app with
experimental.bundledDevand an SSR handler that renders a code-split (import()-ed) component and emits<link rel="modulepreload">/ a script thatimport()s that module's dev URL (/src/Comp.tsx). The HTML streams fine; the module request 404s; anything gated on it fails — while the same URL works in unbundled dev.
Related precedent: solidjs/solid-start#2210 (the hardcoded entry-URL workaround mentioned above).
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Activity
sapphi-red commentedon Jul 21, 2026
Thanks for the issue. Would you expand more on the dynamic entrypoints? It would probably interact with "lazy bundling" feature which defers the transform of dynamically imported modules.
ryansolid commentedon Jul 21, 2026
Happy to expand — and yes, lazy bundling is exactly where this bites.
What our dynamic entrypoints are. Two flavors, both reached only via dynamic import:
src/routes/(basic).tsx?pick=default&pick=$css), and the generated route tree loads it withlazy(() => import(...)).lazy(() => import("./HeavyComp"))anywhere in the tree.Since nothing imports these statically, under lazy bundling every one of them is a deferred entry.
When we need their URLs. During the SSR render itself. As the server streams HTML, each server-rendered
lazycomponent resolves its module id through the framework's asset resolver and we emit, into the stream:<link rel="modulepreload" href="...">in the head, and<script>chunks) mapping hydration keys to module URLs.The browser starts fetching those URLs during HTML parse, and the client runtime
import()s the hydration-map URLs and blocks hydration resume on them. All of this happens before the client entry has executed — so before any HMR connection exists, i.e. before there is aclientId. That's why/@vite/lazy?id=…&clientId=…can't serve the first render/hydration of a code-split page: the consumer of the URL is the HTML we already sent, not a connected client.What semantics would work for us. We don't actually need the compile to have happened at emit time — we need a stable URL we can emit that will serve the module's code when the browser requests it, compiling on demand at request time. Two shapes that would both solve it, in order of how well they seem to fit lazy bundling:
compileEntrywhen that URL is first requested (noclientIdrequired, or one minted server-side), everything composes: we emit the facade URL during SSR, the browser's preload request is itself the compile trigger, and lazy bundling keeps its full deferral benefit — only routes actually rendered ever compile. This also sidesteps the hashed-filename problem: a content-hashed name can't be known before the compile, so any "resolve to final chunk URL" API would otherwise have to force the compile at SSR time.resolveModuleUrl(id)or similar) that triggers/awaits compilation of the lazy entry and returns the served URL(s). The SSR render knows exactly which dynamic modules it rendered, so it would only warm those — the deferral still pays off for everything unrendered. Slightly worse than (1) because it serializes compile into the render, but entirely workable.One extra wrinkle worth noting for either shape: ideally the answer includes the entry's static import chain too (the chunks the entry will pull in), so the preload hints are complete — that's what we read from
manifest.jsonin prod. But entry-URL-only would already unblock correctness; the import chain is the optimization layer on top.Happy to prototype against a branch if you land on a direction.
nihgwu commentedon Jul 21, 2026
We’ve now hit another instance of this API gap while testing @vitejs/plugin-rsc with experimental.bundledDev in a real application.
RSC SSR discovers CSS imports from route-specific and server-rendered modules. In normal dev mode, those module IDs can be emitted as stylesheet URLs in the rendered HTML. With
bundledDev, the normal transform middleware is unavailable andenvironment.bundledDev.memoryFilescontains only bundle outputs, so the RSC integration cannot safely translate a discovered CSS module ID into a browser-loadable URL.This appears to require the same general primitive proposed here: an environment-aware way to map a module ID to its current served bundled output URL. For CSS, the result must be directly loadable as a stylesheet, rather than the JavaScript wrapper produced by the normal development CSS transform.
The plugin should not need to parse generated chunks, create data URLs, or install custom CSS middleware. A Vite-owned mapping or direct transformation API would allow RSC and other SSR integrations to emit correct preload and stylesheet links while preserving
bundledDev’s ownership of its generated output.mark Vite experimental bundledDev as unsupported until vitejs/vite#22991
sapphi-red commentedon Aug 6, 2026
Thanks for the explanations.
While I'm still thinking about the design, I have a question. Did you wait for the client bundle to be ready? Was that possible? I assume that is needed to properly reference the client output from SSR, otherwise it may return 404.
ryansolid commentedon Aug 6, 2026
Good question — timing wasn't the failure mode we hit, though it's entangled with the design.
We didn't add an explicit wait on the client bundle, and waiting wouldn't have changed the outcome: our dev asset resolver derives URLs purely from module ids (
/src/routes/(basic).tsx?pick=default&pick=$css) and never reads anything the client build produces, so a fully completed bundle leaves the emitted HTML byte-identical — and those module-id URLs are never servable in bundled dev, sincememoryFilesMiddlewareonly answers for outputfileNames and there's no way to learn which output file corresponds to a module id. The 404s persist at every point in the build lifecycle. It's a mapping gap, not a race. (Our only bundled-dev accommodation is the hardcoded entry-chunk name described under "Alternative" above — the entry loads fine; it's the code-split modules that have no equivalent.)That said, you're right that a real solution has an await in it, in two distinct senses:
waitForInitialBuildFinish-like semantics for modules in the initial client graph — that's what we meant in the proposal. Fine for SSR: streaming renders already await async work mid-stream.compileEntry, and today the only trigger requires a live HMRclientId, which doesn't exist during the first SSR render. That's why the facade-URL shape appeals to us: a stable, unhashed URL per deferred entry whose first browser request is the compile trigger means SSR never blocks on a compile and never needs the bundle graph — and lazy bundling keeps full deferral. The resolve-API shape works too if it can trigger/await lazy compilation without a clientId; it just serializes that compile into the render.So: "wait for the client bundle" is answerable and workable for the initial graph, impossible today for lazy entries — and either way the missing primitive is the id→URL mapping.