Skip to content

fix: apply reroute hook to remote function requests#15559

Open
half2me wants to merge 1 commit intosveltejs:mainfrom
half2me:fix-reroute-remote-functions
Open

fix: apply reroute hook to remote function requests#15559
half2me wants to merge 1 commit intosveltejs:mainfrom
half2me:fix-reroute-remote-functions

Conversation

@half2me
Copy link
Contributor

@half2me half2me commented Mar 17, 2026

Summary

Fixes #15558

Remote function requests (command(), and likely form()) receive the page's pathname via the x-sveltekit-pathname header, but the reroute hook was skipped for these requests due to the if (!remote_id) guard added in #13986.

This caused event.route.id to be null (or match the wrong route) when the page was served via a reroute hook.

The Fix

Remove the !remote_id guard around the reroute hook call in respond.js.

By the time reroute runs, url.pathname has already been replaced with the page pathname from the x-sveltekit-pathname header — so the hook correctly resolves the page's route. It never sees the /_app/remote/ path.

Test

Added a test in the async test app:

  • A reroute hook maps /remote/rerouted/original/remote/rerouted/actual
  • A command() on that page returns event.route.id and event.url.pathname
  • The test navigates to the rerouted URL, clicks a button that triggers the command, and verifies event.route.id is /remote/rerouted/actual

Before fix: event.route.id is null
After fix: event.route.id is /remote/rerouted/actual

Reproduction

Minimal repo: https://github.com/half2me/sveltekit-reroute-command-bug

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: ffa9e4b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@half2me half2me force-pushed the fix-reroute-remote-functions branch 2 times, most recently from faf9a96 to 070ea4c Compare March 17, 2026 19:58
Remote function requests (command/query) receive the page's pathname
via the x-sveltekit-pathname header, but the reroute hook was skipped
for these requests. This caused event.route.id to be null (or match
the wrong route) when the page was served via a reroute hook.

The fix removes the !remote_id guard around the reroute hook call.
By the time reroute runs, url.pathname has already been replaced with
the page pathname from the header, so the reroute correctly resolves
the page's route — it never sees the /_app/remote/ path.

Fixes sveltejs#15558
@half2me half2me force-pushed the fix-reroute-remote-functions branch from 070ea4c to ffa9e4b Compare March 17, 2026 20:17
themavik

This comment was marked as spam.

@half2me
Copy link
Contributor Author

half2me commented Mar 19, 2026

@themavik tf?

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.

command() ignores reroute hook — event.route.id reflects un-rerouted path

2 participants