-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
When using SvelteKit's experimental command() (remote functions) from a page that is served via a reroute hook, event.route.id inside the command is null instead of the matched route.
Page navigation correctly resolves event.route.id via the reroute hook. But when a command() is invoked from that same page, event.route.id is null.
Reproduction
Minimal repo: https://github.com/half2me/sveltekit-reroute-command-bug
git clone https://github.com/half2me/sveltekit-reroute-command-bug
cd sveltekit-reroute-command-bug
pnpm install
pnpm dev- Navigate to
http://localhost:5173/original- The page loads correctly — the
reroutehook maps/original→/actual - In the terminal:
[hooks.server] GET /original → route.id: /actual
- The page loads correctly — the
- Click "Call command()"
- The page shows
event.route.id: null— BUG
Navigate to /actual directly and click the button to verify — in that case event.route.id is correctly /actual.
Setup:
src/hooks.ts— reroute hook:/original→/actualsrc/routes/actual/+page.svelte— page with a button calling acommand()src/lib/get-route-info.remote.ts— command that returnsevent.routeandevent.url
Logs
Page load (correct):
[hooks.server] GET /original → route.id: /actual
Command call (bug):
event.route.id: null
event.url.pathname: /original
Expected behavior
event.route.id should be /actual inside the command(), same as during page navigation.
Actual behavior
event.route.id is null.
Real-world impact
This breaks any handle hook logic that uses event.route.id for command() requests. In our production app we use subdomain-based routing via reroute:
// hooks.ts — reroutes acme.example.com/ → /o/acme
export const reroute: Reroute = ({ url }) => {
const subdomain = getSubdomain(url.hostname);
if (subdomain) return `/o/${subdomain}${url.pathname}`;
};// hooks.server.ts — skips auth for static marketing pages
const handleAuth: Handle = async ({ event, resolve }) => {
if (event.route.id?.includes('(static)')) return resolve(event);
// ... set up session ...
};When a command() is called from acme.example.com/, event.route.id is null instead of /o/[slug]. In our case the un-rerouted / path happened to match a /(static) route group, causing the auth hook to break things.
System Info
SvelteKit 2.55.0
Svelte 5.53.13
Vite 8.0.0
TypeScript 5.9.3
macOS 15.5
Severity
serious, but I can work around it
Additional Information
- Page loads (GET requests) correctly apply the
reroutehook - Only
command()POST requests are affected - The
handlehook inhooks.server.tsdoes run for command requests, butevent.route.idis alreadynullby the time it executes