sveltekit-superforms icon indicating copy to clipboard operation
sveltekit-superforms copied to clipboard

Form submit clears $page.state while shallow routing

Open suicide opened this issue 10 months ago • 7 comments

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.

suicide avatar Apr 09 '24 19:04 suicide

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.

ciscoheat avatar Apr 09 '24 19:04 ciscoheat

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

suicide avatar Apr 09 '24 23:04 suicide

I'm have same issue, any updates?

falkomerr avatar Apr 12 '24 20:04 falkomerr

I need a MRE to take a closer look: https://sveltelab.dev/github.com/ciscoheat/superforms-examples/tree/zod

ciscoheat avatar Apr 12 '24 20:04 ciscoheat

https://www.sveltelab.dev/y0wab60zrf5hr6c

falkomerr avatar Apr 12 '24 20:04 falkomerr

I see that the button won't display the form, but what is the Superforms issue about this?

ciscoheat avatar Apr 12 '24 20:04 ciscoheat

But I guess it is more of a sveltekit problem actually: https://github.com/sveltejs/kit/issues/11956

^ for sure

ghostdevv avatar Apr 14 '24 18:04 ghostdevv