Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(dev): load StyleX dev CSS from the dev server in the debug proxy (#21324)

Innei5b3b4b721ef9
diff --git a/plugins/vite/stylexDevCss.test.ts b/plugins/vite/stylexDevCss.test.ts
index bc385c741cc..2b119008982 100644
--- a/plugins/vite/stylexDevCss.test.ts
+++ b/plugins/vite/stylexDevCss.test.ts
@@ -96,3 +96,15 @@ describe('@stylexjs/unplugin dev internals', () => {
}
});
});
+
+describe('debug proxy page', () => {
+ it('swaps the StyleX dev runtime for the proxied CSS shim', () => {
+ const html = readFileSync(
+ path.resolve(import.meta.dirname, '../../public/_dangerous_local_dev_proxy.html'),
+ 'utf8',
+ );
+
+ expect(html).toContain(`srcPath.indexOf('${stylexDevRuntimeId}') !== -1`);
+ expect(html).toContain(`srcPath = '/@id/${stylexProxiedDevCssModuleId}'`);
+ });
+});
diff --git a/public/_dangerous_local_dev_proxy.html b/public/_dangerous_local_dev_proxy.html
index d260e3ea144..1f8391fb510 100644
--- a/public/_dangerous_local_dev_proxy.html
+++ b/public/_dangerous_local_dev_proxy.html
@@ -123,6 +123,11 @@
var srcPath = script.src.startsWith('http')
? new URL(script.src).pathname
: script.src;
+ // StyleX's dev runtime fetches its CSS root-relative, which here is
+ // this page's origin, so swap in the shim that fetches from `host`.
+ if (srcPath.indexOf('virtual:stylex:runtime') !== -1) {
+ srcPath = '/@id/virtual:lobe-stylex-dev-css';
+ }
s.src = new URL(srcPath, host).toString();
} else if (script.textContent) {
s.textContent = script.textContent.replace(