#1913·stylex

[unplugin] Vite dev on Windows: runtime/CSS URLs built with path.join reach the browser as "\\virtual:…" and never load

Author: DION-CLCreated Sep 28, 2026Updated Sep 28, 2026

Describe the issue

On Windows, @stylexjs/unplugin/vite in dev (devMode: 'full') injects its runtime script and stylesheet with URLs built by Node's path.join, which produces backslashes:

javascript
// packages/@stylexjs/unplugin/src/vite.js (transformIndexHtml), still on main
src: path.join(base, '/@id/virtual:stylex:runtime'),   // win32 -> "\\@id\\virtual:stylex:runtime"
href: path.join(base, DEV_CSS_PATH),                    // win32 -> "\\virtual:stylex.css"

Vite then serializes tag attributes with JSON.stringify, so each backslash is doubled in the HTML the browser receives:

xml
<script type="module" src="\\@id\\virtual:stylex:runtime"></script>
<link rel="stylesheet" href="\\virtual:stylex.css">

A browser treats a leading \\ as //, i.e. a protocol-relative URL to another host:

  • \\virtual:stylex.css → //virtual:stylex.css → host virtual, port stylex.css → invalid URL, never requested
  • \\@id\\virtual:stylex:runtime → http://id//virtual:stylex:runtime → a request to host id

So on Windows no StyleX CSS ever reaches the page in dev. In our app (with more on the page) the first load did not complete at all; in the minimal repro below the page loads but is unstyled.

The same path.join(base, 'virtual:stylex:css-module') is used as a module-graph id in handleHotUpdate, which on Windows can never match either.

Expected behavior

Dev URLs are URL paths, not file paths: /@id/virtual:stylex:runtime and /virtual:stylex.css (joined with path.posix.join, or plain string concatenation with the Vite base) on every OS.

Steps to reproduce

Windows 11 Pro (10.0.26200), Node 20.19.0, Vite 5.4.21, React 18.3.1, @stylexjs/unplugin / @stylexjs/stylex / @stylexjs/babel-plugin 0.19.1, Chromium (Playwright 1.62.1).

  1. vite.config.mjs:
    javascript
    import { defineConfig } from 'vite';
    import stylex from '@stylexjs/unplugin/vite';
    export default defineConfig({
      plugins: [stylex({ dev: true, devMode: 'full', runtimeInjection: false, useCSSLayers: true })],
    });
  2. src/main.js:
    javascript
    import { createElement } from 'react';
    import { createRoot } from 'react-dom/client';
    import * as stylex from '@stylexjs/stylex';
    const styles = stylex.create({ hello: { color: 'rebeccapurple' } });
    createRoot(document.getElementById('root')).render(
      createElement('h1', { ...stylex.props(styles.hello), id: 'hello' }, 'hello'),
    );
    plus an index.html with <div id="root"> and <script type="module" src="/src/main.js">.
  3. Start vite on Windows with the dependency cache already warm (or with the workaround from #1912, the cold-start deadlock), then curl http://localhost:5173/. The injected tags are the backslashed ones above.
  4. Open the page: #hello computes rgb(0, 0, 0). With the URLs fixed (workaround below) it computes rgb(102, 51, 153).

Test case

The repro above is complete (four files, no other dependencies). Measured on our machine:

variant injected href #hello color
plugin as shipped \\virtual:stylex.css rgb(0, 0, 0)
with the workaround /virtual:stylex.css rgb(102, 51, 153)

Additional comments

Workaround we run (a post transformIndexHtml that puts the slashes back):

typescript
export function stylexDevUrlsOnWindows(): Plugin {
  return {
    name: 'stylex-dev-urls-on-windows',
    apply: 'serve',
    enforce: 'post',
    transformIndexHtml: {
      order: 'post',
      handler: (html) =>
        html.replace(/(src|href)="\\+(@id\\+)?virtual:stylex([^"]*)"/g, (_all, attr, idPart, rest) =>
          `${attr}="/${idPart ? '@id/' : ''}virtual:stylex${rest}"`),
    },
  };
}

Suggested fix: use path.posix.join (or string concatenation that respects base) for the three dev URLs/ids in vite.js. Related but different: #1347 (dev URLs ignoring a non-root base).