sveltekit-superforms
sveltekit-superforms copied to clipboard
Form submit clears $page.state while shallow routing
Description
I have been experimenting with shallow routing and found that if you submit a superform (SPA mode) the $page.state
variable is cleared which consequently kind of 'breaks' shallow routing
My concrete use case is a form on an /edit
page that I load as a modal via shadow routing (similar to the example from the sveltekit docs). After submitting the form the browser url remains on /edit
but as the state is cleared, the modal is closed.
I could not find any information on the lifecycle of the state property and I could not find any code in superforms that would explicitly clear the values.
I also tried applyAction=false
in hopes that superforms would not touch the $page store, but the value is still reset.
So my question is, is this intended behavior? I haven't seen any example using shallow routing, thus I am not sure if my config is somehow broken or it is actually a bug.
If you can make a MRE here or in a repo, I'll take a closer look. Haven't tested it much with shallow routing.
thanks for the quick reply!
turns out, that if I build a simple example. everything works fine.
Through some more testing I figured out that the load functions in +page.ts and/or +layout.ts are the trouble makers. As soon as I have a load function in the mix that returns data, the state is reset after the submit
here is the repo: https://github.com/suicide/superforms-examples
if you comment the load function out, everything works fine
But I guess it is more of a sveltekit problem actually: https://github.com/sveltejs/kit/issues/11956
I'm have same issue, any updates?
I need a MRE to take a closer look: https://sveltelab.dev/github.com/ciscoheat/superforms-examples/tree/zod
https://www.sveltelab.dev/y0wab60zrf5hr6c
I see that the button won't display the form, but what is the Superforms issue about this?
But I guess it is more of a sveltekit problem actually: https://github.com/sveltejs/kit/issues/11956
^ for sure