-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
fix(vue-app): consider watchQuery
option in routerViewKey
#5516
Conversation
It works the same as router.go(n) in vue-router.
Hi @utatti and thank you for your PR. I remember having something like this by default for a while, you can see some history here: #1022 You can see in this issue why I had to change the behaviour: #1255 (comment) This is not as simple as it looks like when doing such changes :/ But I do like what you did on the tests, and I think we should be able to:
|
So if I understand correctly, we keep the current behaviour and update the doc? I also thought that using the Also, I still think that triggerScroll should at least work with query changes specified in |
If using let key = this.$route.path
if (Component && Component.options && Component.options.watchQuery) {
const watchQuery = Component.options.watchQuery
if (watchQuery === true) {
key = this.$route.fullPath
} else if (Array.isArray(watchQuery)) {
key += `?${watchQuery.map(key => `${key}=${this.$route.query[key]}`).join('&')}`
}
}
return key The reason why I'd like to add a way to consider query in building key is that saving/restoring scroll position doesn't work currently when only query is changed. It's basically because query change is not considered as a vue-router transition (thus no I understand reusing component is important, but I guess considering Let me know your thought about the change above. I'll add follow-up fixes and test cases. Cheers |
routerViewKey
to route.fullPath
Codecov Report
@@ Coverage Diff @@
## dev #5516 +/- ##
=======================================
Coverage 95.67% 95.67%
=======================================
Files 81 81
Lines 2635 2635
Branches 671 671
=======================================
Hits 2521 2521
Misses 96 96
Partials 18 18 Continue to review full report at Codecov.
|
routerViewKey
to route.fullPath
watchQuery
option in routerViewKey
I've updated the p-r and now it's to consider I've also added more test cases. |
Hi @utatti Thank you so much for investigating into this, I like your changes actually! Could you also help to update the documentation to explain a bit more how it works, then I am ready to merge this PR :) (https://github.com/nuxt/docs/blob/master/en/api/components-nuxt.md) |
Thanks! I've just uploaded a p-r on docs: nuxt/docs#1331 |
As @clarkdo correctly mentioned in nuxt/docs#1331, this is a breaking change. |
Actually it's not really a breaking change, but mostly an improvement in the DX about transitions and scrollToTop from my POV |
@clarkdo Can you please re-review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a breaking change, new option watchQuery
as great enhancement.
All looks good, expect tiny change in my opinion.
const watchQuery = options.watchQuery | ||
if (watchQuery === true) { | ||
return this.$route.fullPath | ||
} else if (Array.isArray(watchQuery)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If watchQuery
is []
, is router.resolve
or fullPath
supposed to be the expected value ?
fix(vue-app): consider watchQuery
option in routerViewKey
(#5516)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from formatting issues which I've commented on.
Thanks all! |
* Fix extra space in package.json * all: Add additional information for nuxtChildKey Please refer to the following pull request in nuxt.js. nuxt/nuxt#5516
@clarkdo Yes, this is a breaking change in that manner. I understand we can use the According to the
However, only the scroll restoration and transition hooks are not working with I understand the final decision is up to maintainers, but I personally think the current behaviour is natural and the case like #5738 (where |
@utatti Hmm. I would argue that re-using the component as much as possible should not be the exception, but is instead the Vue way.
// this PR's behaviour in v2.6.3
export default {
key(route) {
return route.path + route.query.bar
}
} |
I understand that we can override the route key using I also agree that re-using components is essential, but the key discussion here is what
What I meant was 2 seemed natural to me than 1. I didn't mean that re-using component is exceptional. I'm actually good to revert the change if scroll restoration works at least somehow with All in all, I agree with you that reusing components is important and we should avoid breaking changes. |
Today I'll investigate if there is a better way that we reuse page components and make scroll restoration work at the same time. |
Types of changes
Description
According to the Nuxt documentation, the default
key
provided to<nuxt-child>
should be$route.fullPath
. Please check the reference ofnuxtChildKey
in the following link:However, the current code seems like using
$route.path
. Because of that, transition is not fired correctly when moving between the same page component, by changing query while keeping path the same.I guess the documentation is describing the correct behavior (
fullPath
) and the current code should be changed.It's my first contribution on Nuxt, so please feel free to guide me if I did something wrong :)
References
Commits
This p-r has 4 commits.
scrollToTop: false
, so I added a test case to checkscrollToTop: true
case.go()
helper method to browser test util.Checklist: