Skip to content

Commit 0b5110a

Browse files
committed
Add server function inspector
1 parent db4c511 commit 0b5110a

38 files changed

+2137
-268
lines changed

apps/tests/src/routes/server-function-ping.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
import { createEffect, createSignal } from "solid-js";
22

3-
async function ping(value: string) {
3+
async function sleep(value: unknown, ms: number) {
4+
return new Promise((res) => {
5+
setTimeout(res, ms, value);
6+
})
7+
}
8+
9+
async function ping(value: Date) {
410
"use server";
511

6-
return await Promise.resolve(value);
12+
const current = [
13+
value,
14+
{
15+
name: 'example',
16+
async *[Symbol.asyncIterator]() {
17+
yield sleep('foo', 5000);
18+
yield sleep('bar', 5000);
19+
yield sleep('baz', 5000);
20+
}
21+
}
22+
];
23+
24+
return current;
725
}
826

927
export default function App() {
1028
const [output, setOutput] = createSignal<{ result?: boolean }>({});
1129

1230
createEffect(async () => {
13-
const value = `${Math.random() * 1000}`;
31+
const value = new Date();
1432
const result = await ping(value);
15-
setOutput(prev => ({ ...prev, result: value === result }));
33+
await ping(value);
34+
console.log(result);
35+
setOutput((prev) => ({ ...prev, result: value.toString() === result[0].toString() }));
1636
});
1737

1838
return (

apps/tests/test-results/.last-run.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/start/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
"path-to-regexp": "^8.2.0",
5757
"pathe": "^2.0.3",
5858
"radix3": "^1.1.2",
59-
"seroval": "^1.4.1",
59+
"seroval": "^1.4.2",
6060
"seroval-plugins": "^1.4.0",
6161
"shiki": "^1.26.1",
6262
"solid-js": "^1.9.9",
6363
"source-map-js": "^1.2.1",
6464
"srvx": "^0.9.1",
65-
"terracotta": "^1.0.6",
65+
"terracotta": "^1.1.0",
6666
"vite-plugin-solid": "^2.11.9"
6767
},
6868
"engines": {

packages/start/src/server/serialization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function serializeToJSONStream(value: any) {
111111
});
112112
}
113113

114-
class SerovalChunkReader {
114+
export class SerovalChunkReader {
115115
reader: ReadableStreamDefaultReader<Uint8Array>;
116116
buffer: Uint8Array;
117117
done: boolean;

packages/start/src/server/server-runtime.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
21
import { type Component } from "solid-js";
2+
import {
3+
pushRequest,
4+
pushResponse,
5+
} from "../shared/server-function-inspector/server-function-tracker";
36
import {
47
deserializeJSONStream,
58
deserializeJSStream,
@@ -9,13 +12,13 @@ import {
912

1013
let 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
}
2839
async 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 {

packages/start/src/shared/ErrorBoundary.tsx

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
11
// @refresh skip
2-
import { ErrorBoundary as DefaultErrorBoundary, catchError, type ParentProps } from "solid-js";
2+
import {
3+
catchError,
4+
ErrorBoundary as DefaultErrorBoundary,
5+
type ParentProps,
6+
} from "solid-js";
37
import { isServer } from "solid-js/web";
4-
import { HttpStatusCode } from "./HttpStatusCode.ts";
58
import { DevOverlay } from "./dev-overlay/index.tsx";
9+
import { HttpStatusCode } from "./HttpStatusCode.ts";
10+
import { ServerFunctionInspector } from "./server-function-inspector/index.tsx";
611

712
export const ErrorBoundary =
813
import.meta.env.DEV && import.meta.env.START_DEV_OVERLAY
9-
? (props: ParentProps) => <DevOverlay>{props.children}</DevOverlay>
14+
? (props: ParentProps) => (
15+
<DevOverlay>
16+
<ServerFunctionInspector />
17+
{props.children}
18+
</DevOverlay>
19+
)
1020
: (props: ParentProps) => {
11-
const message = isServer
12-
? "500 | Internal Server Error"
13-
: "Error | Uncaught Client Exception";
14-
return (
15-
<DefaultErrorBoundary
16-
fallback={error => {
17-
console.error(error);
18-
return (
19-
<>
20-
<span style="font-size:1.5em;text-align:center;position:fixed;left:0px;bottom:55%;width:100%;">
21-
{message}
22-
</span>
23-
<HttpStatusCode code={500} />
24-
</>
25-
);
26-
}}
27-
>
28-
{props.children}
29-
</DefaultErrorBoundary>
30-
);
31-
};
21+
const message = isServer
22+
? "500 | Internal Server Error"
23+
: "Error | Uncaught Client Exception";
24+
return (
25+
<DefaultErrorBoundary
26+
fallback={(error) => {
27+
console.error(error);
28+
return (
29+
<>
30+
<span style="font-size:1.5em;text-align:center;position:fixed;left:0px;bottom:55%;width:100%;">
31+
{message}
32+
</span>
33+
<HttpStatusCode code={500} />
34+
</>
35+
);
36+
}}
37+
>
38+
{props.children}
39+
</DefaultErrorBoundary>
40+
);
41+
};
3242

3343
export const TopErrorBoundary = (props: ParentProps) => {
3444
let isError = false;
3545
const res = catchError(
3646
() => props.children,
37-
err => {
47+
(err) => {
3848
console.error(err);
3949
isError = !!err;
4050
},

0 commit comments

Comments
 (0)