@@ -88,37 +88,29 @@ export function createRpcClient<T>(options: { endpoint: string }): T {
8888
8989const encodePlugin : EncodePlugin = ( value ) => {
9090 if ( value instanceof Response ) {
91- return [
92- 'vite-rsc/response' ,
93- value . status ,
94- value . statusText ,
95- [ ...value . headers ] ,
91+ const data : ConstructorParameters < typeof Response > = [
9692 value . body ,
93+ {
94+ status : value . status ,
95+ statusText : value . statusText ,
96+ headers : value . headers ,
97+ } ,
9798 ]
99+ return [ 'vite-rsc/response' , ...data ]
98100 }
99101 if ( value instanceof Headers ) {
100- return [ 'vite-rsc/headers' , [ ...value ] ]
102+ const data : ConstructorParameters < typeof Headers > = [ [ ...value ] ]
103+ return [ 'vite-rsc/headers' , ...data ]
101104 }
102105}
103106
104107const decodePlugin : DecodePlugin = ( type , ...data ) => {
105108 if ( type === 'vite-rsc/response' ) {
106- const [ status , statusText , headers , body ] = data as [
107- number ,
108- string ,
109- [ string , string ] [ ] ,
110- ReadableStream < Uint8Array > | null ,
111- ]
112- const value = new Response ( body , {
113- status,
114- statusText,
115- headers,
116- } )
109+ const value = new Response ( ...( data as any ) )
117110 return { value }
118111 }
119112 if ( type === 'vite-rsc/headers' ) {
120- const [ headers ] = data as [ [ string , string ] [ ] ]
121- const value = new Headers ( headers )
113+ const value = new Headers ( ...( data as any ) )
122114 return { value }
123115 }
124116}
0 commit comments