Skip to content

load() fetch calls API twice if URL lacks trailing slash #14781

Description

@AbdulSamiEjazQureshi

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

Activity

  1. added
    bugSomething isn't working
    and removed
    bugSomething isn't working
    on Aug 4, 2026
  2. added theissue type on Aug 4, 2026
  3. added a commit that references this issue on Aug 17, 2026
    d8efec6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions