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): this.$nuxt.refresh doesn't refresh every fetch hooks #9530
base: 2.x
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #9530 +/- ##
=======================================
Coverage 65.19% 65.19%
=======================================
Files 94 94
Lines 4155 4155
Branches 1172 1172
=======================================
Hits 2709 2709
Misses 1167 1167
Partials 279 279
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
packages/vue-app/template/App.js
Outdated
} else { | ||
// Get all component instance to call $fetch | ||
// get layout component | ||
const layout = this.$children.find((component) => component._name?.toLowerCase().includes("layouts")) |
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.
Refactor suggest: Maybe we can use let root = page
and change it to parent layout instance if exists? (this way we merge to branches)
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.
I think this also makes sense to only crawl everything once, also keeping getChildrenComponentInstancesUsingFetch
simple. What was your opinion on that @ms-fadaei?
Can you please ensure about this? If is a case, we might make use of WeakSet to dedup. (Note: IE support 🤷) Also can you please check behavior when page does not having $fetch but layout does? |
I checked that right now. it not working properly with nested routes (then I should refactor the code) |
@pi0 If a child has the fetch, children of it will not be considered! |
And I realized the sequence call of fetch (first parent then child) is not guaranteed! (in the current version this is just about nested routes because of limited fetch calls but in my version, this occur in every parent-child relations) |
Hey friends, what's up on this one? Cheers! |
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.
I think the main thing we still need to handle is:
- ensure that we don't duplicate fetches (for example if a component with fetch is included in both a page/layout) - see fix(vue-app): this.$nuxt.refresh doesn't refresh every fetch hooks #9530 (comment) for one approach
I'll try to have a look at the last bit @danielroe mentioned this week 💪 Keeping you up-to-date! |
OK, I'm having a bit of trouble understanding the "duplicate fetch" maybe issue mentioned above. Looking at the changes, 3 things have been achieved:
Taking all of those changes individually they seem pretty straightforward to me. Basically, the I don't really see how we can end up with duplicate calls here, or at least how we can end up with duplicate calls we didn't have already before(?) Now, maybe where I'm wrong is on my understanding of the If I'm wrong here and there's definitely something leading to duplicated behaviors, I'm not sure however a set would solve the issue? Or maybe it would? I'd be afraid only some of the deduplicated hooks get called and that the others remain stale (a.K.a. no new data?) Let me know! |
@ms-fadaei @lihbr Can you please check the latest |
Hey there, Unfortunately, this doesn't appear to fix the issue as the component-crawling function still starts from the page component instead of the layout. Maybe I'm doing something wrong, here's my repro on edge: nuxt_nuxt.js_9530_1.zip |
Thanks for checking @lihbr. @ms-fadaei Would you please rebase your branch to dev? |
Hi Pooya, |
@@ -214,6 +221,24 @@ export default { | |||
|
|||
return Promise.all(p) | |||
}) | |||
|
|||
<% if (features.fetch) { %> |
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.
Should this be considered again here? From #10489
With this fix, layout fetch, layout child components fetch (including the page), and page child component fetch will be called during the Nuxt refresh helper.
Types of changes
Description
In the current version of the Nuxt when we call $nuxt.refresh(), the page fetch will be called if the current page has a fetch, otherwise, the child components fetch method will be called.
with this fix:
Caution: What about nested routes? layout fetch will be inserted twice? can use
set
instead ofarray
to prevent duplication?fix: #9439
Checklist: