sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.46k stars 1.89k forks source link

Shadow endpoints broken on browser back navigation, tries to fetch http://__data.json/ #3718

Closed pixelmund closed 2 years ago

pixelmund commented 2 years ago

Describe the bug

Hey, i've noticed that the shadow endpoints are broken if you try to navigate back with the default browser navigation, it tries to fetch http://__data.json/.

EDIT: This seems to be happening on every client side navigation.

Reproduction

https://github.com/pixelmund/shadow-endpoints-repro

Steps to reproduce:

2nd Method without pulling the repo:

The error is cause because the browser tries to fetch http://__data.json/.

Logs

500
Failed to fetch
TypeError: Failed to fetch
    at Renderer._load (http://localhost:3000/@fs/Users/info/Desktop/DEV/shadow-endpoints/.svelte-kit/runtime/client/start.js:1269:25)
    at async Renderer._get_navigation_result (http://localhost:3000/@fs/Users/info/Desktop/DEV/shadow-endpoints/.svelte-kit/runtime/client/start.js:999:19)
    at async Renderer.update (http://localhost:3000/@fs/Users/info/Desktop/DEV/shadow-endpoints/.svelte-kit/runtime/client/start.js:831:27)
    at async Renderer.handle_navigation (http://localhost:3000/@fs/Users/info/Desktop/DEV/shadow-endpoints/.svelte-kit/runtime/client/start.js:820:3)
    at async Router._navigate (http://localhost:3000/@fs/Users/info/Desktop/DEV/shadow-endpoints/.svelte-kit/runtime/client/start.js:413:3)

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 23.70 GB / 31.93 GB
  Binaries:
    Node: 16.2.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (97.0.1072.76)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.17
    @sveltejs/kit: next => 1.0.0-next.260
    svelte: ^3.44.0 => 3.46.4

Severity

blocking an upgrade

Additional Information

No response

Conduitry commented 2 years ago

It looks like the culprit is https://github.com/sveltejs/kit/blob/647131e00149cb5299042eedeb880efcd855a2df/packages/kit/src/runtime/client/renderer.js#L756

If url.pathname is /, we need to make sure we're not fetching //__data.json, which will be interpreted as a protocol-relative URL. This would probably also be an issue with other paths ending in a / (if https://kit.svelte.dev/docs#configuration-trailingslash were set so as to allow that to happen).

kdheepak commented 2 years ago

~I had to get around this by using rel="external".~

Using rel="external" resolves the problem when clicking on internal links. I'm not sure if there's a temporary solution for dealing with the currently broken browser back navigation function.

livehtml commented 2 years ago

Yep, quick workaround is manually edit the node_modules/@sveltejs/kit/assets/client/start.js~1269:

const res = await fetch(`${url.pathname == '/' ? '' : url.pathname}/__data.json`, {