You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(plugin-rsc): add comprehensive CSS support documentation
- Add CSS Support section explaining auto CSS injection mechanism
- Document rscCssTransform feature and configuration options
- Add note linking from loadCss API to CSS Support section
- Include examples of component detection and transformation
- Cover query parameter control and dev vs prod behavior
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: packages/plugin-rsc/README.md
+121Lines changed: 121 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,6 +264,9 @@ export function renderHTML(...) {}
264
264
265
265
#### `import.meta.viteRsc.loadCss`
266
266
267
+
> [!NOTE]
268
+
> The plugin automatically injects CSS for React components through the `rscCssTransform` feature. See the [CSS Support](#css-support) section for detailed information about automatic CSS injection.
269
+
267
270
- Type: `(importer?:string) =>React.ReactNode`
268
271
269
272
This allows collecting css which is imported through a current server module and injecting them inside server components.
@@ -436,6 +439,124 @@ This is a wrapper of `react-server-dom` API and helper API to setup a minimal RS
436
439
437
440
- `hydrate`
438
441
442
+
## CSS Support
443
+
444
+
The plugin provides automatic CSS code-splitting and injection for both client and server components through the `rscCssTransform` feature. This eliminates the need to manually call `import.meta.viteRsc.loadCss()` in most cases.
445
+
446
+
### How Auto CSS Injection Works
447
+
448
+
The core mechanism is implemented in the `rscCssTransform` function in `packages/plugin-rsc/src/plugin.ts`. Here's how it works:
449
+
450
+
1. **Component Detection**: The plugin automatically detects React components by looking for:
451
+
- Function exports with capital letter names (e.g., `export function Page() {}`)
452
+
- Default exports that are functions with capital names (e.g., `export default function Page() {}`)
453
+
- Const exports assigned to functions with capital names (e.g., `export const Page = () => {}`)
454
+
455
+
2. **CSS Import Detection**: For detected components, the plugin checks if the module imports any CSS files (`.css`, `.scss`, `.sass`, etc.)
456
+
457
+
3. **Automatic Wrapping**: When both conditions are met, the plugin wraps the component with a CSS injection wrapper:
0 commit comments