Skip to content

Component beforeRouteUpdate not triggered after hmr #2500

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

Open
char101 opened this issue May 14, 2025 · 3 comments
Open

Component beforeRouteUpdate not triggered after hmr #2500

char101 opened this issue May 14, 2025 · 3 comments
Labels
contribution welcome The team would welcome a contribution from the community for this issue enhancement New feature or request

Comments

@char101
Copy link

char101 commented May 14, 2025

Reproduction

https://github.com/char101/vue1

Steps to reproduce the bug

  1. Run pnpm run dev
  2. Click button, verify that the counter is increasing
  3. Add a comment on Test.vue to trigger hmr
  4. The button is no longer working, when clicking the button for the first time, the url is updated which implies that $router.push is working, but beforeRouteUpdate is not triggered.

Expected behavior

beforeRouteUpdate should still works after hmr.

Actual behavior

beforeRouteUpdate not called after hmr.

Additional information

No response

@char101
Copy link
Author

char101 commented May 14, 2025

I guess this is because to.matched.components[0].default is a different object after hmr to from.matched.components[0].default.

I would be nice if hmr-ed components can be detected as update in the development environment.

For now I guess the workaround is to only use this.$watch.

@posva posva added enhancement New feature or request contribution welcome The team would welcome a contribution from the community for this issue labels May 14, 2025 — with Volta.net
Copy link
Member

posva commented May 14, 2025

It's indeed an HMR bug with the options API only (works with onBeforeRouteUpdate()). Contribution welcome!

@char101
Copy link
Author

char101 commented May 14, 2025

I can't send a pull request but I can verify that removing {flush: 'post' } in

{ flush: 'post' }

fixed the problem. The cause is that after hmr, the instances.default value in both to and from routes are null, causing the guard not to be extracted. Although the watch is triggered, it is only run later due to the flush post option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome The team would welcome a contribution from the community for this issue enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants