question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different-origin link to same path incorrectly getting handled by client-side router

See original GitHub issue

Describe the bug

Installing the default Skeleton with JS or TS and clicking on the link to https://kit.svelte.dev does not work.

Reproduction

Cannot follow link https://kit.svelte.dev from deployed and/or local Sveltekit installation. This is pretty much the default skeleton installation with JS or TS.

https://daiki-six.vercel.app/

Logs

Firefox

Uncaught (in promise) DOMException: The operation is insecure. start-f3a65506.js:1
    ge https://daiki-six.vercel.app/_app/start-f3a65506.js:1
    AsyncFunctionThrow self-hosted:704
    (Async: async)
    _start_router https://daiki-six.vercel.app/_app/start-f3a65506.js:1

Chrome

start-f3a65506.js:1 Uncaught (in promise) DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'https://kit.svelte.dev/' cannot be created in a document with origin 'https://daiki-six.vercel.app' and URL 'https://daiki-six.vercel.app/'.
    at he (https://daiki-six.vercel.app/_app/start-f3a65506.js:1:13087)
    at async ge (https://daiki-six.vercel.app/_app/start-f3a65506.js:1:18752)

https://github.com/robots4life/daiki

Firefox http://localhost:3000

Uncaught (in promise) DOMException: The operation is insecure. start.js:623
    navigate http://localhost:3000/@fs/shared/httpd/daiki/.svelte-kit/runtime/client/start.js:1256
    AsyncFunctionThrow self-hosted:704
    (Async: async)
    _start_router http://localhost:3000/@fs/shared/httpd/daiki/.svelte-kit/runtime/client/start.js:1460

Chrome http://localhost:3000

start.js:623 Uncaught (in promise) DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'https://kit.svelte.dev/' cannot be created in a document with origin 'http://localhost:3000' and URL 'http://localhost:3000/'.
    at update (http://localhost:3000/@fs/shared/httpd/daiki/.svelte-kit/runtime/client/start.js:623:64)
    at async navigate (http://localhost:3000/@fs/shared/httpd/daiki/.svelte-kit/runtime/client/start.js:1241:3)

System Info

System:
    OS: Linux 5.4 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 6.10 GB / 15.53 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 17.4.0 - /opt/nvm/versions/node/v17.4.0/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 8.3.1 - /opt/nvm/versions/node/v17.4.0/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.33 
    @sveltejs/adapter-node: ^1.0.0-next.73 => 1.0.0-next.73 
    @sveltejs/kit: next => 1.0.0-next.302 
    svelte: ^3.44.0 => 3.46.4

Severity

annoyance

Additional Information

Adding rel=external to the link makes it work.

Visit <a rel="external" href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
patricknelsoncommented, Apr 4, 2022

Tinkering with this on the weekends, I had only just picked up SvelteKit (and Svelte) for the very first time only 2 weeks ago (right after this broke). Naturally ,the very first thing I try is linking to www.google.com and I was getting errors, so of course I assumed I was doing something wrong! 😄 Stumbled upon this (since I hadn’t updated yet) since I was about to report a bug!

Thanks @robots4life for finding this and thanks to @Conduitry for putting in the effort to get this to 1.0!

1reaction
Conduitrycommented, Mar 23, 2022

Aha! This case was already supposed to be handled by the code at https://github.com/sveltejs/kit/blob/2865f41874bad7e373398e88a33a10b947f07210/packages/kit/src/runtime/client/client.js#L219 but this bug is specifically happening when we’re linking to the same path on a different origin, because the branch at https://github.com/sveltejs/kit/blob/2865f41874bad7e373398e88a33a10b947f07210/packages/kit/src/runtime/client/client.js#L205 is erroneously kicking in. (I’ll update the issue title.)

I think the proper fix is to just additionally check url.origin === location.origin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

next/link prefixing urls with / only on client side #19922 - GitHub
When using next/link a slash / get's prefixed to the url on client side but not on server. I had no errors on...
Read more >
react-router redirect to a different domain url - Stack Overflow
From within the code, you need to redirect the user to an external url, based on some programmatic logic. The question is asking...
Read more >
Understanding single page apps & client-side routing
Let's get some clarity on what single page apps are, how they work, and where they differ from server-side routing.
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
In this post you'll learn how to fix the 'cannot GET /URL' error with React Router. Along the way, you'll also learn how...
Read more >
Understand Open Shortest Path First (OSPF) - Design Guide
This is how routers know how to get to external routes in other ASs. Network Links are generated by a Designated Router (DR)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found