diff --git a/packages/plugin-rsc/README.md b/packages/plugin-rsc/README.md index cb5bcb6e..bb913e38 100644 --- a/packages/plugin-rsc/README.md +++ b/packages/plugin-rsc/README.md @@ -168,6 +168,11 @@ export default async function handler(request: Request): Promise { }, }) } + +// add `import.meta.hot.accept` to handle server module change efficiently +if (import.meta.hot) { + import.meta.hot.accept() +} ``` - [`entry.ssr.tsx`](./examples/starter/src/framework/entry.ssr.tsx) @@ -517,6 +522,26 @@ export default function myRscFrameworkPlugin() { } ``` +## Typescript + +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: + +```json +{ + "compilerOptions": { + "types": ["vite/client", "@vitejs/plugin-rsc/types"] + } +} +``` + +```ts +import.meta.viteRsc.loadModule +// ^^^^^^^^^^ +// (environmentName: string, entryName: string) => Promise +``` + +See also [Vite documentation](https://vite.dev/guide/api-hmr.html#intellisense-for-typescript) for `vite/client` types. + ## Credits This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.