sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.78k stars 1.96k forks source link

Specific keyword as route name causes it to become slower than others #12061

Open dihmeetree opened 8 months ago

dihmeetree commented 8 months ago

Describe the bug

If you name a route /home it will cause the page to load much slower (~300ms for me), however if you create a route named /test for example (in the same directory), it will load quickly (~35ms). Not sure if it is only the word home, or if it also involves other keywords as well. There's nothing in my code that would cause /home to load slower than other routes either (hooks, etc).

I had another member of the Discord also test on their machine, and they confirmed the issue as well.

Note: This does only seem to be a development mode issue, there is not lag/delay after the site is built and in production.

Reproduction

I've created a minimal reproduction here https://github.com/dihmeetree/svelte-bug-repro

Logs

No response

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 31.81 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.0 - /usr/local/bin/node
    npm: 10.5.0 - /usr/local/bin/npm
    bun: 1.0.36 - ~/.bun/bin/bun
  Browsers:
    Safari: 17.4.1
  npmPackages:
    @sveltejs/adapter-auto: ^3.2.0 => 3.2.0 
    @sveltejs/adapter-cloudflare: 4.2.0 => 4.2.0 
    @sveltejs/kit: 2.5.5 => 2.5.5 
    @sveltejs/vite-plugin-svelte: 3.0.2 => 3.0.2 
    svelte: 4.2.12 => 4.2.12 
    vite: 5.2.7 => 5.2.7

Severity

annoyance

Additional Information

No response

dihmeetree commented 7 months ago

Does this need more context? Please let me know if so. You actually don't even need to clone my repo. I noticed that any SvelteKit app with a route named home will reproduce the bug (you can can even reproduce it with the npm create svelte@latest my-app command)

gterras commented 7 months ago

I don't see any difference in loading time between both routes in your example (dev mode). Check from another browser and/or computer.

dihmeetree commented 7 months ago

I don't see any difference in loading time between both routes in your example (dev mode). Check from another browser and/or computer.

Did you test on Windows or Mac? I just tested on a Lightsail VPS running Windows and it definitely seems to not be as bad as when running on a Mac. It may be something related to that.

gterras commented 7 months ago

Did you test on Windows or Mac? I just tested on a Lightsail VPS running Windows and it definitely seems to not be as bad as when running on a Mac. It may be something related to that.

Tested on chrome/firefox linux. My first bet would be Safari or one of its extension (adblocker?), try with another route named advertising or something like this.

dihmeetree commented 7 months ago

Did you test on Windows or Mac? I just tested on a Lightsail VPS running Windows and it definitely seems to not be as bad as when running on a Mac. It may be something related to that.

Tested on chrome/firefox linux. My first bet would be Safari or one of its extension (adblocker?), try with another route named advertising or something like this.

I use Chrome on Mac. Tested in Safari (No ad blocker) and I get the same result. I had another user (In the Svelte Discord) confirm the slowness as well (https://discord.com/channels/457912077277855764/1223280626724241439) Waiting to hear back from them on whether they use Mac or not (I'm assuming yes)

Edit: Confirmed, yes they are on Mac.

amit13k commented 7 months ago

This seems to be related to vite. I get similar issue in astro on Mac. After debugging a bit i found, vite does a few things whenever /home route is accessed.

        const stat = fs.statSync("/home")
        stat.isFile()
        stat.isDirectory()
        fs.existsSync("/home/package.json")

https://github.com/vitejs/vite/blob/088d24b9226959dd29f8bf881b8c684cf8d82f62/packages/vite/src/node/plugins/resolve.ts#L580

which is too slow for some reason on MacOS. I don't know/understand if it's necessary for vite to do this.

dihmeetree commented 7 months ago

Thank you @amit13k for pointing out that this issue also exists in the Astro framework as well, so this is most likely a Vite issue. An issue thread has been created here https://github.com/vitejs/vite/issues/16481