1-
21import { type Component } from "solid-js" ;
2+ import {
3+ pushRequest ,
4+ pushResponse ,
5+ } from "../shared/server-function-inspector/server-function-tracker" ;
36import {
47 deserializeJSONStream ,
58 deserializeJSStream ,
@@ -9,13 +12,13 @@ import {
912
1013let INSTANCE = 0 ;
1114
12- function createRequest (
15+ async function createRequest (
1316 base : string ,
1417 id : string ,
1518 instance : string ,
1619 options : RequestInit ,
1720) {
18- return fetch ( base , {
21+ const request = new Request ( base , {
1922 method : "POST" ,
2023 ...options ,
2124 headers : {
@@ -24,6 +27,14 @@ function createRequest(
2427 "X-Server-Instance" : instance ,
2528 } ,
2629 } ) ;
30+ if ( import . meta. env . DEV ) {
31+ pushRequest ( id , instance , request . clone ( ) ) ;
32+ }
33+ const response = await fetch ( request ) ;
34+ if ( import . meta. env . DEV ) {
35+ pushResponse ( id , instance , response . clone ( ) ) ;
36+ }
37+ return response ;
2738}
2839async function fetchServerFunction (
2940 base : string ,
@@ -54,7 +65,7 @@ async function fetchServerFunction(
5465 headers : {
5566 ...options . headers ,
5667 "x-serialized" : "true" ,
57- "Content-Type" : "text/plain"
68+ "Content-Type" : "text/plain" ,
5869 } ,
5970 } ) ) ;
6071
@@ -82,7 +93,7 @@ async function fetchServerFunction(
8293 result = await clone . text ( ) ;
8394 } else if ( contentType ?. startsWith ( "application/json" ) ) {
8495 result = await clone . json ( ) ;
85- } else if ( response . headers . get ( ' x-serialized' ) ) {
96+ } else if ( response . headers . get ( " x-serialized" ) ) {
8697 if ( import . meta. env . SEROVAL_MODE === "js" ) {
8798 result = await deserializeJSStream ( instance , clone ) ;
8899 } else {
0 commit comments