Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/get-file-arguments-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/web": patch
---

A `GET` server function called with a file among its arguments (with `enableRichArguments`) now throws a clear error before sending, instead of putting `[object FormData]` in the url and failing with a 400. A `GET` call whose codec-encoded arguments are too long for a url and go over POST now sends the encoding it already made instead of encoding the arguments a second time, so a one-shot argument such as an async iterator arrives with all its chunks.
16 changes: 13 additions & 3 deletions packages/web/server-functions/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,14 @@ async function initializeResponse(base, id, options, args, meta) {
// The encoder answers `FormData` when the arguments hold files (see
// uploads.js). No content type is set here: fetch gives a string body
// `text/plain` and a form its multipart boundary, which is how the handler
// tells the two apart.
// tells the two apart. A GET call too long for its url brings the encoding
// it already made, so a one-shot argument is read once.
return createRequest(
base,
id,
{
...options,
body: await serializeArguments(args),
body: options.body ?? (await serializeArguments(args)),
headers: {
...options.headers,
[BODY_FORMAT_HEADER]: BodyFormat.Serialized
Expand Down Expand Up @@ -1209,6 +1210,9 @@ export function GET(fn) {
// The handler accepts both encodings: plain JSON and the codec's framed
// string (distinguished by the `;0x` frame prefix).
const encoded = isJSONSafe(args) ? JSON.stringify(args) : await serializeArguments(args);
if (typeof encoded !== "string") {
throw new Error("A GET server function cannot send files: use POST");
}
const url = `${address}?args=${encodeURIComponent(encoded)}`;
const absolute = new URL(url, globalThis.location?.href || "http://localhost").href;
// Arguments too long for a url call over POST instead: a cache miss, not
Expand All @@ -1219,7 +1223,13 @@ export function GET(fn) {
// says so, and a POST-shaped read must not ask the server for
// single-flight collection, which is mutation policy.
if (absolute.length > MAX_GET_URL_LENGTH) {
return fetchServerFunction(address, id, { ...opts, read: true }, args, metadata);
return fetchServerFunction(
address,
id,
{ ...opts, read: true, body: encoded },
args,
metadata
);
}
return fetchServerFunction(url, id, { ...opts, method: "GET" }, [], metadata, args);
};
Expand Down
23 changes: 21 additions & 2 deletions packages/web/test/server/server-functions-body-formats.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import { AsyncLocalStorage } from "node:async_hooks";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
GET as serverGET,
createServerReference as createServerSideReference,
handleServerFunctionRequest,
registerServerFunction
registerServerFunction,
registerServerReference
} from "@solidjs/web/server-functions/server";
import { createServerReference } from "@solidjs/web/server-functions/client";
import { GET, createServerReference } from "@solidjs/web/server-functions/client";

const RequestContext = Symbol.for("solid.RequestContext");
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
Expand Down Expand Up @@ -173,6 +176,22 @@ describe("an argument with a natural HTTP encoding", () => {
});
});

describe("a GET call with a File argument", () => {
it("asks for the codec without sending a request", async () => {
serverGET(
createServerSideReference(registerServerReference("rich-get-file", async () => "ran"))
);
const transport = connectTransport();
try {
const read = GET(createServerReference("rich-get-file"));
await expect(read(new File(["hello"], "a.txt"))).rejects.toThrow(/enableRichArguments/);
} finally {
transport.restore();
}
expect(transport.requests).toEqual([]);
});
});

describe("a bound call ending in a natural encoding", () => {
it("puts the leading arguments in the url and the body last, in declared order", async () => {
let ran = 0;
Expand Down
54 changes: 52 additions & 2 deletions packages/web/test/server/server-functions-uploads.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import { AsyncLocalStorage } from "node:async_hooks";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
GET as serverGET,
createServerReference as createServerSideReference,
handleServerFunctionRequest,
registerServerFunction
registerServerFunction,
registerServerReference
} from "@solidjs/web/server-functions/server";
import { createServerReference } from "@solidjs/web/server-functions/client";
import { GET, createServerReference } from "@solidjs/web/server-functions/client";
// @ts-ignore — the rich-args dist has no adjacent type declarations.
import { enableRichArguments } from "../../server-functions/dist/rich-args.js";

Expand Down Expand Up @@ -286,6 +289,53 @@ describe("files in codec arguments", () => {
});
});

describe("a GET call with the codec", () => {
const declareRead = <A extends unknown[]>(id: string, fn: (...args: A) => unknown) => {
serverGET(createServerSideReference(registerServerReference(id, fn)));
return GET(createServerReference(id));
};

it("refuses arguments holding a file without sending a request", async () => {
const read = declareRead("get-upload-files", async (..._args: unknown[]) => "ran");
const file = () => new File(["hello"], "a.txt", { type: "text/plain" });
const form = new FormData();
form.set("doc", file());
const transport = connectTransport();
try {
for (const args of [[file()], [1, file()], [form], [{ doc: new Blob(["hi"]) }]]) {
await expect(read(...args)).rejects.toThrow("A GET server function cannot send files");
}
} finally {
transport.restore();
}
expect(transport.requests).toEqual([]);
});

it("reads a one-shot argument once when long arguments go over POST", async () => {
const read = declareRead(
"get-upload-once",
async (input: { padding: string; source: AsyncIterable<string> }) => {
const seen: string[] = [];
for await (const chunk of input.source) seen.push(chunk);
return seen;
}
);
async function* chunks() {
yield "one";
yield "two";
}
const transport = connectTransport();
try {
expect(await read({ padding: "x".repeat(3000), source: chunks() })).toEqual(["one", "two"]);
} finally {
transport.restore();
}
const [request] = transport.requests;
expect(request.method).toBe("POST");
expect(new URL(request.url).search).toBe("");
});
});

describe("malformed uploads", () => {
// A real upload body, captured, so each case changes one thing about it.
async function capture() {
Expand Down
4 changes: 2 additions & 2 deletions scripts/size/floor-caps.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"minified": 102359
},
"page: live server components (base + live/GET + action + isPending/latest)": {
"cap": "41.66 KB",
"minified": 125175
"cap": "41.69 KB",
"minified": 125286
},
"server: floor (getRequestEvent + isServer)": {
"cap": "1.33 KB",
Expand Down
16 changes: 10 additions & 6 deletions scripts/size/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5884,6 +5884,7 @@ module.exports = [
// 2026-11-18 (#5011, #5017 from #5013: a delegated container's capture listener clears the event-owner mark so a re-dispatched Event runs its handlers again; +89 B minified on every bundle with delegation; CI Size run 44281451857, over main @ e57fc3f): frozen floor 41.56 KB unchanged, recorded minified 124,875 -> 124,960 B, measured at 41,531 B brotli. Frozen floor in floor-caps.json, Size-Exception in the PR body. Growth accepted by the maintainer (2026-11-18: "We shouldn't block a good pr on size").
// 2026-11-19 (#5085, carries #5075 for #5073: a mount pending only on its own lane's reveal no longer blocks that lane (S-30); CI size head job 135764846606, over main @ bab8a53): floor 41.56 KB -> 41.63 KB, recorded minified 124,960 -> 125,063 B, measured at 41,620 B brotli (Size-Exception). Growth accepted by the maintainer (2026-11-19: "we can raise caps").
// 2026-11-21 (#5153: a hydrated stream claims its first buffered value before later yields or a throw; normalizeIterator guards its later pulls and a settled promise of a stream goes through it; +153 B minified on hydrating bundles; CI size run 44910497132 on 6cdfec9, over main @ 8399755a): floor 41.63 KB -> 41.66 KB, recorded minified 125,063 -> 125,175 B, measured at 41,648 B brotli (Size-Exception). Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
// 2026-11-25 (#5177: a GET server function throws a clear error when its codec arguments encode to multipart (a file among them), and its long-argument POST fallback sends the encoding it already made instead of encoding the arguments again; +106 B minified on every server-function page; measured locally with the native compiler over main @ 5420b4a7c, matching CI's size check to the byte at 30e7805eb): frozen floor 41.66 KB -> 41.69 KB, recorded minified 125,175 -> 125,286 B, measured at 41,671 B brotli (needs Size-Exception). Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: floorCaps["page: live server components (base + live/GET + action + isPending/latest)"],
capMinified:
floorMinified["page: live server components (base + live/GET + action + isPending/latest)"],
Expand Down Expand Up @@ -6065,8 +6066,9 @@ module.exports = [
// Batch re-record (2026-11-03, over next @ 6e569c7, size job 125766182293: #4639, #4641): cap unchanged at 35.93 KB, recorded minified 108,286 -> 108,360 B (+74 B), measured at 35,909 B brotli. #4639 and #4641 were accepted by the maintainer. Re-recorded once after the batch, per the batch process.
// Batch re-record (2026-11-03, over next @ ccfc7ea, size job 125848841075: #4653, #4655, #4657, #4659): 35.93 KB -> 36.00 KB, recorded minified 108,360 -> 108,546 B (+186 B), measured at 35,989 B brotli. The growth of #4653, #4655 and #4659 was accepted by the maintainer; #4657 and #4654 are size-neutral on the gated rows. Re-recorded once after the batch, per the batch process.
// 2026-11-09 (store guess carrier, over next @ eef34fd9d): store.ts gained the optimistic hook call sites for the guess carrier (read, presence, descriptor, enumeration, the landing's silence and judgement — each a null check on a plain store; S-59/#4724), net of the LaneView/asBacking/follow code it lost: measured 36,049 B / 108,556 B minified (+49 B brotli, +10 B minified over the record). 0 B on the core floor and the compiled floor.
limit: "36.06 KB",
capMinified: 108556,
// 2026-11-25 (#5177: a GET server function throws a clear error when its codec arguments encode to multipart (a file among them), and its long-argument POST fallback sends the encoding it already made instead of encoding the arguments again; +106 B minified on every server-function page; measured locally with the native compiler over main @ 5420b4a7c, matching CI's size check to the byte at 30e7805eb): 36.06 KB -> 36.20 KB, recorded minified 108,556 -> 108,668 B, measured at 36,188 B brotli. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: "36.20 KB",
capMinified: 108668,
alias: pageAlias
},
{
Expand Down Expand Up @@ -6271,11 +6273,12 @@ module.exports = [
// 2026-11-19 (#5055: markRaw accepts a class, +7 B minified, +42 B brotli from layout drift (the compiled base page moved -42 B); CI size head job 135428351139 on 8d9bf2b, over main @ 7f86b2d): cap 45.76 KB -> 45.79 KB, recorded minified 133,239 -> 133,275 B, measured at 45,776 B brotli. Raise accepted by the maintainer (2026-11-19). Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
// 2026-11-19 (#5085, carries #5075 for #5073: a mount pending only on its own lane's reveal no longer blocks that lane (S-30); lanes.ts heldMountUnder, lane bundles only; CI size head job 135764846606, over main @ bab8a53): 45.79 KB -> 45.80 KB, recorded minified 133,275 -> 133,347 B, measured at 45,785 B brotli. Growth accepted by the maintainer (2026-11-19: "we can raise caps"). Cap at measured + 10 B rounded up to 0.01 KB, never lowered; recorded minified = measured.
// 2026-11-21 (#5153: a hydrated stream claims its first buffered value before later yields or a throw; normalizeIterator guards its later pulls and a settled promise of a stream goes through it; +153 B minified on hydrating bundles; CI size run 44910497132 on 6cdfec9, over main @ 8399755a): 45.80 KB -> 45.83 KB, recorded minified 133,347 -> 133,509 B, measured at 45,811 B brotli. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: "45.83 KB",
// 2026-11-25 (#5177: a GET server function throws a clear error when its codec arguments encode to multipart (a file among them), and its long-argument POST fallback sends the encoding it already made instead of encoding the arguments again; +106 B minified on every server-function page; measured locally with the native compiler over main @ 5420b4a7c, matching CI's size check to the byte at 30e7805eb): 45.83 KB -> 45.89 KB, recorded minified 133,509 -> 133,626 B, measured at 45,875 B brotli. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: "45.89 KB",
// An Errored heals when the last reader that caught its error is disposed (#4373, #4384, 2026-10-28, re-recorded over next @ cbc0eebd): recorded minified 123,191 -> 123,249 B (+58 B minified over next's record), measured locally (linux) at 41,899 B brotli. Recorded minified = measured; CI re-bases.
// Boundary readers keyed by the source they wait on (#4373), with enterLane's tail folded into one else-chain as an offset (-29 B on lane pages) (#4384, 2026-10-28, re-recorded over next @ 1b32ff2e): recorded minified 123,203 -> 123,224 B (+21 B minified over next's record), measured locally (linux) at 41,966 B brotli. Recorded minified = measured; CI re-bases.
// latest() read inline and through a memo show the same screen (#4284 through a memo; a plain write beside an async memo), 2026-10-29, over next @ 7ebd4a32: recorded minified 123,224 -> 123,733 B (+403 B minified over next), measured locally (linux) at 42,119 B brotli (+169 B over next). A render effect a verdict memo's change re-runs reads as its verdict reader for that pass (`laneDirty`), a pass that read a staging before the frame had a transaction re-derives once as a verdict reader only if the frame parks, `latest()` of a first load in flight in a verdict lane is loading (also through an identity memo, a derived store and `isPending`), a lane's dissolution leaves such a load and the nodes pending on it uninitialized instead of committing `undefined`, a verdict lane born at a seam is judged at it, a pass born in a staged reader stays the frame's on a verdict-memo read (C4, #4010), a plain write beside `latest()` computes once (the seam re-derives a pre-transaction staged reader only if the frame parks), a verdict reader's plain read of a staging in a transaction only a `latest()` opened is the frame's read, so a memo of `latest()` computes once too (D-22; not a pass with no value yet, D-6), and an error stays the display while the memo it came through re-asks, a Loading fallback behind it included (D-39, async-gen 91501 #1831). recompute's CONFIG_VERDICT clear now sits behind the lane engine: -21 B minified on every floor. Correctness; the maintainer: "only flag me if brotli goes more than 20kb" (2026-10-29). Cap unchanged; recorded minified = measured.
capMinified: 133509,
capMinified: 133626,
alias: pageAlias
},
{
Expand Down Expand Up @@ -6753,12 +6756,13 @@ module.exports = [
// 2026-11-18 (#5011, #5017 from #5013: a delegated container's capture listener clears the event-owner mark so a re-dispatched Event runs its handlers again; +89 B minified on every bundle with delegation; CI Size run 44281451857, over main @ e57fc3f): cap 51.41 KB unchanged, recorded minified 150,822 -> 150,907 B, measured at 51,382 B brotli. Growth accepted by the maintainer (2026-11-18: "We shouldn't block a good pr on size").
// 2026-11-19 (#5085, carries #5075 for #5073: a mount pending only on its own lane's reveal no longer blocks that lane (S-30); lanes.ts heldMountUnder, lane bundles only; CI size head job 135764846606, over main @ bab8a53): cap 51.41 KB unchanged, recorded minified 150,927 -> 150,999 B, measured at 51,373 B brotli. Growth accepted by the maintainer (2026-11-19: "we can raise caps"). Cap at measured + 10 B rounded up to 0.01 KB, never lowered; recorded minified = measured.
// 2026-11-21 (#5153: a hydrated stream claims its first buffered value before later yields or a throw; normalizeIterator guards its later pulls and a settled promise of a stream goes through it; +153 B minified on hydrating bundles; CI size run 44910497132 on 6cdfec9, over main @ 8399755a): 51.41 KB -> 51.47 KB, recorded minified 150,999 -> 151,124 B, measured at 51,458 B brotli. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: "51.47 KB",
// 2026-11-25 (#5177: a GET server function throws a clear error when its codec arguments encode to multipart (a file among them), and its long-argument POST fallback sends the encoding it already made instead of encoding the arguments again; +106 B minified on every server-function page; measured locally with the native compiler over main @ 5420b4a7c, matching CI's size check to the byte at 30e7805eb): 51.47 KB -> 51.57 KB, recorded minified 151,124 -> 151,241 B, measured at 51,557 B brotli. Correctness. Cap at measured + 10 B rounded up to 0.01 KB; recorded minified = measured.
limit: "51.57 KB",
// An Errored heals when the last reader that caught its error is disposed (#4373, #4384, 2026-10-28, re-recorded over next @ cbc0eebd): recorded minified 140,451 -> 140,509 B (+58 B minified over next's record), measured locally (linux) at 47,516 B brotli. Recorded minified = measured; CI re-bases.
// Boundary readers keyed by the source they wait on (#4373), with enterLane's tail folded into one else-chain as an offset (-29 B on lane pages) (#4384, 2026-10-28, re-recorded over next @ 1b32ff2e): recorded minified 140,463 -> 140,485 B (+22 B minified over next's record), measured locally (linux) at 47,547 B brotli. Recorded minified = measured; CI re-bases.
// latest() read inline and through a memo show the same screen (#4284 through a memo; a plain write beside an async memo), 2026-10-29, over next @ 7ebd4a32: recorded minified 140,485 -> 140,983 B (+405 B minified over next), measured locally (linux) at 47,722 B brotli (+162 B over next). A render effect a verdict memo's change re-runs reads as its verdict reader for that pass (`laneDirty`), a pass that read a staging before the frame had a transaction re-derives once as a verdict reader only if the frame parks, `latest()` of a first load in flight in a verdict lane is loading (also through an identity memo, a derived store and `isPending`), a lane's dissolution leaves such a load and the nodes pending on it uninitialized instead of committing `undefined`, a verdict lane born at a seam is judged at it, a pass born in a staged reader stays the frame's on a verdict-memo read (C4, #4010), a plain write beside `latest()` computes once (the seam re-derives a pre-transaction staged reader only if the frame parks), a verdict reader's plain read of a staging in a transaction only a `latest()` opened is the frame's read, so a memo of `latest()` computes once too (D-22; not a pass with no value yet, D-6), and an error stays the display while the memo it came through re-asks, a Loading fallback behind it included (D-39, async-gen 91501 #1831). recompute's CONFIG_VERDICT clear now sits behind the lane engine: -21 B minified on every floor. Correctness; the maintainer: "only flag me if brotli goes more than 20kb" (2026-10-29). Cap unchanged; recorded minified = measured.
// 2026-11-19 (#5055: markRaw accepts a class; CI size head job 135428351139 on 8d9bf2b, over main @ 7f86b2d): recorded minified 150,907 -> 150,927 B, measured 51,339 B brotli; cap unchanged. Recorded minified = measured.
capMinified: 151124,
capMinified: 151241,
alias: pageAlias,
conditions: solidConditions,
compile: { hydratable: true }
Expand Down
Loading