fix: apply reroute hook to remote function requests#15559
Open
half2me wants to merge 1 commit intosveltejs:mainfrom
Open
fix: apply reroute hook to remote function requests#15559half2me wants to merge 1 commit intosveltejs:mainfrom
half2me wants to merge 1 commit intosveltejs:mainfrom
Conversation
|
faf9a96 to
070ea4c
Compare
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
070ea4c to
ffa9e4b
Compare
Contributor
Author
|
@themavik tf? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #15558
Remote function requests (
command(), and likelyform()) receive the page's pathname via thex-sveltekit-pathnameheader, but thereroutehook was skipped for these requests due to theif (!remote_id)guard added in #13986.This caused
event.route.idto benull(or match the wrong route) when the page was served via areroutehook.The Fix
Remove the
!remote_idguard around thereroutehook call inrespond.js.By the time
rerouteruns,url.pathnamehas already been replaced with the page pathname from thex-sveltekit-pathnameheader — so the hook correctly resolves the page's route. It never sees the/_app/remote/path.Test
Added a test in the
asynctest app:reroutehook maps/remote/rerouted/original→/remote/rerouted/actualcommand()on that page returnsevent.route.idandevent.url.pathnameevent.route.idis/remote/rerouted/actualBefore fix:
event.route.idisnullAfter fix:
event.route.idis/remote/rerouted/actualReproduction
Minimal repo: https://github.com/half2me/sveltekit-reroute-command-bug