vite icon indicating copy to clipboard operation
vite copied to clipboard

Generated index.html is the same for different requests

Open DudaGod opened this issue 1 year ago • 1 comments

Describe the bug

I write MRE - https://github.com/DudaGod/vite-gen-index.html-issue. In this repo I use post hook configureServer in which I call transformIndexHtml on each request. I expect that for different queries (they differ in the value of the query parameter) will be generated different index.html. But when opening two pages with different query parameters at the same time I get the same generated script that outputs the log from the first request.

  • http://localhost:4444/@id/x00/?uuid=12345?html-proxy&index=0.js
  • http://localhost:4444/@id/x00/?uuid=67890?html-proxy&index=0.js

Reproduction

https://github.com/DudaGod/vite-gen-index.html-issue

Steps to reproduce

  1. Install packages using npm install
  2. Run script node ./vite-run.js
  3. As a result, 2 pages with http://localhost:4444/?uuid=12345 and http://localhost:4444/?uuid=67890 urls will open. And both of them will have 12345 in the log (it is almost always reproduced with rare exceptions).

System Info

System:
  OS: macOS 13.6
  CPU: (10) arm64 Apple M1 Pro
  Memory: 529.50 MB / 32.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.12.1/bin/yarn
  npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  pnpm: 6.34.0 - ~/.nvm/versions/node/v18.12.1/bin/pnpm
Browsers:
  Chrome: 124.0.6367.61
  Safari: 16.6
npmPackages:
  vite: ^5.2.9 => 5.2.9

Used Package Manager

npm

Logs

No response

Validations

DudaGod avatar Apr 19 '24 09:04 DudaGod

Looks like problem is here. Inside cleanUrl all query params are replaced to empty string. As a result all my requests cached to the same path - /.

Looks like this is expected behaviour and in my case I should modify query parameter to path, like this: http://localhost:4444/?uuid=12345 -> http://localhost:4444/12345

DudaGod avatar Apr 19 '24 11:04 DudaGod