|
1 | 1 | # AI Agent Guide for @vitejs/plugin-rsc |
2 | 2 |
|
3 | | -This document provides specific guidance for AI agents working with the React Server Components (RSC) plugin. |
| 3 | +This document provides AI-agent-specific guidance for the React Server Components (RSC) plugin. For comprehensive documentation, see: |
4 | 4 |
|
5 | | -## Overview |
| 5 | +- **[README.md](README.md)** - Plugin overview, concepts, and examples |
| 6 | +- **[CONTRIBUTING.md](CONTRIBUTING.md)** - Development setup and testing guidelines |
6 | 7 |
|
7 | | -The `@vitejs/plugin-rsc` provides React Server Components support for Vite. It's built on the Vite environment API and enables: |
| 8 | +## Quick Reference for AI Agents |
8 | 9 |
|
9 | | -- Framework-agnostic RSC bundler features |
10 | | -- HMR support for both client and server components |
11 | | -- CSS code-splitting and injection |
12 | | -- Runtime-agnostic builds (works with various deployment targets) |
| 10 | +### Key Plugin Concepts |
13 | 11 |
|
14 | | -## Key Concepts |
| 12 | +The RSC plugin creates three environments (see [README.md Basic Concepts](README.md#basic-concepts) for diagrams): |
15 | 13 |
|
16 | | -### Environments |
| 14 | +- **rsc** - Server component rendering |
| 15 | +- **ssr** - Server-side rendering |
| 16 | +- **client** - Browser hydration |
17 | 17 |
|
18 | | -The plugin creates three distinct environments: |
19 | | - |
20 | | -1. **rsc** - React server components rendering |
21 | | -2. **ssr** - Server-side rendering environment |
22 | | -3. **client** - Browser environment for hydration |
23 | | - |
24 | | -### Architecture |
25 | | - |
26 | | -``` |
27 | | -RSC Component → RSC Stream → SSR/Client Consumption → DOM/HTML |
28 | | -``` |
29 | | - |
30 | | -See [Basic Concepts](README.md#basic-concepts) in the README for detailed flow diagrams. |
31 | | - |
32 | | -## Development Workflow |
33 | | - |
34 | | -### Setup |
| 18 | +### Essential Commands |
35 | 19 |
|
36 | 20 | ```bash |
37 | | -# Build the plugin |
38 | | -pnpm -C packages/plugin-rsc dev |
39 | | - |
40 | | -# Type checking |
41 | | -pnpm -C packages/plugin-rsc tsc-dev |
| 21 | +pnpm -C packages/plugin-rsc dev # Watch mode development |
| 22 | +pnpm -C packages/plugin-rsc test-e2e # Run e2e tests |
| 23 | +pnpm -C packages/plugin-rsc test-e2e basic # Test specific example |
42 | 24 | ``` |
43 | 25 |
|
44 | | -### Testing |
| 26 | +### AI-Specific Development Tips |
45 | 27 |
|
46 | | -```bash |
47 | | -# Run all e2e tests |
48 | | -pnpm -C packages/plugin-rsc test-e2e |
49 | | - |
50 | | -# Run with UI (interactive filtering) |
51 | | -pnpm -C packages/plugin-rsc test-e2e --ui |
| 28 | +#### Making RSC Changes |
52 | 29 |
|
53 | | -# Run specific test file |
54 | | -pnpm -C packages/plugin-rsc test-e2e basic |
| 30 | +1. **Start with `examples/starter/`** - Best learning resource for understanding RSC flows |
| 31 | +2. **Use `examples/basic/` for testing** - Comprehensive test suite with routing |
| 32 | +3. **Test across all environments** - Verify rsc, ssr, and client functionality |
| 33 | +4. **Check virtual modules** - Important for RSC manifest and reference handling |
55 | 34 |
|
56 | | -# Run with grep filter |
57 | | -pnpm -C packages/plugin-rsc test-e2e -g "hmr" |
58 | | -``` |
| 35 | +#### Testing Patterns |
59 | 36 |
|
60 | | -### Examples |
| 37 | +- **examples/basic** - Add test cases to `src/routes/`, update routing, add tests to `e2e/basic.test.ts` |
| 38 | +- **setupInlineFixture** - For isolated edge cases (see `e2e/ssr-thenable.test.ts` pattern) |
61 | 39 |
|
62 | | -- `examples/starter/` - **Start here** - Comprehensive learning resource |
63 | | -- `examples/basic/` - Advanced features and main e2e test suite |
64 | | -- `examples/ssg/` - Static site generation example |
65 | | -- `examples/react-router/` - React Router integration |
66 | | - |
67 | | -## Important Files |
68 | | - |
69 | | -### Core Plugin Files |
| 40 | +#### Important File Locations |
70 | 41 |
|
71 | 42 | - `src/plugin.ts` - Main plugin implementation |
72 | 43 | - `src/environment/` - Environment-specific logic |
73 | | -- `src/types/` - TypeScript definitions |
74 | | -- `types/` - External type definitions |
75 | | - |
76 | | -### Runtime APIs |
77 | | - |
78 | | -- `rsc/` - Server component runtime |
79 | | -- `ssr/` - SSR runtime |
80 | | -- `browser/` - Client runtime |
81 | | -- `vendor/` - Vendored react-server-dom |
82 | | - |
83 | | -### Configuration |
84 | | - |
85 | | -- `vite.config.ts` - Development configuration |
86 | | -- `tsdown.config.ts` - Build configuration |
87 | | -- `playwright.config.ts` - E2E test configuration |
| 44 | +- `rsc/`, `ssr/`, `browser/` - Runtime APIs |
| 45 | +- `examples/` - Test applications and learning resources |
88 | 46 |
|
89 | | -## Testing Patterns |
90 | | - |
91 | | -### Test Fixture Patterns |
92 | | - |
93 | | -1. **examples/basic** - Comprehensive test suite |
94 | | - - Add test cases to `src/routes/` |
95 | | - - Update routing in `src/routes/root.tsx` |
96 | | - - Add tests to `e2e/basic.test.ts` |
97 | | - |
98 | | -2. **setupInlineFixture** - Isolated edge case testing |
99 | | - - Best for specific scenarios |
100 | | - - See `e2e/ssr-thenable.test.ts` for pattern |
101 | | - - Dependencies managed in `examples/e2e/package.json` |
102 | | - |
103 | | -### Adding Tests |
104 | | - |
105 | | -```bash |
106 | | -# Create new test project (automatically runnable) |
107 | | -pnpm -C packages/plugin-rsc/examples/e2e/temp/my-test dev |
108 | | -``` |
109 | | - |
110 | | -## Common Development Tasks |
111 | | - |
112 | | -### Adding New RSC Features |
113 | | - |
114 | | -1. Understand the React Server Components specification |
115 | | -2. Check existing implementation in `src/environment/` |
116 | | -3. Add runtime support in appropriate environment |
117 | | -4. Update type definitions |
118 | | -5. Add comprehensive tests |
119 | | -6. Update documentation |
120 | | - |
121 | | -### Debugging Issues |
| 47 | +### Debugging RSC Issues |
122 | 48 |
|
123 | 49 | 1. Use `examples/starter` for basic reproduction |
124 | | -2. Check environment-specific builds in `.vite/` |
125 | | -3. Examine RSC streams and manifests |
126 | | -4. Test across all three environments |
127 | | -5. Verify HMR behavior |
128 | | - |
129 | | -### Performance Optimization |
130 | | - |
131 | | -1. Analyze bundle outputs with metadata plugins |
132 | | -2. Check CSS code-splitting effectiveness |
133 | | -3. Monitor RSC payload sizes |
134 | | -4. Test streaming performance |
135 | | - |
136 | | -## Key Plugin APIs |
137 | | - |
138 | | -### Virtual Modules |
139 | | - |
140 | | -- `virtual:vite-rsc/assets-manifest` |
141 | | -- `virtual:vite-rsc/client-references` |
142 | | -- `virtual:vite-rsc/server-references` |
143 | | -- `virtual:vite-rsc/encryption-key` |
144 | | - |
145 | | -### Environment Helper API |
146 | | - |
147 | | -- `import.meta.viteRsc.loadCss()` - CSS loading |
148 | | -- `?vite-rsc-css-export=<name>` - CSS exports |
149 | | - |
150 | | -### Runtime Modules |
151 | | - |
152 | | -- `@vitejs/plugin-rsc/rsc` - Server component rendering |
153 | | -- `@vitejs/plugin-rsc/ssr` - SSR utilities |
154 | | -- `@vitejs/plugin-rsc/browser` - Client-side RSC |
155 | | - |
156 | | -## Best Practices |
157 | | - |
158 | | -1. **Use setupInlineFixture for new tests** - More maintainable and faster |
159 | | -2. **Follow existing patterns** - Check `examples/basic` for comprehensive examples |
160 | | -3. **Test across environments** - Ensure functionality works in rsc, ssr, and client |
161 | | -4. **Maintain backward compatibility** - RSC ecosystem is evolving rapidly |
162 | | -5. **Document breaking changes** - Update CHANGELOG.md appropriately |
163 | | - |
164 | | -## Troubleshooting |
165 | | - |
166 | | -### Common Issues |
167 | | - |
168 | | -1. **Module resolution errors** - Check `optimizeDeps.include` configuration |
169 | | -2. **CSS not loading** - Verify `loadCss()` usage and environment setup |
170 | | -3. **HMR not working** - Check component boundaries and environment isolation |
171 | | -4. **Build failures** - Verify environment-specific configurations |
172 | | - |
173 | | -### Debugging Tools |
174 | | - |
175 | | -- Vite's built-in inspect plugin |
176 | | -- Browser DevTools for client environment |
177 | | -- Server logs for rsc/ssr environments |
178 | | -- Playwright test inspector for e2e tests |
| 50 | +2. Check environment builds in `.vite/` directory |
| 51 | +3. Examine RSC streams and client/server manifests |
| 52 | +4. Verify HMR behavior across environments |
179 | 53 |
|
180 | | -For more detailed contributing guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md). |
| 54 | +For detailed setup, testing procedures, and architectural deep-dives, refer to the comprehensive documentation in [README.md](README.md) and [CONTRIBUTING.md](CONTRIBUTING.md). |
0 commit comments