-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Component variables aren't re-initiated when navigating to a different slug #1497
Comments
This seems sort of related but I don't think it's quite the same issue since it doesn't involve the load function: #1075 |
I think this bug/feature is also the cause of this issue. #1449 |
You're right, it might be the same thing. But at the very least I feel like the documentation is lacking, if several people have run into this behavior thinking it's a bug. When I read the dynamic routes docs I don't expect the component to stick around with the previous values when the user navigates to a different slug, that makes dynamic routes more cumbersome to write. Anything that is slug-specific needs to become reactive even if it is a constant in the scope of each different slug. |
@jthegedus This issue differs from #1075 because initially the OP was not using the |
I'm going to close this as a duplicate of #552 which requests some possible additional functionality. There's some explanation there as to why it currently works the way it does |
There is a problem in sveltekit with the data prop updating on page navigation to another url param at the same route. sveltejs/kit#1497
Describe the bug
When navigating between slugs via links or by triggering
goto()
, component variables aren't re-initialized, leading to bugs.Navigating directly to the pages via the browser's address bar does have the expected result.
To Reproduce
Here's a simple component that shows the issue:
currentSlug
andcurrentValue
should always match, but insteadcurrentValue
seems to be calculated only once and retains the value between navigations. If you click the buttons or links, you'll seecurrentSlug
changing but notcurrentValue
.Expected behavior
Since these are supposed to be dynamic routes I expect the component to be-reinitialized after a navigation (or at least behave as if it was, even if some optimizations are in place that avoid re-initializing most of the component).
Information about your SvelteKit Installation:
Diagnostics
System:
OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
Memory: 978.23 MB / 31.32 GB
Container: Yes
Shell: 3.1.2 - /usr/bin/fish
Binaries:
Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
npm: 7.12.0 - ~/.nvm/versions/node/v14.16.0/bin/npm
Browsers:
Chromium: 90.0.4430.212
Firefox: 88.0.1
npmPackages:
@sveltejs/kit: next => 1.0.0-next.107
svelte: ^3.38.2 => 3.38.2
vite: ^2.3.2 => 2.3.2
Firefox
adapter-static 1.0.0-next.9
Severity
This does have a workaround by declaring
currentValue
as a reactive statement:$: currentValue = currentSlug;
However I think it's very unintuitive behavior and I can't find any documentation that states this is expected or intentional behavior. It took me a while to figure out what was going on, as I was running into this in a more complicated component.
The text was updated successfully, but these errors were encountered: