Cannot call invalidateAll() on the server #9683
Replies: 8 comments 2 replies
-
I temporarily "fixed" by setting export const ssr = false but I know that this is not recommended. |
Beta Was this translation helpful? Give feedback.
-
You're getting this because you indeed cannot call |
Beta Was this translation helpful? Give feedback.
-
The invalidateAll() function is within the +page.svelte file inside the <script></script> tag.
|
Beta Was this translation helpful? Give feedback.
-
You should put the setInterval invocation in the onMount lifecycle function if you want it to only run on the client side. Otherwise, you can always check the browser variable |
Beta Was this translation helpful? Give feedback.
-
I'll try out that. Thanks. |
Beta Was this translation helpful? Give feedback.
-
So, without const ssr = false, I tried the suggestion but this is the result: Code: <script>
...
function actualizarDatos() {
invalidateAll();
convertToLoaded();
}
onMount(async () => {
actualizarDatos();
setInterval(() => {
if (chequearHorarioOperatoria(moment().tz("America/New_York"))) {
// console.log('estamos en horario de operatoria');
actualizarDatos();
} else {
//console.log('no estamos en horario de operatoria');
}
}, 60000);
});
</script> I started my project from the ts skeleton boilerplate. |
Beta Was this translation helpful? Give feedback.
-
Presumably your previous error with invalidateAll was masking another error where either you or some library you import is trying to access Once again, we can't really investigate without a minimal repro. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I started with a typescript boilerplate app from "@sveltejs/kit": "^1.5.0". I added a +page.server.ts with a load function (server-side). I want it to be rerun. I added an invalidateAll() in my +page.svelte but I always get "Cannot call invalidateAll() on the server".
Reproduction
run npm create svelte@latest my-app
pick skeleton project --> typescript notation
cd my-app
npm install
create a +page.server.ts in .src/routes
add an invalidateAll() function in +page.svelte
npm run dev -- --open
Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions