Vite dev server bundles two versions of a file causing `svelte-routing` to break
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:1
- Comments:13
Top GitHub Comments
Okay it’s not being reloaded. Vite bundles two versions of
history.js
to the browser. The versions received byApp.svelte
andRouter.svelte
are different, so thelistener
variable changed bynavigate()
call inApp.svelte
is different from the oneRouter.svelte
gets.Details:
Path to Version 1: Goes to Which goes to
Version 1 of history.js shown in red.
Version 2 is loaded by Router.svelte Which goes to
@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.