Skip to content

Commit 49966c4

Browse files
committed
fix: patch rsc:inject-async-local-storage
1 parent 572cbc8 commit 49966c4

File tree

1 file changed

+13
-67
lines changed

1 file changed

+13
-67
lines changed

packages/plugin-rsc/examples/browser-mode2/vite.config.ts

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,43 @@
11
import { defineConfig, type Plugin } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import rsc from '@vitejs/plugin-rsc'
4-
import fsp from 'node:fs/promises'
54

65
export default defineConfig({
6+
appType: 'spa',
77
plugins: [
8-
spaPlugin(),
98
react(),
109
rsc({
10+
serverHandler: false,
1111
entries: {
1212
rsc: './src/framework/entry.rsc.tsx',
1313
},
1414
}),
1515
rscBrowserMode2Plugin(),
16+
{
17+
name: 'patch-rsc',
18+
configResolved(config) {
19+
const plugin = config.plugins.find(
20+
(p) => p.name === 'rsc:inject-async-local-storage',
21+
)
22+
delete plugin!.transform
23+
},
24+
},
1625
],
17-
define: {
18-
'process.env.NODE_ENV': JSON.stringify('development'),
19-
},
2026
environments: {
2127
rsc: {
28+
keepProcessEnv: false,
2229
resolve: {
2330
noExternal: true,
24-
alias: {
25-
'node:async_hooks': '/src/framework/async-hooks-polyfill.js',
26-
},
2731
},
2832
optimizeDeps: {
29-
include: [
30-
'react',
31-
'react-dom',
32-
'react/jsx-runtime',
33-
'react/jsx-dev-runtime',
34-
'@vitejs/plugin-rsc/vendor/react-server-dom/server.edge',
35-
'@vitejs/plugin-rsc/vendor/react-server-dom/client.edge',
36-
],
37-
exclude: ['@vitejs/plugin-rsc'],
3833
esbuildOptions: {
39-
platform: 'browser',
34+
platform: 'neutral',
4035
},
4136
},
4237
},
4338
},
4439
})
4540

46-
function spaPlugin(): Plugin[] {
47-
// serve index.html before rsc server
48-
return [
49-
{
50-
name: 'serve-spa',
51-
configureServer(server) {
52-
return () => {
53-
server.middlewares.use(async (req, res, next) => {
54-
try {
55-
if (req.headers.accept?.includes('text/html')) {
56-
const html = await fsp.readFile('index.html', 'utf-8')
57-
const transformed = await server.transformIndexHtml('/', html)
58-
res.setHeader('Content-type', 'text/html')
59-
res.setHeader('Vary', 'accept')
60-
res.end(transformed)
61-
return
62-
}
63-
} catch (error) {
64-
next(error)
65-
return
66-
}
67-
next()
68-
})
69-
}
70-
},
71-
configurePreviewServer(server) {
72-
return () => {
73-
server.middlewares.use(async (req, res, next) => {
74-
try {
75-
if (req.headers.accept?.includes('text/html')) {
76-
const html = await fsp.readFile(
77-
'dist/client/index.html',
78-
'utf-8',
79-
)
80-
res.end(html)
81-
return
82-
}
83-
} catch (error) {
84-
next(error)
85-
return
86-
}
87-
next()
88-
})
89-
}
90-
},
91-
},
92-
]
93-
}
94-
9541
function rscBrowserMode2Plugin(): Plugin[] {
9642
return [
9743
{

0 commit comments

Comments
 (0)