Repository navigation
fix(rsbuild): load StyleX styles via extracted stylex.css - #511
Conversation
Disable StyleX runtimeInjection and link the emitted stylex.css from the HTML template so production builds render styles correctly. Fixes rstackjs#356 Co-authored-by: Cursor <cursoragent@cursor.com>
chenjiahan
left a comment
There was a problem hiding this comment.
Thanks for the fix! Hardcoding /stylex.css bypasses Rsbuild’s CSS asset handling, including content-hashed filenames and inlineStyles.
Disabling runtime injection in dev also breaks style HMR: class names update, but the stylesheet only updates after a page refresh.
Could we try the official @stylexjs/unplugin instead? It may be a better fit.
Use the official StyleX unplugin so generated CSS is appended to Rsbuild's content-hashed CssExtract asset instead of a hardcoded /stylex.css link. Prefer stylex.webpack() because CSS injection is attached via the webpack-compatible hook. Addresses review feedback on rstackjs#511 / rstackjs#356. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the review — addressed in a621f95. Changes
NoteUsed Verified with |
Summary
runtimeInjectionand link the emittedstylex.cssfrompublic/index.htmlinrsbuild/stylex.Fixes #356
Test plan
pnpm --filter @rsbuild-example/stylex buildsucceedsdist/stylex.cssis emitted anddist/index.htmlcontains<link rel="stylesheet" href="/stylex.css" />pnpm --filter @rsbuild-example/stylex preview— StyleX styles render (stylex.cssloads, h1font-size: 3.6rem/font-weight: 700, flex column layout)pnpm --filter @rsbuild-example/stylex dev— same StyleX styles render via/stylex.css