Page reloads if an endpoint exist on the same URL even without GET method #2012
Labels
feature / enhancement
New feature or request
p2-nice-to-have
SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Describe the bug
Might be related to #1711.
See Reproduction for a TLDR of the bug itself.
I am currently working on creating a form that can be both sent via ajax or via a classic form submission when JavaScript is not active. This is just like the usecase mentioned in #1711.
So my POST endpoint fallthrough a svelte page and pass information using
getSession
, waiting for a more idomatic solution in #1711. It works, however, there is currently a bug when I try to navigate to my form page.Since there is an endpoint and a page matching the same URL, the
Renderer
, when itupdates
will consider that the first route matching the URL is an endpoint and thus will reload. However, my endpoint only have a POST method and no GET method. So it should never conflict with the client side navigation.My suggestion would be a change during the generation of the
manifest.js
. If we include the type of methods handled by each route we would be able to filter out the endpoints that don't have any GET method. This new information could then be used in Router.parse. Not sure how you'd like to do such a change. Parsing the AST of the endpoint file to see what are the named exports? If so I could try to tackle a PR around this change if it can help. Would be kind of an impactful change so not sure if that's something you'd like.kit/packages/kit/src/runtime/client/router.js
Lines 167 to 171 in b14a365
Reproduction
Here is a repository demonstrating the issue: https://github.com/JulienPradet/sveltekit-page-reload-bug
npm run dev
Current behavior:
Expected behavior:
The form available in the repository is not relevant to the issue itself but I added it to explain why I need to have the
/login
endpoint that have the same URL as my page.Logs
Not relevant
System Info
Severity
serious, but I can work around it
Additional Information
About the severity, I can disable my no-javascript form and only use ajax, but I couldn't find a workaround to make it work with the no-javascript form. So kinda blocking even though it's still a rare usecase in the javascript community (sadly). But since #1711 exists, I guess it's still something you'd like to consider in Svelte Kit.
The text was updated successfully, but these errors were encountered: