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

Only last hot.accept callback function is called #158

Closed
marvinhagemeister opened this issue May 15, 2020 · 0 comments · Fixed by #170
Closed

Only last hot.accept callback function is called #158

marvinhagemeister opened this issue May 15, 2020 · 0 comments · Fixed by #170

Comments

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented May 15, 2020

Describe the bug

When multiple plugins are in play it may happen that we end up with many calls to hot.accept() in the same file:

if (__DEV__) {
	hot.accept(() => {
		console.log("A");
	});
	hot.accept(() => {
		console.log("B");
	});
}

Problem is that only the latter will be called. The console will never print "A" on HMR. We ran into this error with prefresh (our Preact HMR plugin) and a custom error overlay plugin I'm currently writing.

The source of the problem is in this line where the callback for the current file is overwritten:

https://github.com/vuejs/vite/blob/d1bdf5a07fdae032a69987ac238bc0d68881b3f2/src/client/client.ts#L179

Reproduction

https://github.com/marvinhagemeister/vite-hmr-bug

System Info

  • required vite version: 0.15.3
  • required Operating System: Arch Linux
  • required Node version: v14.1.0
  • Optional:
    • npm/yarn version: yarn 1.22.4
    • Installed vue version (from yarn.lock or package-lock.json)
    • Installed @vue/compiler-sfc version

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
$ vite --debug
vite v0.15.3
  vite:optimize Hash is consistent. Skipping. Use --force to override. +0ms
Port 3000 is in use, trying another one...
  vite:optimize Hash is consistent. Skipping. Use --force to override. +0ms

  Dev server running at:
  > Local:    http://localhost:3001/
  > Network:  http://192.168.178.45:3001/

  vite:server server ready in 631ms. +0ms
  vite:history redirecting / to /index.html +0ms
  vite:hmr         /index.html imports /main.js +0ms
  vite:history not redirecting /main.js (has file extension) +164ms
  vite:rewrite /main.js: rewriting +0ms
  vite:resolve (extension) /home/marvinh/dev/test/vite-hot-accept/foo -> /home/marvinh/dev/test/vite-hot-accept/foo.js +0ms
  vite:rewrite     "./foo" --> "/foo.js" +2ms
  vite:hmr         /main.js imports /foo.js +162ms
  vite:history not redirecting /foo.js (has file extension) +27ms
  vite:rewrite /foo.js: rewriting +25ms
  vite:rewrite     "vite/hmr" --> "/vite/hmr" +10ms
  vite:history not redirecting /favicon.ico (has file extension) +29ms
  vite:rewrite (skipped) /favicon.ico +18ms
[vite:hmr] /foo.js updated due to change in /foo.js.
  vite:hmr update: {
  vite:hmr   "type": "js-update",
  vite:hmr   "path": "/foo.js",
  vite:hmr   "changeSrcPath": "/foo.js",
  vite:hmr   "timestamp": 1589566121861
  vite:hmr } +5s
  vite:rewrite /foo.js: cache busted +5s
  vite:hmr ws client connected +4s
underfin added a commit to rolldown/vite that referenced this issue May 17, 2020
yyx990803 pushed a commit that referenced this issue May 18, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
weihanglo Weihang Lo
fix #158
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants