Post request in load function is sent at least twice when using page parameter
See original GitHub issueDescribe the bug
Hi. I need to make a post request on page load. Because I’m using the page
parameter in the load
function, the request is being sent twice. Is this by design?
Not sure if I’m just doing something wrong.
export async function load({ fetch, page }) {
// `code` in the URL is here because of an OAuth2 redirect
const code = page.query.get("code");
// This request is sent twice. The code can only be used once
const res = await fetch({
method: "POST",
url: "https://example.com",
body: JSON.stringify({ code }),
});
const aProp = await res.json();
return {
props: { aProp },
};
}
Reproduction
Don’t have a link to a repo, but my project is just a brand new SvelteKit project. Code very similar to the above is in index.svelte
.
Logs
No response
System Info
System:
OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 4.88 GB / 15.53 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.15.1 - /usr/local/bin/node
npm: 7.20.3 - /usr/local/bin/npm
Browsers:
Brave Browser: 92.1.27.111
Chrome: 92.0.4515.131
Firefox: 90.0.2
npmPackages:
@sveltejs/kit: next => 1.0.0-next.142
svelte: ^3.34.0 => 3.42.1
Severity
serious, but I can work around it
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Sending multiple data parameters with jQuery AJAX
Here is how POST data should be formatted: key1=value1&key2=value2&key3=value3. In your case (note the & as a separator):
Read more >Advanced Usage — Requests 2.28.1 documentation
The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance,...
Read more >XMLHttpRequest.send() - Web APIs | MDN
The XMLHttpRequest method send() sends the request to the server. If the request is asynchronous (which is the default), this method returns ...
Read more >.load() | jQuery API Documentation
The POST method is used if data is provided as an object; otherwise, GET is assumed. Loading Page Fragments. The .load() method, unlike...
Read more >Listeners for your Application Load Balancers
If the listener protocol is HTTPS, you must deploy at least one SSL server ... You can send up to 128 requests in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@a6h-s I’m going to close this since there’s no reproduction. We can reopen if you provide one
Okay now only the node request is there, with POST too. This definitely works. Thanks a ton!