How to avoid invalidateAll() on each form action? #9467
-
It seems that after each form action, there is an invalidateAll() happening, which causes all the load function to re-run. Can be seen here. On the First route there is a form. As long as I navigate between all forms, the load action in the layout.server file is not run. But if I post the form, the load is executed again on the layout.server. https://stackblitz.com/edit/sveltejs-kit-template-default-gf1pq5 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
We can prevent <form method="POST" use:enhance={() => {
return async ({ result }) => {
if (result.type === 'redirect') {
// redirect without invalidating
await goto(result.location);
} else {
await applyAction(result);
}
}
}}> |
Beta Was this translation helpful? Give feedback.
We can prevent
invalidateAll
when using theuse:enhance
action on the form.First, we pass a custom callback, and avoid calling
applyAction
whenresult.type
is aredirect
.https://stackblitz.com/edit/sveltejs-kit-template-default-fbiwbs?file=src%2Froutes%2Ffirst%2F%2Bpage.svelte,src%2Froutes%2Ffirst%2F%2Bpage.server.ts