-
-
Couldn't load subscription status.
- Fork 191
Open
Labels
Description
Not sure what this means but we can somehow polish and generalize this example, so it's usable on Waku, React router, etc.
vite-plugin-react/packages/plugin-rsc/examples/basic/vite.config.ts
Lines 312 to 337 in 954b361
| function vitePluginUseCache(): Plugin[] { | |
| return [ | |
| { | |
| name: 'use-cache', | |
| async transform(code) { | |
| if (!code.includes('use cache')) return | |
| const ast = await parseAstAsync(code) | |
| // @ts-ignore for rolldown-vite ci estree/oxc mismatch | |
| const result = transformHoistInlineDirective(code, ast, { | |
| runtime: (value) => `__vite_rsc_cache(${value})`, | |
| directive: 'use cache', | |
| rejectNonAsyncFunction: true, | |
| noExport: true, | |
| }) | |
| if (!result.output.hasChanged()) return | |
| result.output.prepend( | |
| `import __vite_rsc_cache from "/src/framework/use-cache-runtime";`, | |
| ) | |
| return { | |
| code: result.output.toString(), | |
| map: result.output.generateMap({ hires: 'boundary' }), | |
| } | |
| }, | |
| }, | |
| ] | |
| } |
See also hi-ogawa/vite-plugins#902 for more context.
(Also I'm feeling stacking together transformHoistInlineDirective for "use cache" and internally for "use server" can break something. We want to investigate that.)
Or we can use externally maintained: