-
-
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
feat(vue-app): add prefetch
prop to <nuxt-link>
#6292
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #6292 +/- ##
=====================================
Coverage 95.6% 95.6%
=====================================
Files 79 79
Lines 2684 2684
Branches 692 692
=====================================
Hits 2566 2566
Misses 101 101
Partials 17 17
Continue to review full report at Codecov.
|
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.
My apologies to have to do this, but I have just added a compileTemplate test helper method I would like you to ask to use to add unit tests (using vue-test-utils) instead of adding new fixtures. Adding new fixtures is not preferred as building each fixtures takes at least 10 seconds to the total test time.
You can have a look at nuxt-loading.test.js for an example of an existing component unit test.
For this pr you could use the compileTemplate function as follows:
// nuxt-link.client.prefetch.test.js
const compiledTemplatePath = await compileTemplate('components/nuxt-link.client.vue', 'nuxt-link.client.prefetch.vue', { router: { prefetch: true } })
// nuxt-link.client.noprefetch.test.js
const compiledTemplatePath = await compileTemplate('components/nuxt-link.client.vue', 'nuxt-link.client.noprefetch.vue', { router: { prefetch: false } })
For quick reference, here is the link to the vtu docs
What about |
Maybe the best option is to wait for the PR #6287 to be merged? |
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.
Looks good to me.
Thanks for the recurring work you put into this pr!
I tried to do some tests but I faced some issues mounting the I think it's because So there is no test in this PR at the moment... 😕 |
Its probably because |
I tried but it has no effect 😕 |
What about something like this? import { createLocalVue } from '@vue/test-utils'
const localVue = createLocalVue()
// register stub component so nuxt-link extends its render fn
localVue.component('RouterLink', {
render: h => h('a')
})
// load nuxt-link |
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
<nuxt-link>
<nuxt-link>
<nuxt-link>
Still face the issue 😕, I made a WIP commit to show you the code :) (I also needed to fix a bug in the |
Hmm, could you try to explicitly set the |
Still facing the warning 😕 |
@lmichelin Hope you dont mind, but as I didnt knew the correct answer myself I just tried fixing this on your branch. The tests should work now. Feel free to improve them further if you wish! |
Nice! Thanks a lot for your help 😃 |
And btw do you agree with the fix in |
Yes, a bit sily to have I have added one more test condition btw, thought it was a bit disconcerting that VTU only logged an error but didnt seem to return/throw any error about the failed mount. So have added some spies on the console to make sure no errors or warnings are logged. @lmichelin Let us know btw if you think this PR is now ready or if you wish to make some other changes, thanks :) |
Do you want me to clean the commit history to squash some commits and remove |
@lmichelin Thanks but dont think that is necessary. The pr will be squashed when merged already so those commits wont show up on the dev branch anyway. |
Great work here @lmichelin 👏 One thing came to my mind when I read |
I asked the question here #6292 (comment) but @pi0 preferred not to deprecate it. |
It's ok for me! |
<nuxt-link>
<nuxt-link>
<nuxt-link>
prefetch
prop to <nuxt-link>
Type of changes
Bug fix(a non-breaking change which fixes an issue)Breaking change(fix or feature that would cause existing functionality to change)Description
Fixes #6135
<nuxt-link>
currently allows disabling prefetching with a specific link using a no-prefetch prop, but on the other hand, there is no way to prefetch a specific link when links prefetching is disabled globally vianuxt.config.js
withprefetchLinks: false
.This PR adds a
prefetch
prop to<nuxt-link>
which can be used whenprefetchLinks
is set tofalse
.Checklist: