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

Double-hitting the get endpoint with the progressive enhancement action (sveltekit-for-beginners) #22

Closed
cenuij opened this issue Mar 31, 2022 · 1 comment

Comments

@cenuij
Copy link

cenuij commented Mar 31, 2022

The fetch in the svelte action follows the returned redirect automatically (to the get endpoint), after which the page is invalidated and svelte will call the get endpoint again to get the updated data. You can see this in dev tools, with the two GETs hitting the same endpoint.

POST http://localhost:3000/
GET http://localhost:3000/
GET http://localhost:3000/__data.json

I can get around that by adding a redirect: "manual" option to the fetch request in the svelte action, since we don't use the data from the redirect anyway. However, by not following the redirect, you don't get the proper status code of the post request (since it ultimately depends on the page you are redirected to)? Not sure what other implications ignoring the redirect might have ...

@mattcroat
Copy link
Owner

Hey! 👋

I'm not sure I understand. When JavaScript is on the page it's going to use the action instead so you aren't going to have double fetching of the data. You can read more about page endpoints here sveltejs/kit#3532.

For client-side redirects you can use goto. Here's an example I use in a project. It's not perfect but I plan on doing a series on working with forms and finding answers to some of the questions I got from the series.

Not sure what other implications ignoring the redirect might have

I'm not sure if it's a good idea to change that behavior but thanks for sharing it because I wasn't aware of it. 😄

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

2 participants