You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When watching for url changes the store seems to stop being reactive after a short while.
For example in my repro, i have a link that appends #modal to the url, i then have a modal component using the page store to watch this change and show some html, initially it works as expected but after opening then closing then opening then closing again that last close stops working.
May be related to #4554 which appears to be caused by #3177; see #4554 (comment) for some debugging steps I did on that one which you could reproduce. (Basically, insert another URL change between steps 6 and 7, or between steps 7 and 8, and the behavior will probably change).
I haven't kept up with Svelte-Kit internals recently, so I'm not current on how the URL hash is being handled w/r/t navigations and whether there are plans to change that in the near future. In the meantime, it might be possible to work around this by using something other than the hash to keep track of a modal being opened or not.
My workaround has been to store the location.hash in its own store.
// /routes/+layout.svelte
<script lang="ts">
import { browser } from "$app/environment";
import { fragment } from "$lib/store";
if (browser) {
// Store the #hash into a Svelte store for easy access everywhere
fragment.set(location.hash);
window.onhashchange = () => {
fragment.set(location.hash);
};
}
</script>
Describe the bug
When watching for url changes the store seems to stop being reactive after a short while.
For example in my repro, i have a link that appends
#modal
to the url, i then have a modal component using the page store to watch this change and show some html, initially it works as expected but after opening then closing then opening then closing again that last close stops working.There are no errors
Reproduction
https://github.com/mattpilott/sveltekit-page-store-issue
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
How to repro
git clone
npm i
npm run dev
http://localhost:5173
Open Modal
Close me
Open Modal
againClose me
againmodal wont close even though url is updated
The text was updated successfully, but these errors were encountered: