Remote function form() returns 405 on pages without +page.server.ts
Describe the bug
When using a remote function form() on a page that has no +page.server.ts, the progressive enhancement fallback path (native form submission to ?/remote=<hash>/<name>) returns 405 Method Not Allowed instead of being handled by the remote function.
The JS-enhanced path (/_app/remote/...) works correctly. Only the ?/remote= fallback is broken.
Root cause
In src/runtime/server/page/index.js, is_action_json_request(event) (line 54) is checked before the remote function handler (line 67):
// Line 54 — checked FIRST, short-circuits with 405
if (is_action_json_request(event)) {
const node = await manifest._.nodes[page.leaf]();
return handle_action_json_request(event, event_state, options, node?.server);
}
// Line 67 — never reached for JSON action requests
if (is_action_request(event)) {
const remote_id = get_remote_action(event.url);
if (remote_id) {
action_result = await handle_remote_form_post(event, event_state, manifest, remote_id);
}
}
is_action_json_request returns true for any POST where Accept negotiates to application/json (including the default */*). Since the page has no +page.server.ts, handle_action_json_request finds no server?.actions and returns 405 with allow: GET.
The remote function form handler in handle_remote_form_post (which correctly handles this case) is never reached.
Reproduction
- Create a page with only
+page.svelte(no+page.server.ts) - Use a remote function
form()on that page - Submit the form via native POST to
?/remote=<hash>/<name>(e.g., withcurl):
curl -X POST "http://localhost:5173/login?/remote=<hash>/loginUser" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "[email protected]&password=test"
Expected: Remote function handles the form submission
Actual: 405 Method Not Allowed — POST method not allowed. No form actions exist for the page
Sending Accept: text/html bypasses is_action_json_request and correctly reaches the remote function handler:
curl -X POST "http://localhost:5173/login?/remote=<hash>/loginUser" \
-H "Accept: text/html" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "[email protected]&password=test"
# → 200 OK
Suggested fix
In page/index.js, check for remote function actions before falling through to handle_action_json_request:
if (is_action_json_request(event)) {
const remote_id = get_remote_action(event.url);
if (remote_id) {
action_result = await handle_remote_form_post(event, event_state, manifest, remote_id);
} else {
const node = await manifest._.nodes[page.leaf]();
return handle_action_json_request(event, event_state, options, node?.server);
}
}
Severity
The JS-enhanced client path (/_app/remote/...) works, so this only affects the ?/remote= fallback. This means it impacts:
- Progressive enhancement (no-JS browsers)
- Form submissions before JS hydration completes
- Form submissions during HMR-triggered page reloads in dev
System Info
@sveltejs/kit: 2.50.1 (also verified on 2.54.0)
svelte: 5.49.1
vite: 7.2.2
Node: v22