-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
page props are re-set whenever the session
store is updated, and the load
function is re-run the first time
#3732
Comments
Another bug ... may be. example:
It will happen when a ssr page is modified for example: const c = [
() => import('/src/routes/__layout.svelte'),
() => import('/.svelte-kit/runtime/components/error.svelte'),
() => import('/src/routes/index.svelte')
]; after you modify index.svelte: const c = [
() => import("..\\..\\src\\routes\\__layout.svelte"),
() => import("..\\runtime\\components\\error.svelte"),
() => import("..\\..\\src\\routes\\index.svelte")
]; after you reload page: const c = [
() => import('/src/routes/__layout.svelte'),
() => import('/.svelte-kit/runtime/components/error.svelte'),
() => import('/src/routes/index.svelte?t=1644064437131')
]; as you see there is a version number append to the module. When session changed page will renderer and modules will load : // preload modules
a.forEach((loader) => loader()); but modules in page render from server have different path start({
target: document.querySelector('[data-hydrate="lf6ho7"]').parentNode,
paths: {"base":"","assets":""},
session: {},
route: true,
spa: false,
trailing_slash: "never",
hydrate: {
status: 200,
error: null,
nodes: [
import("/src/routes/__layout.svelte"),
import("/src/routes/index.svelte")
],
url: new URL("http://localhost:3000/"),
params: {}
}
}); so...same page but from different modules will execute. |
@aolose I'm not sure I understand what you're saying, but I don't think it answers the question of why props are reset when session changes. All I know is that that shouldn't happen.
What do you mean?! I'm not modifying the page. |
I would appreciate a response from the maintainers, this behavior doesn't make sense to me and is creating countless problems and causing me a lot of headache... :( |
emmm... I tried to reproduce your problem then i found my reply was wrong~ |
Any ideas, anyone? |
One thing I've found so far is that the As for |
Hi @rmunn, thank you for the response. Needless to say, props being reset whenever
Good to hear, thank you :) <3 |
Agreed, this has been driving me nuts for days until I finally became sure that it was a bug with Sveltekit and not me just being stupid. To add to the strangeness, you can even change the page props and then call a setTimeout for a large amount of time to set the $session store value and after the $session store value gets set the page props will revert to their previous value. How is this even possible!? |
@DrDanRyan Yeah unfortunately this bug is still present in SvelteKit and can cause a lot of cofusion and headache, it's planned for v1.0 so I very much hope it will be fixed soon. |
If its any help, this is my minimal reproduction of the bug you can see that the props ( // index.svelte
<script>
import { session } from '$app/stores';
export let user;
async function submit() {
const response = await fetch('/', {
method: 'POST',
headers: { accept: 'application/json' }
});
const body = await response.json();
user = body.user;
setTimeout(() => {
$session.message = body.message;
}, 2000);
}
</script>
<div>{JSON.stringify($session)}</div>
<p>Hello {user}!</p>
<button on:click={submit}>Submit</button> // index.js
export async function get() {
return {
body: {
user: 'Bob'
}
};
}
export async function post() {
return {
body: {
user: 'Tom',
message: 'I come from the post call!'
}
};
} |
* [fix] Prevent rerender when route state did not change Fixes #3732 * adjust code to fix only session case, tests * format * fix test expectation Co-authored-by: Simon Holthausen <[email protected]>
Describe the bug
In the docs, in the section about the
load
function, it's stated that:But this doesn't seem to be the case. I have the following page in my SvelteKit app:
index.svelte
:If you click on the "Change $session" button, you'll see the message "index load function" appearing in the console, which obviously means the load function is re-run, even though
session
isn't used in theload
function. This is inconsistent with the behavior described in the docs.The strange thing, however, is that from the second time onwards, when the value of the '$session' store changes, the
load
function is no longer re-run. This is confusing.The more severe bug, however, which seems to be related to this one, is that every time the
$session
store changes, the page's props are apparently re-set, which means reactivity is re-triggered throughout the entire page, potentially causing massive problems.Consider the following:
In this setup, whenever you click on the "Change $session" button — which is to say whenever you update the
$session
store — thefetch
request in the markup, which uses theuserBaicInfo
prop, is re-triggered, even though it obviously shouldn't. And you can see theuserBasicInfo changed: ...
message in the console which proves that it's because of theuserBasicInfo
prop getting re-set.Reproduction
You can create an empty SvelteKit skeleton project and then copy-paste the two code snippets above into the
index.svelte
file, and thennpm run dev
=> open your browser and see the behavior for yourself.Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: