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.

Vite dev server bundles two versions of a file causing `svelte-routing` to break

See original GitHub issue

Describe the bug

Using svelte-routing as the router, when navigate() is called, the address bar url changes, but the displayed route component doesn’t change. It appears that triggering of some event listeners are not working when running with Vite. (https://github.com/EmilTholin/svelte-routing/issues/199#issuecomment-826684338)

The same code works when used with plain Rollup, and when used with vite build + vite preview. Only vite dev server has the issue.

This could be related to https://github.com/vitejs/vite/issues/443.

Reproduction

https://codesandbox.io/s/distracted-star-uhss6?file=/src/App.svelte

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers: I don’t think this matters because I have tested the repro locally in different machines and inside codesandbox.io. Happy to provide if needed.


Used package manager: yarn

Logs

Not available. No errors are shown in the browser console either.



Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

1reaction
itsfarseencommented, Apr 26, 2021

Okay it’s not being reloaded. Vite bundles two versions of history.js to the browser. The versions received by App.svelte and Router.svelte are different, so the listener variable changed by navigate() call in App.svelte is different from the one Router.svelte gets.


Details:

Path to Version 1: image Goes to image Which goes to image

Version 1 of history.js shown in red.

image

Version 2 is loaded by Router.svelte image Which goes to image

0reactions
itsfarseencommented, May 22, 2021

@sidharthramesh I don’t think svelte routing is doing anything wrong here.
It’s an edge case that happens due to the way Vite dev server optimizes things.
We can easily opt out of that from the configuration. It doesn’t affect dev server performance much. It also doesn’t happen with the final build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Vite
Vite improves the dev server start time by first dividing the modules in an application into two categories: dependencies and source code.
Read more >
Docs • Svelte
SvelteKit utilizes Vite to build your code and handle server-side rendering (SSR). There are plugins for all the major web bundlers to handle...
Read more >
Having a hard time with SvelteKit's new router and ...
And, if they really didn't want file based routing anymore, fine. Force directory routing but use already established standards like index.
Read more >
Getting started with Svelte - Learn web development | MDN
Svelte provides a different approach to building web apps than some ... like server-side rendering, code splitting, file-based routing and ...
Read more >
SvelteKit API | SK Incognito - Vercel
SvelteKit currently uses Vite to (un)bundle your app. ... Routing. There are two types of routes in SvelteKit — pages, and server routes....
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