Skip to content

Commit 83a8f00

Browse files
hi-ogawaclaude
andcommitted
docs(plugin-rsc): simplify CSS support documentation
- Remove redundant configuration examples (already covered in Plugin API section) - Remove explicit mentions of rscCssTransform internal name - Focus only on how auto CSS injection works - Keep documentation concise and user-focused 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 27c67ff commit 83a8f00

File tree

1 file changed

+2
-75
lines changed

1 file changed

+2
-75
lines changed

packages/plugin-rsc/README.md

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function renderHTML(...) {}
265265
#### `import.meta.viteRsc.loadCss`
266266
267267
> [!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.
268+
> The plugin automatically injects CSS for React components. See the [CSS Support](#css-support) section for detailed information about automatic CSS injection.
269269
270270
- Type: `(importer?: string) => React.ReactNode`
271271
@@ -441,11 +441,9 @@ This is a wrapper of `react-server-dom` API and helper API to setup a minimal RS
441441

442442
## CSS Support
443443

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-
446444
### How Auto CSS Injection Works
447445

448-
The core mechanism is implemented in the `rscCssTransform` function in `packages/plugin-rsc/src/plugin.ts`. Here's how it works:
446+
The plugin automatically handles CSS code-splitting and injection for React components. This eliminates the need to manually call `import.meta.viteRsc.loadCss()` in most cases.
449447

450448
1. **Component Detection**: The plugin automatically detects React components by looking for:
451449
- Function exports with capital letter names (e.g., `export function Page() {}`)
@@ -486,77 +484,6 @@ Object.defineProperty(__wrapper, 'name', { value: 'Page' })
486484
export { __wrapper as Page }
487485
```
488486

489-
### Configuration
490-
491-
You can configure or disable the auto CSS injection feature:
492-
493-
```js
494-
// vite.config.ts
495-
export default defineConfig({
496-
plugins: [
497-
rsc({
498-
// Disable auto CSS injection entirely
499-
rscCssTransform: false,
500-
501-
// Or configure with a custom filter
502-
rscCssTransform: {
503-
filter: (id) => {
504-
// Only apply to files in specific directories
505-
return id.includes('/components/') || id.includes('/pages/')
506-
},
507-
},
508-
}),
509-
],
510-
})
511-
```
512-
513-
### Manual Control with Query Parameters
514-
515-
For fine-grained control, you can use the `?vite-rsc-css-export=<name>` query parameter:
516-
517-
```tsx
518-
// my-component.tsx?vite-rsc-css-export=MyComponent
519-
import './styles.css'
520-
521-
export function MyComponent() {
522-
return <div>Only this component gets CSS injection</div>
523-
}
524-
525-
export function AnotherComponent() {
526-
return <div>This one doesn't</div>
527-
}
528-
```
529-
530-
You can also specify multiple component names:
531-
532-
```tsx
533-
// my-components.tsx?vite-rsc-css-export=ComponentA,ComponentB
534-
```
535-
536-
### Development vs Production
537-
538-
- **Development**: CSS injection happens dynamically to support HMR (Hot Module Replacement)
539-
- **Production**: CSS dependencies are collected during build and injected as `<link>` tags in the HTML
540-
541-
### Manual CSS Loading
542-
543-
For cases where you need manual control, you can still use [`import.meta.viteRsc.loadCss()`](#importmetaviterscloadcss):
544-
545-
```tsx
546-
export function Layout() {
547-
return (
548-
<html>
549-
<head>
550-
{/* Load CSS for specific routes */}
551-
{import.meta.viteRsc.loadCss('/routes/home.tsx')}
552-
{import.meta.viteRsc.loadCss('/routes/about.tsx')}
553-
</head>
554-
<body>...</body>
555-
</html>
556-
)
557-
}
558-
```
559-
560487
## Credits
561488

562489
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.

0 commit comments

Comments
 (0)