Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form submit clears $page.state while shallow routing #405

Open
suicide opened this issue Apr 9, 2024 · 7 comments
Open

Form submit clears $page.state while shallow routing #405

suicide opened this issue Apr 9, 2024 · 7 comments

Comments

@suicide
Copy link

suicide commented Apr 9, 2024

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 suicide added the bug Something isn't working label Apr 9, 2024
@ciscoheat
Copy link
Owner

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.

@suicide
Copy link
Author

suicide commented Apr 9, 2024

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: sveltejs/kit#11956

@falkomerr
Copy link

I'm have same issue, any updates?

@ciscoheat
Copy link
Owner

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

@falkomerr
Copy link

@ciscoheat
Copy link
Owner

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

@ghostdevv
Copy link

But I guess it is more of a sveltekit problem actually: sveltejs/kit#11956

^ for sure

@ciscoheat ciscoheat removed the bug Something isn't working label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants