kit
kit copied to clipboard
Navigation protocol checks are breaking Tauri apps
Describe the bug
Tauri is an Electron alternative for bundling web content into a desktop application. When built, the release apps use tauri:
as the internal URL protocol. Because of a recent SvelteKit PR, navigation causes a complete page refresh instead of the expected routing.
Reproduction
Create a SvelteKit + Tauri app with any SvelteKit version after or including 1.0.0-next.398. Navigation causes a complete page refresh. (Manual navigation using goto
still works correctly.)
Logs
No response
System Info
System:
OS: macOS 12.5.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 134.39 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.4.0 - ~/Library/pnpm/node
npm: 8.12.1 - ~/Library/pnpm/npm
Browsers:
Safari: 15.6.1
npmPackages:
@sveltejs/adapter-static: 1.0.0-next.38 => 1.0.0-next.38
@sveltejs/kit: 1.0.0-next.398 => 1.0.0-next.398
svelte: ^3.49.0 => 3.49.0
vite: ^3.0.0 => 3.0.0
Severity
serious, but I can work around it
Additional Information
This issue persists in the most recent version of SvelteKit.
Do you have another idea of how to avoid #5725 without adding in a hard coded reference to tauri:
?
Could we just check if url.protocol === location.protocol
? Not sure why we're not already doing that to be honest
Or url.origin === location.origin
for that matter
Oh actually, looking at the code, we don't return
at this point if origin
differs because we want to run beforeNavigate
functions for cross-document navigations (e.g. to pop up the 'you have unsaved changes' dialog). So it isn't quite that simple
Do you have another idea of how to avoid #5725 without adding in a hard coded reference to
tauri:
?
I don't entirely know the intent behind the check so it's hard to say. If it's to intercept certain actions, then perhaps checking for those specifically instead of a blanket check to only allow http(s)
?
Something more flexible would be to allow users to set their own "allowed" protocols (or disallowed, if the default is flipped), although I would understand not wanting to add configuration file bloat.
Related (really, the same) issue: https://github.com/sveltejs/kit/issues/6166
Related (really, the same) issue: #6166
Hi, do you mind telling me how you circumvent this issue? Trying to see if there's a better solution than mine. For me, I'm facing the same problem with electron (that annoyingly works in dev but not build). What I ended up doing was to use goto
from $app/navigation
instead of a href on my anchor tag and it seems to be working fine.
Hmm... I'm still facing the same issue even after the upgrade. I'm not sure if it might be an electron configuration issue on my end.
Are you sure it's the same underlying issue? Could you add a console.log(url.protocol, location.protocol)
before return
for the if that contains !(url.protocol === 'https:' || url.protocol === 'http:'
inside node_modules/@sveltejs/kit/src/runtime/client/client.js
?
My bad. I didn't realise that my version of sveltekit is wrong. It is working now. Thanks for the fix!