File tree Expand file tree Collapse file tree 5 files changed +39
-39
lines changed
packages/plugin-rsc/examples/browser-mode2/src/framework Expand file tree Collapse file tree 5 files changed +39
-39
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,9 @@ import {
88} from '@vitejs/plugin-rsc/browser'
99import type { RscPayload } from './entry.rsc'
1010
11- let fetchRsc : ( request : Request ) => Promise < Response >
12-
13- export function initialize ( options : {
14- fetchRsc : ( request : Request ) => Promise < Response >
15- } ) {
16- fetchRsc = options . fetchRsc
11+ async function fetchRsc ( request : Request ) : Promise < Response > {
12+ const module = await import ( 'virtual:vite-rsc-browser-mode2/load-rsc' )
13+ return module . default . fetch ( request )
1714}
1815
1916export async function main ( ) {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export type RscPayload = {
1515 formState ?: ReactFormState
1616}
1717
18- export default async function handler ( request : Request ) : Promise < Response > {
18+ async function handler ( request : Request ) : Promise < Response > {
1919 const isAction = request . method === 'POST'
2020 let returnValue : unknown | undefined
2121 let formState : ReactFormState | undefined
@@ -51,6 +51,10 @@ export default async function handler(request: Request): Promise<Response> {
5151 } )
5252}
5353
54+ export default {
55+ fetch : handler ,
56+ }
57+
5458if ( import . meta. hot ) {
5559 import . meta. hot . accept ( )
5660}
Original file line number Diff line number Diff line change 11import { ESModulesEvaluator , ModuleRunner } from 'vite/module-runner'
22
3- export default async function loadRsc ( ) {
4- const runner = new ModuleRunner (
5- {
6- sourcemapInterceptor : false ,
7- transport : {
8- invoke : async ( payload ) => {
9- const response = await fetch (
10- '/@vite/invoke-rsc?' +
11- new URLSearchParams ( {
12- data : JSON . stringify ( payload ) ,
13- } ) ,
14- )
15- return response . json ( )
16- } ,
3+ const runner = new ModuleRunner (
4+ {
5+ sourcemapInterceptor : false ,
6+ transport : {
7+ invoke : async ( payload ) => {
8+ const response = await fetch (
9+ '/@vite/invoke-rsc?' +
10+ new URLSearchParams ( {
11+ data : JSON . stringify ( payload ) ,
12+ } ) ,
13+ )
14+ return response . json ( )
1715 } ,
18- hmr : false ,
1916 } ,
20- new ESModulesEvaluator ( ) ,
21- )
22- return await runner . import < typeof import ( './entry.rsc' ) > (
23- '/src/framework/entry.rsc.tsx' ,
24- )
25- }
17+ hmr : false ,
18+ } ,
19+ new ESModulesEvaluator ( ) ,
20+ )
21+
22+ export default new Proxy (
23+ { } ,
24+ {
25+ get ( _target , p , _receiver ) {
26+ return async ( ...args : any [ ] ) => {
27+ const module = await runner . import ( '/src/framework/entry.rsc.tsx' )
28+ return module . default [ p ] ( ...args )
29+ }
30+ } ,
31+ } ,
32+ )
Original file line number Diff line number Diff line change 1- import * as client from './entry.browser'
2- import loadRsc from 'virtual:vite-rsc-browser-mode2/load-rsc'
3-
4- async function main ( ) {
5- const rsc = await loadRsc ( )
6- client . initialize ( { fetchRsc : rsc . default } )
7- await client . main ( )
8- }
9-
1+ import { main } from './entry.browser'
102main ( )
Original file line number Diff line number Diff line change 11declare module 'virtual:vite-rsc-browser-mode2/load-rsc' {
2- const loadRsc : ( ) => Promise < typeof import ( './entry.rsc' ) >
3- export default loadRsc
2+ const default_ : typeof import ( './entry.rsc.tsx' ) . default
3+ export default default_
44}
You can’t perform that action at this time.
0 commit comments