Describe the bug
i have an api running at http://localhost:8080 when i go to routes/+page.svelte and call load function from +page.ts
export async function load({ fetch }) {
const data = await (await fetch("http://localhost:8080")).json()
return {
text: data.text
}
}
it calls this api twice but when i put a trailing slash at end of url http://localhost:8080/ it calls the api once, after i debugged the code i found out that data serialized when load is called at server has selector data-sveltekit-fetched data-url="http://localhost:8080/" but in file kit/src/runtime/client/fetcher.js at line 158:
const url = JSON.stringify(resource instanceof Request ? resource.url : resource);
the resource is not constructed with new URL() so it doesn't add a trailing slash so this selector
let selector = `script[data-sveltekit-fetched][data-url=${url}]`;
doesnt get the serialized data and calls the api twice. so is this intentional or a mistake? changing the line 158 to this worked for me
const constructed_url = new URL(resource instanceof Request ? resource.url : resource).href
const url = JSON.stringify(constructed_url);
Reproduction
Create any +page.ts file and call any api
export async function load({ fetch }) {
const data = await (await fetch("<api_url>")).json()
return {
text: data.text
}
}
add trailing slash after <api_url>/ it calls the api one and remove / it calls this api twice
Logs
System Info
System:
OS: Linux 6.16 Arch Linux
CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
Memory: 4.85 GB / 11.24 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 24.8.0 - /usr/bin/node
npm: 11.6.0 - /usr/bin/npm
pnpm: 10.17.1 - /usr/bin/pnpm
bun: 1.3.0 - /home/softrock/.bun/bin/bun
Browsers:
Brave Browser: 141.1.83.112
Firefox: 143.0.1
Firefox Developer Edition: 143.0.1
Severity
annoyance
Additional Information
No response
Describe the bug
i have an api running at
http://localhost:8080when i go toroutes/+page.svelteand call load function from+page.tsit calls this api twice but when i put a trailing slash at end of url
http://localhost:8080/it calls the api once, after i debugged the code i found out that data serialized when load is called at server has selectordata-sveltekit-fetched data-url="http://localhost:8080/"but in filekit/src/runtime/client/fetcher.jsat line 158:the resource is not constructed with new URL() so it doesn't add a trailing slash so this selector
doesnt get the serialized data and calls the api twice. so is this intentional or a mistake? changing the line 158 to this worked for me
Reproduction
Create any +page.ts file and call any api
add trailing slash after
<api_url>/it calls the api one and remove/it calls this api twiceLogs
System Info
System: OS: Linux 6.16 Arch Linux CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz Memory: 4.85 GB / 11.24 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 24.8.0 - /usr/bin/node npm: 11.6.0 - /usr/bin/npm pnpm: 10.17.1 - /usr/bin/pnpm bun: 1.3.0 - /home/softrock/.bun/bin/bun Browsers: Brave Browser: 141.1.83.112 Firefox: 143.0.1 Firefox Developer Edition: 143.0.1Severity
annoyance
Additional Information
No response