-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
[SSR] Client data fetching in beforeMount mixin double-fetches #9252
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
Comments
This has to be solved in your business logic Since Vue won't decide for you how "fresh" you want your data to be. Certainly the example could be improved in this way, but that should be solved in the repository for the SSR docs (linked from within said docs): |
@LinusBorg I had created this very issue @ ssr-docs repo already (210) where you adivced me to open it here instead. So according to you, there is no proper place to open this issue. I am confused. :-) Regarding the issue itself: The usecase is: Prevent entry-client from calling Now, in the docs, there are two approaches mentioned for client data fetching.
Should we reopen the issue at ssr-docs then? |
Sorry about the confusion, i must have misinterpreted your original issue in the docs repository. I've reopened it, let's continue there |
Moved from vue-ssr-docs#210.
Version
2.5.21
Reproduction link
https://github.com/phil294/vue-hackernews-ssr-alternative-data-fetching
Steps to reproduce
In SSR docs, option 2, Fetch data after the matched view is rendered, calls
asyncData
inbeforeMount
.The pseudo-syntax is
This does not check if
asyncData
was already called by the server. Thus, guided by the official docs, this leads to duplicate fetches. In the case of dynamic module registration, even to duplicate modules.In the linked repro, I cloned vue-hackernews and changed the fetch method accordingly. I also added a console.log to when
fetchIdsByType
is called which happens whenasyncData
is called.What is expected?
Data is fetched on server, client does not fetch it again (as is the case with the usual
router.beforeResolve
solution (step 1).What is actually happening?
Data is fetched twice, also on client, because there is no check on whether the data is already there, effectively making option 2 unusable.
The text was updated successfully, but these errors were encountered: