Skip to content

Commit fce37a8

Browse files
committed
fix copilot suggestions
1 parent 0defa47 commit fce37a8

8 files changed

Lines changed: 80 additions & 75 deletions

File tree

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
},
55
"typescript.tsdk": "node_modules/typescript/lib",
66
"editor.formatOnSave": true,
7-
"editor.defaultFormatter": "oxc.oxc-vscode"
7+
"editor.defaultFormatter": "oxc.oxc-vscode",
8+
"[typescript]": {
9+
"editor.defaultFormatter": "oxc.oxc-vscode"
10+
},
11+
"[typescriptreact]": {
12+
"editor.defaultFormatter": "oxc.oxc-vscode"
13+
}
814
}

apps/tests/src/e2e/server-function.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ test.describe("server-function", () => {
7777
await page.goto("http://localhost:3000/server-function-form-data");
7878
await expect(page.locator("#server-fn-test")).toContainText('{"result":true}');
7979
});
80+
test("should build with a server function w/ blob data", async ({ page }) => {
81+
await page.goto("http://localhost:3000/server-function-blob");
82+
await expect(page.locator("#server-fn-test")).toContainText('{"result":true}');
83+
});
8084
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ async function ping(value: Blob) {
55
return value;
66
}
77

8-
const blobURI = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAxNjYgMTU1LjMnPjxwYXRoIGQ9J00xNjMgMzVTMTEwLTQgNjkgNWwtMyAxYy02IDItMTEgNS0xNCA5bC0yIDMtMTUgMjYgMjYgNWMxMSA3IDI1IDEwIDM4IDdsNDYgOSAxOC0zMHonIGZpbGw9JyM3NmIzZTEnLz48bGluZWFyR3JhZGllbnQgaWQ9J2EnIGdyYWRpZW50VW5pdHM9J3VzZXJTcGFjZU9uVXNlJyB4MT0nMjcuN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BhY2VPblVzZScgeDE9JzE4LjQnIHkxPSc2NC4yJyB4Mj0nMTQ0LjMnIHkyPScxNDkuOCc+PHN0b3Agb2Zmc2V0PScwJyBzdG9wLWNvbG9yPScjMzE1YWE5Jy8+PHN0b3Agb2Zmc2V0PScuNScgc3RvcC1jb2xvcj0nIzUxOGFjOCcvPjxzdG9wIG9mZnNldD0nMScgc3RvcC1jb2xvcj0nIzMxNWFhOScvPjwvbGluZWFyR3JhZGllbnQ+PHBhdGggZD0nTTEzNCA4MGE0NSA0NSAwIDAwLTQ4LTE1TDI0IDg1IDQgMTIwbDExMiAxOSAyMC0zNmM0LTcgMy0xNS0yLTIzeicgZmlsbD0ndXJsKCNjKScvPjxsaW5lYXJHcmFkaWVudCBpZD0nZCcgZ3JhZGllbnRVbml0cz0ndXNlclNwYWNlT25Vc2UnIHgxPSc3NS4yJyB5MT0nNzQuNScgeDI9JzI0LjQnIHkyPScyNjAuOCc+PHN0b3Agb2Zmc2V0PScwJyBzdG9wLWNvbG9yPScjNDM3N2JiJy8+PHN0b3Agb2Zmc2V0PScuNScgc3RvcC1jb2xvcj0nIzFhMzM2YicvPjxzdG9wIG9mZnNldD0nMScgc3RvcC1jb2xvcj0nIzFhMzM2YicvPjwvbGluZWFyR3JhZGllbnQ+PHBhdGggZD0nTTExNCAxMTVhNDUgNDUgMCAwMC00OC0xNUw0IDEyMHM1MyA0MCA5NCAzMGwzLTFjMTctNSAyMy0yMSAxMy0zNHonIGZpbGw9J3VybCgjZCknLz48L3N2Zz4=";
910

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

apps/tests/src/routes/server-function-form-data.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { createEffect, createSignal } from "solid-js";
22

33
async function ping(value: FormData) {
44
"use server";
5-
const file = value.get('example') as File;
5+
const file = value.get("example") as File;
66
return await file.text();
77
}
88

99
export default function App() {
1010
const [output, setOutput] = createSignal<{ result?: boolean }>({});
1111

1212
createEffect(async () => {
13-
const file = new File(['Hello, World!'], 'hello-world.txt');
13+
const file = new File(["Hello, World!"], "hello-world.txt");
1414
const formData = new FormData();
15-
formData.append('example', file);
15+
formData.append("example", file);
1616
const result = await ping(formData);
1717
const value = await file.text();
1818
setOutput(prev => ({ ...prev, result: value === result }));

packages/start/src/config/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface SolidStartOptions {
2323
middleware?: string;
2424
serialization?: {
2525
// This only matters for server function responses
26-
mode?: 'js' | 'json';
26+
mode?: "js" | "json";
2727
};
2828
}
2929

@@ -135,7 +135,7 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
135135
"import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
136136
"import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
137137
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
138-
"import.meta.env.SEROVAL_MODE": JSON.stringify(start.serialization?.mode || 'json'),
138+
"import.meta.env.SEROVAL_MODE": JSON.stringify(start.serialization?.mode || "json"),
139139
},
140140
builder: {
141141
sharedPlugins: true,
@@ -181,7 +181,7 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
181181
envName: VITE_ENVIRONMENTS.client,
182182
getRuntimeCode: () =>
183183
`import { createServerReference } from "${normalizePath(
184-
fileURLToPath(new URL("../server/server-runtime", import.meta.url))
184+
fileURLToPath(new URL("../server/server-runtime", import.meta.url)),
185185
)}"`,
186186
replacer: opts => `createServerReference('${opts.functionId}')`,
187187
},
@@ -190,7 +190,7 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
190190
envName: VITE_ENVIRONMENTS.server,
191191
getRuntimeCode: () =>
192192
`import { createServerReference } from '${normalizePath(
193-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url))
193+
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
194194
)}'`,
195195
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
196196
},
@@ -199,7 +199,7 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
199199
envName: VITE_ENVIRONMENTS.server,
200200
getRuntimeCode: () =>
201201
`import { createServerReference } from '${normalizePath(
202-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url))
202+
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
203203
)}'`,
204204
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
205205
},

packages/start/src/server/server-functions-handler.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import {
1212
serializeToJSONStream,
1313
serializeToJSStream,
1414
} from "./serialization.ts";
15-
import { BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody } from "./server-functions-shared.ts";
15+
import {
16+
BODY_FORMAT_KEY,
17+
BodyFormat,
18+
extractBody,
19+
getHeadersAndBody,
20+
} from "./server-functions-shared.ts";
1621
import type { FetchEvent, PageEvent } from "./types.ts";
1722
import { getExpectedRedirectStatus } from "./util.ts";
1823

@@ -52,8 +57,14 @@ export async function handleServerFunction(h3Event: H3Event) {
5257
}
5358
}
5459
}
55-
if (request.method === "POST") {
56-
parsed.push(await extractBody('', false, request.clone()));
60+
if (request.method === "POST" && request.body !== null) {
61+
const bodyFormat = request.headers.get(BODY_FORMAT_KEY);
62+
const decoded = await extractBody("", false, request.clone());
63+
if (bodyFormat === BodyFormat.Seroval) {
64+
parsed = decoded as any[];
65+
} else {
66+
parsed.push(decoded);
67+
}
5768
}
5869
try {
5970
let result = await provideRequestEvent(event, async () => {
@@ -87,18 +98,19 @@ export async function handleServerFunction(h3Event: H3Event) {
8798
// handle no JS success case
8899
if (!instance) return handleNoJS(result, request, parsed);
89100

90-
const body = getHeadersAndBody(result);
91-
if (body) {
92-
return new Response(body.body, {
93-
headers: body.headers,
94-
});
95-
}
96-
h3Event.res.headers.set(BODY_FORMAT_KEY, BodyFormat.Seroval);
97-
if (import.meta.env.SEROVAL_MODE === "js") {
98-
h3Event.res.headers.set("content-type", "text/javascript");
99-
return serializeToJSStream(instance, result);
100-
}
101-
return serializeToJSONStream(result);
101+
const body = getHeadersAndBody(result);
102+
if (body) {
103+
return new Response(body.body, {
104+
headers: body.headers,
105+
});
106+
}
107+
h3Event.res.headers.set(BODY_FORMAT_KEY, BodyFormat.Seroval);
108+
if (import.meta.env.SEROVAL_MODE === "js") {
109+
h3Event.res.headers.set("content-type", "text/javascript");
110+
return serializeToJSStream(instance, result);
111+
}
112+
h3Event.res.headers.set("content-type", "text/plain");
113+
return serializeToJSONStream(result);
102114
} catch (x) {
103115
if (x instanceof Response) {
104116
if (singleFlight && instance) {
@@ -107,18 +119,14 @@ export async function handleServerFunction(h3Event: H3Event) {
107119
// forward headers
108120
if ((x as any).headers) mergeResponseHeaders(h3Event, (x as any).headers);
109121
// forward non-redirect statuses
110-
if (
111-
(x as any).status &&
112-
(!instance || (x as any).status < 300 || (x as any).status >= 400)
113-
)
122+
if ((x as any).status && (!instance || (x as any).status < 300 || (x as any).status >= 400))
114123
h3Event.res.status = (x as any).status;
115124
if ((x as any).customBody) {
116-
x = (x as any).customBody();
117-
} else if ((x as any).body === undefined) x = null;
125+
x = await (x as any).customBody();
126+
} else if ((x as any).body == null) x = null;
118127
h3Event.res.headers.set("X-Error", "true");
119128
} else if (instance) {
120-
const error =
121-
x instanceof Error ? x.message : typeof x === "string" ? x : "true";
129+
const error = x instanceof Error ? x.message : typeof x === "string" ? x : "true";
122130

123131
h3Event.res.headers.set("X-Error", error.replace(/[\r\n]+/g, ""));
124132
} else {
@@ -127,6 +135,11 @@ export async function handleServerFunction(h3Event: H3Event) {
127135
if (instance) {
128136
const body = getHeadersAndBody(x);
129137
if (body) {
138+
const headers = new Headers(body.headers as HeadersInit);
139+
const errorHeader = h3Event.res.headers.get("X-Error");
140+
if (errorHeader !== null) {
141+
headers.set("X-Error", errorHeader);
142+
}
130143
return new Response(body.body, {
131144
headers: body.headers,
132145
});
@@ -136,18 +149,14 @@ export async function handleServerFunction(h3Event: H3Event) {
136149
h3Event.res.headers.set("content-type", "text/javascript");
137150
return serializeToJSStream(instance, x);
138151
}
152+
h3Event.res.headers.set("content-type", "text/plain");
139153
return serializeToJSONStream(x);
140154
}
141155
return x;
142156
}
143157
}
144158

145-
function handleNoJS(
146-
result: any,
147-
request: Request,
148-
parsed: any[],
149-
thrown?: boolean,
150-
) {
159+
function handleNoJS(result: any, request: Request, parsed: any[], thrown?: boolean) {
151160
const url = new URL(request.url);
152161
const isError = result instanceof Error;
153162
let statusCode = 302;
@@ -157,10 +166,7 @@ function handleNoJS(
157166
if (result.headers.has("Location")) {
158167
headers.set(
159168
`Location`,
160-
new URL(
161-
result.headers.get("Location")!,
162-
url.origin + import.meta.env.BASE_URL,
163-
).toString(),
169+
new URL(result.headers.get("Location")!, url.origin + import.meta.env.BASE_URL).toString(),
164170
);
165171
statusCode = getExpectedRedirectStatus(result);
166172
}
@@ -177,10 +183,7 @@ function handleNoJS(
177183
result: isError ? result.message : result,
178184
thrown: thrown,
179185
error: isError,
180-
input: [
181-
...parsed.slice(0, -1),
182-
[...parsed[parsed.length - 1].entries()],
183-
],
186+
input: [...parsed.slice(0, -1), [...parsed[parsed.length - 1].entries()]],
184187
}),
185188
)}; Secure; HttpOnly;`,
186189
);
@@ -206,7 +209,7 @@ function createSingleFlightHeaders(sourceEvent: FetchEvent) {
206209
// useH3Internals = true;
207210
// sourceEvent.nativeEvent.node.req.headers.cookie = "";
208211
// }
209-
SetCookies.forEach((cookie) => {
212+
SetCookies.forEach(cookie => {
210213
if (!cookie) return;
211214
const { maxAge, expires, name, value } = parseSetCookie(cookie);
212215
if (maxAge != null && maxAge <= 0) {
@@ -227,10 +230,7 @@ function createSingleFlightHeaders(sourceEvent: FetchEvent) {
227230

228231
return headers;
229232
}
230-
async function handleSingleFlight(
231-
sourceEvent: FetchEvent,
232-
result: any,
233-
): Promise<Response> {
233+
async function handleSingleFlight(sourceEvent: FetchEvent, result: any): Promise<Response> {
234234
let revalidate: string[];
235235
let url = new URL(sourceEvent.request.headers.get("referer")!).toString();
236236
if (result instanceof Response) {

packages/start/src/server/server-functions-shared.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export const enum BodyFormat {
1717

1818
export function getHeadersAndBody(body: any):
1919
| {
20-
headers?: HeadersInit;
21-
body: BodyInit;
22-
}
20+
headers?: HeadersInit;
21+
body: BodyInit;
22+
}
2323
| undefined {
2424
switch (true) {
2525
case typeof body === "string":
@@ -109,7 +109,7 @@ export async function extractBody(instance: string, client: boolean, source: Req
109109
case startType === BodyFormat.ArrayBuffer:
110110
return await clone.arrayBuffer();
111111
case startType === BodyFormat.Uint8Array:
112-
return await clone.bytes();
112+
return new Uint8Array(await clone.arrayBuffer());
113113
}
114114

115115
return undefined;

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { type Component } from "solid-js";
22
import {
3-
deserializeJSONStream,
4-
deserializeJSStream,
53
// serializeToJSONStream,
64
serializeToJSONString,
75
} from "./serialization.ts";
8-
import { BODY_FORMAL_FILE, BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody } from "./server-functions-shared.ts";
6+
import {
7+
BODY_FORMAT_KEY,
8+
BodyFormat,
9+
extractBody,
10+
getHeadersAndBody,
11+
} from "./server-functions-shared.ts";
912

1013
let INSTANCE = 0;
1114

12-
function createRequest(
13-
base: string,
14-
id: string,
15-
instance: string,
16-
options: RequestInit,
17-
) {
15+
function createRequest(base: string, id: string, instance: string, options: RequestInit) {
1816
return fetch(base, {
1917
method: "POST",
2018
...options,
@@ -85,7 +83,7 @@ async function fetchServerFunction(
8583
if (response.body) {
8684
/* @ts-ignore-next-line */
8785
response.customBody = async () => {
88-
return await extractBody(instance, true, response.clone())
86+
return await extractBody(instance, true, response.clone());
8987
};
9088
}
9189
return response;
@@ -102,8 +100,7 @@ export function createServerReference(id: string) {
102100
let baseURL = import.meta.env.BASE_URL ?? "/";
103101
if (!baseURL.endsWith("/")) baseURL += "/";
104102

105-
const fn = (...args: any[]) =>
106-
fetchServerFunction(`${baseURL}_server`, id, {}, args);
103+
const fn = (...args: any[]) => fetchServerFunction(`${baseURL}_server`, id, {}, args);
107104

108105
return new Proxy(fn, {
109106
get(target, prop, receiver) {
@@ -117,16 +114,13 @@ export function createServerReference(id: string) {
117114
const url = `${baseURL}_server?id=${encodeURIComponent(id)}`;
118115
return (options: RequestInit) => {
119116
const fn = async (...args: any[]) => {
120-
const encodeArgs =
121-
options.method && options.method.toUpperCase() === "GET";
117+
const encodeArgs = options.method && options.method.toUpperCase() === "GET";
122118
return fetchServerFunction(
123119
encodeArgs
124120
? url +
125-
(args.length
126-
? `&args=${encodeURIComponent(
127-
await serializeToJSONString(args),
128-
)}`
129-
: "")
121+
(args.length
122+
? `&args=${encodeURIComponent(await serializeToJSONString(args))}`
123+
: "")
130124
: `${baseURL}_server`,
131125
id,
132126
options,

0 commit comments

Comments
 (0)