Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev server resolving file paths inconsistently causing duplicated imports after hot load #19135

Open
7 tasks done
spillz opened this issue Jan 4, 2025 · 1 comment
Open
7 tasks done
Labels
feat: html p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@spillz
Copy link

spillz commented Jan 4, 2025

Describe the bug

When running the dev server on a project where:

  • index.html references main.js
  • main.js references ./file2.js
  • file2.js references ./main.js

The server seemingly has issues identifying which files have already been loaded after a hot reload resulting in duplicate files causing errors and other unexpected runtime behavior. Here's my source list after the reload in Chrome's inspect panel:

image

The issue goes away if all files are imported their absolute paths (e.g. '/main.js' rather than './main.js') as described here. It appears that Vite isn't using a canonical path to identify the unique set of files for the update.

Reproduction

vite-test.zip

Steps to reproduce

unpack the zip files

cd <unpacked-folder>
npm i
npm run dev

change a file, save and check the source file list in browser's inspect panel.

System Info

Vite v6.0.6, Node v20, on Chomebook w/ ARM64 Linux but also replicated issue on windows.

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 6, 2025

I made a simplified reproduction https://stackblitz.com/edit/vitejs-vite-xmqbfoar?file=index.html

It looks like ?t=... injection logic here misses when the original url is relative:

const mod = server.environments.client.moduleGraph.urlToModuleMap.get(url)
if (mod && mod.lastHMRTimestamp > 0) {
url = injectQuery(url, `t=${mod.lastHMRTimestamp}`)
}

@hi-ogawa hi-ogawa added feat: html p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: html p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

No branches or pull requests

2 participants