-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
View Component unnecessarily updates when child route changes #1701
Comments
Aside from investigating how to fix this in the router, I think we could also look into optimizing this in Vue core. I think the renderer picks the vnode hooks directly from the vnode props when it needs to run them, so changing them should not require any processing/updating of the component itself. |
did you try moving the |
I want to experiment with that, but I see potential problems in as that function has a closure over Might not be a problem but needs thorough testing. Couldn't we also just do that in the watch, though? like, check wether the Need to test. |
It's true having the closure avoided timing issues. Having a watcher didn't cover all cases if I remember well but I think I added tests so they should fail if the change is not enough |
I'll give it a shot tomorrow |
I think I found a way of fixing this. It still rerenders when using a |
Did you end up figuring out what was going on here? I have the exact same problem - I have transition "appear" around my RouteView, and always having parents re-render (and re-fetch data) when it's unnecessary. |
Version
4.1.6
Reproduction link
codesandbox.io
Steps to reproduce
What is expected?
Should not log at all, because the component has receives no props and does not depend on any reactive data from the router.
So when a child route changes, it should not update.
What is actually happening?
Home.vue console.logs 3 times, meaning it re-rendered multiple times.
I'm pretty sure the reason for that is that
router-view
needs to re-render multiple times, and each time, a newonVNodeUnmounted
callback is added to the VieComponent vnode's props object here:router/packages/router/src/RouterView.ts
Lines 160 to 170 in e008551
So from the POV of Vue, the props changed. So it will run an update cycle of the router view.
The text was updated successfully, but these errors were encountered: