Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load functions are not always re-run on user changes to URL with hash-based router #13322

Open
stephenlrandall opened this issue Jan 16, 2025 · 1 comment

Comments

@stephenlrandall
Copy link
Contributor

Describe the bug

When using router.type === 'pathname', all load functions are re-run if a user edits what would be part of $page.url.pathname (the page appears to reload).

When using router.type === 'hash', all load functions are not guaranteed to re-run when a user edits the URL. If the search params are modified, the page reloads and all load functions run. But when any part of the path (now following the hash) is edited, selective invalidation seems to be applied. This leads to inconsistent behavior between the two router types.

I don't know if this distinction between "reload on pathname change, don't reload on hash change" is just a browser thing that SvelteKit has no control over, but it would be nice to have full invalidation on hash changes when using the hash-based router, to mirror what happens with pathname changes and the pathname router.

I can work around this with something like:

<svelte:window on:hashchange={invalidateAll}/>

but this obviously ends up running some load functions twice.

Reproduction

Open the console when running https://github.com/stephenlrandall/kit-inline-test. Visit http://localhost:5173/?q=svelte#/search, then modify the URL to http://localhost:5173/?q=svelte#/v2/search. Note that in the console, only the search route's load function has been re-run.

Logs

System Info

System:
    OS: macOS 15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 401.48 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.0 - /usr/local/bin/node
    npm: 10.1.0 - /usr/local/bin/npm
    pnpm: 9.15.4 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.265
    Edge: 131.0.2903.147
    Safari: 18.2
  npmPackages:
    @sveltejs/adapter-auto: ^3.3.1 => 3.3.1 
    @sveltejs/adapter-static: ^3.0.8 => 3.0.8 
    @sveltejs/kit: ^2.15.3 => 2.15.3 
    @sveltejs/vite-plugin-svelte: ^4.0.4 => 4.0.4 
    svelte: ^5.18.0 => 5.18.0

Severity

annoyance

Additional Information

No response

@eltigerchino
Copy link
Member

eltigerchino commented Jan 16, 2025

Should we trigger a full page reload instead of client-side navigating when the address bar URL is edited so the router behaviours are aligned? cc: @dummdidumm

} else if (app.hash) {
// If the user edits the hash via the browser URL bar, it
// (surprisingly!) mutates `current.url`, allowing us to
// detect it and trigger a navigation
if (current.url.hash === location.hash) {
navigate({ type: 'goto', url: current.url });
}
}

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

No branches or pull requests

2 participants