@@ -88,37 +88,29 @@ export function createRpcClient<T>(options: { endpoint: string }): T {
88
88
89
89
const encodePlugin : EncodePlugin = ( value ) => {
90
90
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 > = [
96
92
value . body ,
93
+ {
94
+ status : value . status ,
95
+ statusText : value . statusText ,
96
+ headers : value . headers ,
97
+ } ,
97
98
]
99
+ return [ 'vite-rsc/response' , ...data ]
98
100
}
99
101
if ( value instanceof Headers ) {
100
- return [ 'vite-rsc/headers' , [ ...value ] ]
102
+ const data : ConstructorParameters < typeof Headers > = [ [ ...value ] ]
103
+ return [ 'vite-rsc/headers' , ...data ]
101
104
}
102
105
}
103
106
104
107
const decodePlugin : DecodePlugin = ( type , ...data ) => {
105
108
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 ) )
117
110
return { value }
118
111
}
119
112
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 ) )
122
114
return { value }
123
115
}
124
116
}
0 commit comments