Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/plugin-rsc/examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"@vitejs/test-dep-transitive-use-sync-external-store": "file:./test-dep/transitive-use-sync-external-store",
"rsc-html-stream": "^0.0.7",
"tailwindcss": "^4.1.14",
"unstorage": "^1.17.1",
"vite": "^7.1.9",
"vite-plugin-react-use-cache": "^0.0.4",
"wrangler": "^4.42.2"
},
"stackblitz": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { revalidateCache } from '../../framework/use-cache-runtime'
// import { revalidateCache } from '../../framework/use-cache-runtime'
import { cacheTag, revalidateTag } from 'vite-plugin-react-use-cache/runtime'

export function TestUseCache() {
return (
Expand All @@ -20,7 +21,8 @@ function TestUseCacheFn() {
const argument = formData.get('argument')
await testFn(argument)
if (argument === 'revalidate') {
revalidateCache(testFn)
// revalidateCache(testFn)
revalidateTag('testFn')
}
}}
>
Expand All @@ -38,6 +40,7 @@ let cacheFnCount = 0

async function testFn(..._args: unknown[]) {
'use cache'
cacheTag('testFn')
cacheFnCount++
}

Expand Down
23 changes: 19 additions & 4 deletions packages/plugin-rsc/examples/basic/src/server.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { handleRequest } from './framework/entry.rsc.tsx'
import './styles.css'
import { createStorage } from 'unstorage'
import fsDriver from 'unstorage/drivers/fs'
import { provideCache } from 'vite-plugin-react-use-cache/runtime'
import { createUnstorageCache } from 'vite-plugin-react-use-cache/unstorage'

const storage = createStorage({
driver: fsDriver({ base: './node_modules/.use-cache' }),
})

async function handler(request: Request): Promise<Response> {
const url = new URL(request.url)
Expand All @@ -16,11 +24,18 @@ async function handler(request: Request): Promise<Response> {
<Root url={url} />
</>
)
const response = await handleRequest({
request,
getRoot: () => root,
nonce,
const response = await provideCache(createUnstorageCache(storage), () => {
return handleRequest({
request,
getRoot: () => root,
nonce,
})
})
// const response = await handleRequest({
// request,
// getRoot: () => root,
// nonce,
// })
if (nonce && response.headers.get('content-type')?.includes('text/html')) {
const cspValue = [
`default-src 'self';`,
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-rsc/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import {
import path from 'node:path'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { useCachePlugin } from 'vite-plugin-react-use-cache'

export default defineConfig({
clearScreen: false,
plugins: [
// inspect(),
tailwindcss(),
react(),
vitePluginUseCache(),
useCachePlugin(),
// vitePluginUseCache(),
rsc({
entries: {
client: './src/framework/entry.browser.tsx',
Expand Down
Loading
Loading