@@ -66,19 +66,22 @@ export async function render(Component) {
6666 const accept = context . request . headers . get ( "accept" ) ;
6767 const remote = accept . includes ( ";remote" ) ;
6868 const standalone = accept . includes ( ";standalone" ) || remote ;
69- const outlet = (
70- context . request . headers . get ( "react-server-outlet" ) ?? "PAGE_ROOT"
71- ) . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, "_" ) ;
69+ const outlet = decodeURIComponent (
70+ (
71+ context . request . headers . get ( "react-server-outlet" ) ?? "PAGE_ROOT"
72+ ) . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, "_" )
73+ ) ;
7274
7375 const isFormData = context . request . headers
7476 . get ( "content-type" )
7577 ?. includes ( "multipart/form-data" ) ;
7678 let formState ;
77- const serverActionHeader =
78- context . request . headers . get ( "react-server-action" ) ?? null ;
79+ const serverActionHeader = decodeURIComponent (
80+ context . request . headers . get ( "react-server-action" ) ?? null
81+ ) ;
7982 if (
8083 "POST,PUT,PATCH,DELETE" . includes ( context . request . method ) &&
81- ( serverActionHeader || isFormData )
84+ ( ( serverActionHeader && serverActionHeader !== "null" ) || isFormData )
8285 ) {
8386 let action = async function ( ) {
8487 throw new Error ( "Server action not found" ) ;
@@ -128,7 +131,7 @@ export async function render(Component) {
128131 ) ;
129132 }
130133
131- if ( serverActionHeader ) {
134+ if ( serverActionHeader && serverActionHeader !== "null" ) {
132135 const [ serverReferenceModule , serverReferenceName ] =
133136 serverActionHeader . split ( "#" ) ;
134137 action = async ( ) => {
@@ -157,6 +160,11 @@ export async function render(Component) {
157160 }
158161
159162 const { data, actionId, error } = await action ( ) ;
163+ const httpStatus = getContext ( HTTP_STATUS ) ?? {
164+ status : 200 ,
165+ statusText : "OK" ,
166+ } ;
167+ const httpHeaders = getContext ( HTTP_HEADERS ) ?? { } ;
160168
161169 if ( ! isFormData ) {
162170 if ( error ) {
@@ -165,9 +173,10 @@ export async function render(Component) {
165173
166174 return resolve (
167175 new Response ( JSON . stringify ( data ) , {
168- status : 200 ,
176+ ... httpStatus ,
169177 headers : {
170- "content-type" : "application/json" ,
178+ "content-type" : "application/json; charset=utf-8" ,
179+ ...httpHeaders ,
171180 } ,
172181 } )
173182 ) ;
@@ -182,10 +191,11 @@ export async function render(Component) {
182191 const [ result , key ] = formState ;
183192 return resolve (
184193 new Response ( JSON . stringify ( result ) , {
185- status : 200 ,
194+ ... httpStatus ,
186195 headers : {
187- "React-Server-Action-Key" : key ,
188- "content-type" : "application/json" ,
196+ "React-Server-Action-Key" : encodeURIComponent ( key ) ,
197+ "content-type" : "application/json; charset=utf-8" ,
198+ ...httpHeaders ,
189199 } ,
190200 } )
191201 ) ;
@@ -281,7 +291,7 @@ export async function render(Component) {
281291 status : responseFromCache . status ,
282292 statusText : responseFromCache . statusText ,
283293 headers : {
284- "content-type" : "text/x-component" ,
294+ "content-type" : "text/x-component; charset=utf-8 " ,
285295 "cache-control" :
286296 context . request . headers . get ( "cache-control" ) ===
287297 "no-cache"
@@ -352,7 +362,7 @@ export async function render(Component) {
352362 new Response ( stream , {
353363 ...httpStatus ,
354364 headers : {
355- "content-type" : "text/x-component" ,
365+ "content-type" : "text/x-component; charset=utf-8 " ,
356366 "cache-control" :
357367 context . request . headers . get ( "cache-control" ) ===
358368 "no-cache"
@@ -406,7 +416,7 @@ export async function render(Component) {
406416 status : responseFromCache . status ,
407417 statusText : responseFromCache . statusText ,
408418 headers : {
409- "content-type" : "text/html" ,
419+ "content-type" : "text/html; charset=utf-8 " ,
410420 "cache-control" :
411421 context . request . headers . get ( "cache-control" ) ===
412422 "no-cache"
@@ -500,7 +510,7 @@ export async function render(Component) {
500510 new Response ( responseStream , {
501511 ...httpStatus ,
502512 headers : {
503- "content-type" : "text/html" ,
513+ "content-type" : "text/html; charset=utf-8 " ,
504514 "cache-control" :
505515 context . request . headers . get ( "cache-control" ) ===
506516 "no-cache"
0 commit comments