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
{{ message }}
Repository navigation
Remote form() result persists after navigation #14802
@dummdidumm I think the issue here is that the way remote form works is you're importing an instance of a remote form rather than a function that creates a new instance. Since the import is cached in memory even as you navigate around, the values in that instance are retained.
If it were a function that you call to create an instance, it would create a new instance each time the page is loaded and only the function would be cached in memory.
So instead of:
<scriptlang="ts">
import { todoForm } from"./form.remote.ts";
</script>
<form {...todoForm}> <!-- same instance every time -->
...
</form>
It should be:
<scriptlang="ts">
import { todoForm } from"./form.remote.ts";const form =todoForm(); // creates new instance every time
</script>
<form {...form}>
...
</form>
I tested this out with a local copy of sveltekit and it seemed to work, although I was unable to get the types and .remote.ts export limitation working correctly.
I have a remote form wrapper component that lets me easily pass custom on success, error, etc...hooks to a custom enhance function and was going crazy thinking I was doing something wrong lol. Same bug noticed here running kit v2.43.2
This is also a temporary workaround that I'm using. Using a unique form id with .for() creates a new instance on each page load. .for() has a built-in feature to delete the current instance when unmounted.
Ultimately, though, I think making it a function would be a better DX.
If the goal is to keep the existing API without instanciating a new form on each page, maybe onNavigate could be used to reset the form (but I don't know if it runs if we stay on the same page but add for instance a query parameter to the url, which would be unwanted)
With a function, you could still cache a form instance to get the current behavior by exporting the instance from a module instead of calling it directly from the page/component.
Hi,
I faced the same situation this week. Thanks @sillvva for your workaround using .for()
A bit disappointed and then frustrated to have such behavior (issues persisting even after navigating to another route and trying back).
So solution was to use :
I don't know if it affect the memory/cache but for now, each time the user will add an entry via this remote function a new form will be used. If user refresh the page then all is reset correctly
Activity
sillvva commentedon Oct 25, 2025
@dummdidumm I think the issue here is that the way remote form works is you're importing an instance of a remote form rather than a function that creates a new instance. Since the import is cached in memory even as you navigate around, the values in that instance are retained.
If it were a function that you call to create an instance, it would create a new instance each time the page is loaded and only the function would be cached in memory.
So instead of:
It should be:
I tested this out with a local copy of sveltekit and it seemed to work, although I was unable to get the types and
.remote.tsexport limitation working correctly.iatrophobic commentedon Oct 25, 2025
I have a remote form wrapper component that lets me easily pass custom on success, error, etc...hooks to a custom enhance function and was going crazy thinking I was doing something wrong lol. Same bug noticed here running kit v2.43.2
sillvva commentedon Oct 25, 2025
This is also a temporary workaround that I'm using. Using a unique form id with
.for()creates a new instance on each page load..for()has a built-in feature to delete the current instance when unmounted.Ultimately, though, I think making it a function would be a better DX.
mquandalle commentedon Oct 25, 2025
If the goal is to keep the existing API without instanciating a new form on each page, maybe
onNavigatecould be used to reset the form (but I don't know if it runs if we stay on the same page but add for instance a query parameter to the url, which would be unwanted)sillvva commentedon Oct 25, 2025
With a function, you could still cache a form instance to get the current behavior by exporting the instance from a module instead of calling it directly from the page/component.
There's also PR #14779 awaiting approval to add the ability to programmatically reset the state(s) of a form instance.
fix: workaround sveltejs/kit#14802
hyunbinseo commentedon Dec 26, 2025
@sillvva Thank you for the workaround!
So SvelteKit remote form allows multiple instances of a form:
{#each await getTodos() as todo} {@const modify = modifyTodo.for(todo.id)} <form {...modify}>However, this doesn't have to happen inside an each loop.
Before
After
$props.id()seems to work.Note
I would love to create a new instance by default.
Login page persisting after (login → log out with login page redirect) was not intuitive.
fix: workaround sveltejs/kit#14802
akqira commentedon Feb 15, 2026
Hi,
I faced the same situation this week. Thanks @sillvva for your workaround using
.for()A bit disappointed and then frustrated to have such behavior (issues persisting even after navigating to another route and trying back).
So solution was to use :
I don't know if it affect the memory/cache but for now, each time the user will add an entry via this remote function a new form will be used. If user refresh the page then all is reset correctly
Waiting for your PR @sillvva 🥇
fix: workaround sveltejs/kit#14802