Skip to content

Commit 3568e89

Browse files
authored
docs(rsc): mention @vitejs/plugin-rsc/types (#816)
1 parent 0a02b83 commit 3568e89

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/plugin-rsc/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export default async function handler(request: Request): Promise<Response> {
168168
},
169169
})
170170
}
171+
172+
// add `import.meta.hot.accept` to handle server module change efficiently
173+
if (import.meta.hot) {
174+
import.meta.hot.accept()
175+
}
171176
```
172177

173178
- [`entry.ssr.tsx`](./examples/starter/src/framework/entry.ssr.tsx)
@@ -517,6 +522,26 @@ export default function myRscFrameworkPlugin() {
517522
}
518523
```
519524
525+
## Typescript
526+
527+
Types for global API are defined in `@vitejs/plugin-rsc/types`. For example, you can add it to `tsconfig.json` to have types for `import.meta.viteRsc` APIs:
528+
529+
```json
530+
{
531+
"compilerOptions": {
532+
"types": ["vite/client", "@vitejs/plugin-rsc/types"]
533+
}
534+
}
535+
```
536+
537+
```ts
538+
import.meta.viteRsc.loadModule
539+
// ^^^^^^^^^^
540+
// <T>(environmentName: string, entryName: string) => Promise<T>
541+
```
542+
543+
See also [Vite documentation](https://vite.dev/guide/api-hmr.html#intellisense-for-typescript) for `vite/client` types.
544+
520545
## Credits
521546
522547
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.

0 commit comments

Comments
 (0)