Skip to content

Simultaneously isRemoteRequest: false and route.id: null in remote function during SSR #14543

@sillvva

Description

@sillvva

Describe the bug

When you call a remote function during SSR, the event.isRemoteRequest is false, but the route.id is still null.

Probably either event.isRemoteRequest should be true if it's not part of the same request, or route.id should match the route.id from the page request.

Reproduction

You'll notice in the console that the hook shows a route.id of /(home) and the remote function shows a route.id of null. However, both show isRemoteRequest is false.

https://stackblitz.com/edit/sveltejs-kit-template-default-k6fjdwc3?file=src%2Fhooks.server.ts,src%2Froutes%2F(test)%2Ftest.remote.js

Logs

If the URL was /test, you'd see:

hook:isRemoteRequest false
hook:route.id /(test)/test
hook:url.pathname /test

remote:isRemoteRequest false <-- this doesn't make sense
remote:route.id null
remote:url.pathname /

Ideally, it should be:

remote:isRemoteRequest true
remote:route.id null
remote:url.pathname /

or:

remote:isRemoteRequest false
remote:route.id /(test)/test
remote:url.pathname /test

The problem

When running my authGuard() function inside a remote function, if the user is not authenticated, I redirect the user to the login page with a search param (?redirect=/path) indicating where the user was when they logged out so they can pick up where they left off when the login again.

To get that path, I'm checking this:

const returnUrl = event.isRemoteRequest
	? (event.request.headers.get("referer")?.replace(event.url.origin, "") ?? "/characters")
	: `${event.locals.url.pathname}${event.locals.url.search}`;

If isRemoteRequest is true, I know I can't get the path from event.url.pathname, but when it's not I should be able to. Because isRemoteRequest is false during SSR and pathname is /, I end up needing to pass the actual path from the hooks in event.locals.

System Info

System:
    OS: macOS 26.0
    CPU: (16) arm64 Apple M4 Max
    Memory: 944.73 MB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
    pnpm: 10.11.0 - ~/.nvm/versions/node/v22.12.0/bin/pnpm
    bun: 1.2.20 - ~/.bun/bin/bun
  Browsers:
    Safari: 26.0
  npmPackages:
    @sveltejs/kit: ^2.43.4 => 2.43.4
    svelte: ^5.39.6 => 5.39.6

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions