Skip to content

fix(web): send a GET server function call with file arguments over POST - #5177

Open
Marve10s wants to merge 2 commits into
solidjs:mainfrom
Marve10s:fix-server-get-file-arguments
Open

Marve10s wants to merge 2 commits into
solidjs:mainfrom
Marve10s:fix-server-get-file-arguments

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Summary

A GET server function called with a file in its arguments sends the codec's multipart body as a url parameter, and the server answers 400:

enableRichArguments();
const loadPreview = GET(createServerReference("preview"));
await loadPreview(file);
// GET /_server/data/preview?args=%5Bobject%20FormData%5D
// Error: Server function call failed with status 400

The same happens for (1, file), a FormData holding a file, and an object holding a Blob. The default POST transport delivers all of them. The docs say that with the codec on "files and blobs can sit anywhere in the arguments ... Such a call sends multipart form data", and that GET "arguments too long for a url dispatch over POST instead". GET's send in packages/web/server-functions/src/client.ts put serializeArguments(args) straight into ?args=. Since #4208 that can be a FormData. Same on 2.0.3 and main.

The url-length fallback had a related problem: it encoded the arguments a second time. So a long codec argument next to a one-shot async iterator arrived with no chunks.

GET's send now sends the codec's output over POST, still as a read, when it can't go in the url (a FormData, or a codec string that is too long). It uses the same request shape as the default POST transport's codec branch, now a small withCodecBody helper both paths call, so the arguments are encoded once. JSON-safe calls and short codec strings such as a Date still go over GET with the same url and cache key. POST-shaped reads still never ask for single-flight.

Behavior change

Without enableRichArguments, a GET call whose argument has a natural HTTP encoding (a File, Blob, FormData, URLSearchParams, ArrayBuffer or typed array, alone or as the last bound argument) now goes over POST as a read, the same way the default POST transport sends it. Before, it threw "pass a single Blob/FormData/File argument". Nested values, Date, Map, undefined, (Date, File) and (File, 1) still throw the enableRichArguments message without sending a request.

Without the codec, a long leading argument before a file stays in ?args= on that POST, exactly as the default POST transport sends the same call.

Public API changes

None.

Size

+118 B minified on each server-function page bundle (measured locally on macOS). Two non-floor scenarios go past their allowance, so this PR raises their caps at measured + 10 B with ledger lines in scripts/size/scenarios.js: compiled base server components 36.06 → 36.15 KB, live + router 51.47 → 51.51 KB. The frozen base server components floor stays under its cap by 5 B brotli. If CI measures more than that, it needs a Size-Exception: line. #5175 raises some of the same caps, so whichever lands second needs its ledger lines re-measured.

How did you test this change?

  • packages/web/test/server/server-functions-uploads.spec.tsx:

    • A File, (1, File) and a FormData holding a file go over POST as reads.
    • A one-shot async iterator beside a File arrives with all its chunks.
    • A 4,000-character argument beside a File stays out of the url.
    • A nested file goes as multipart.
    • Arguments without files stay in the url.

    On main the file cases fail with Server function call failed with status 400. The iterator and long-argument cases also fail on a version that re-encodes (chunks: [], ?args=…).

  • packages/web/test/server/server-functions-body-formats.spec.tsx: without the codec, a File goes over POST (on main it throws the "pass a single Blob/FormData/File" error), and a nested Date still asks for the codec.

  • Probed 26 argument shapes with the codec on and off, plus invoke(GET(fn), { signal }) and calls inside an action. GET urls for JSON-safe and codec-string arguments are unchanged, and no GET-declared call sends X-Single-Flight.

  • Web server suite 2228 passed, web client suite 2033 passed, test-types passes.

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fdda428

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@solidjs/web Patch
@solidjs/diagnostics Patch
@solidjs/signals Patch
solid-js Patch
@solidjs/universal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed

codspeed Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

2 warnings

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@codspeed/* 5.4.0 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.

See affected benchmarks

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 201 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing Marve10s:fix-server-get-file-arguments (fdda428) with main (5420b4a)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Copy link
Copy Markdown
Member

Thanks for tracking this down. Both bugs are real: a GET call with the codec on turns a file into ?args=[object FormData] and gets a 400, and the long-argument fallback encodes the arguments twice.

Could you narrow the fix, though? Choosing GET or POST should stay the developer's call, so a GET with a file shouldn't quietly switch to POST. Could you instead:

  • throw a clear error when GET's arguments serialize to a FormData (with the codec on), the way the no-codec path already throws "pass a single Blob/FormData/File argument", and keep that throw for the no-codec case too;
  • keep the fix where the long-argument POST fallback encodes the arguments once, plus its test (the one-shot iterator beside a long codec argument).

That should cost far fewer than 118 B, and may not need the cap raises at all.


Generated by Claude Code

… to POST

Narrowed per review. A GET server function whose codec arguments encode to
multipart form data (a file among them) now throws "A GET server function
cannot send files: use POST" before sending, instead of putting
`[object FormData]` in the url. Without the codec, a GET call with a file
still throws the existing enableRichArguments error.

The long-argument POST fallback keeps the encoding it already made: GET
passes it as the options body and the codec branch of initializeResponse
sends it, so a one-shot argument such as an async iterator arrives with all
its chunks.

Size: +106 B minified on every server-function page. Caps raised at
measured + 10 B over main @ 5420b4a for compiled base, compiled live and
live + router, and for the frozen live page floor, which needs a
Size-Exception line in the PR body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants