Skip to content

Commit b32d7fa

Browse files
committed
Add server function inspector
1 parent fef3a2a commit b32d7fa

38 files changed

+2054
-176
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { type Component } from "solid-js";
2+
import {
3+
pushRequest,
4+
pushResponse,
5+
} from "../shared/server-function-inspector/server-function-tracker";
26
import {
37
deserializeJSONStream,
48
deserializeJSStream,
@@ -9,13 +13,13 @@ import { BODY_FORMAL_FILE, BODY_FORMAT_KEY, BodyFormat } from "./server-function
913

1014
let INSTANCE = 0;
1115

12-
function createRequest(
16+
async function createRequest(
1317
base: string,
1418
id: string,
1519
instance: string,
1620
options: RequestInit,
1721
) {
18-
return fetch(base, {
22+
const request = new Request(base, {
1923
method: "POST",
2024
...options,
2125
headers: {
@@ -24,6 +28,14 @@ function createRequest(
2428
"X-Server-Instance": instance,
2529
},
2630
});
31+
if (import.meta.env.DEV) {
32+
pushRequest(id, instance, request.clone());
33+
}
34+
const response = await fetch(request);
35+
if (import.meta.env.DEV) {
36+
pushResponse(id, instance, response.clone());
37+
}
38+
return response;
2739
}
2840

2941
function getHeadersAndBody(body: any): {

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)