Description
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
in beforeMount
.
The pseudo-syntax is
if (asyncData)
asyncData()
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 when asyncData
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.