Skip to content

Commit 23daadd

Browse files
committed
wip
1 parent 2383c75 commit 23daadd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/plugin-rsc/examples/basic/vite.config.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,25 @@ function vitePluginBrowserOnly(): Plugin[] {
182182
return [
183183
{
184184
name: 'browser-only-component',
185-
load(id: string) {
185+
load(id, code) {
186186
if (id.endsWith('?browser-only')) {
187-
this.environment.name === 'ssr'
188-
this.environment.name === 'rsc'
189-
this.environment.name === 'client'
187+
if (this.environment.name === 'rsc') return
188+
189+
id = id.slice(0, -'?browser-only'.length)
190+
if (this.environment.name === 'ssr') {
191+
code
192+
// const Test = React.lazy(() => import('./test-browser-only?browser-only'))
193+
return `\
194+
export default () => {
195+
throw new Error('Browser-only component on SSR')
196+
};
197+
`
198+
}
199+
if (this.environment.name === 'client') {
200+
return `\
201+
export { default } from ${JSON.stringify(id)}
202+
`
203+
}
190204
}
191205
},
192206
},

0 commit comments

Comments
 (0)