Skip to content

Conversation

Rich-Harris
Copy link
Member

We originally chose to omit event.route and event.url from remote functions, because we worried that it could create confusion — if a query's return value is based on event.url, it could become incorrect later when the URL changes and the query result doesn't.

But it's too restrictive. It's often necessary to know which page a remote function was called from. For example if a query redirects to a /login page, it's nice to be able to include a redirectTo parameter, and for that you need to know the page the user was trying to access:

if (!user) {
  redirect(307, `/login?redirectTo=${encodeURIComponent(event.url.pathname)}`);
}

This PR makes that possible. Closes #14543.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Oct 5, 2025

🦋 Changeset detected

Latest commit: 1edecc4

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

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

Co-authored-by: Patrick <Patrick@ShowYou.us>
@PatrickG
Copy link
Member

PatrickG commented Oct 5, 2025

Should we add a note in the docs that you can not "trust" event.url/event.route if event.isRemoteRequest is true?
Otherwise I can see people trying to secure their remote functions in the handle hook with it.

<script>
import { get_event } from './data.remote.js';
const event = await get_event();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line causing the lint failure:

packages/kit/test/apps/basics check: /home/runner/work/kit/kit/packages/kit/test/apps/basics/src/routes/remote/event/+page.svelte:4:16
packages/kit/test/apps/basics check: Error: 'await' expressions are only allowed within async functions and at the top levels of modules. (js)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhhhh how do we fix that? does svelte-check need to be updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I also get red squigglies in my editor, which I assume is because the VS Code extension is attempting to load config from the project root, rather than the nearest svelte.config.js to the file in question. Is this a bug @dummdidumm?)

@Rich-Harris
Copy link
Member Author

Ok, so it turns out enabling async rendering breaks a few tests, which we'll have to look into. Disabled it for now

@svelte-docs-bot
Copy link

@Rich-Harris
Copy link
Member Author

Should we add a note in the docs

Yeah, just pushed something. I do almost wonder if we should just automatically re-run queries that depend on these values when they change, because I can see people doing that regardless

@Rich-Harris Rich-Harris merged commit 313ee5e into main Oct 5, 2025
22 checks passed
@Rich-Harris Rich-Harris deleted the gh-14543 branch October 5, 2025 19:05
@github-actions github-actions bot mentioned this pull request Oct 5, 2025
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.

Simultaneously isRemoteRequest: false and route.id: null in remote function during SSR
4 participants