File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
packages/plugin-rsc/examples/basic Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff 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 } ,
You can’t perform that action at this time.
0 commit comments