Why nuxtServerInit is called multiple times on site load
Asked Answered
C

2

6

I am working on nuxt-edge + auth.nuxt + vuex project and in the nuxtServerInit method of the store I am only logging a message in the console. When the site is reloaded the message gets printed multiple times. This seems to happen only in dev mode.

Clarisclarisa answered 12/9, 2018 at 9:14 Comment(2)
Whenever I ran into this problem it was because missing assets would fetch the error page which triggered it's own nuxtServerInit call.Tetrachloride
Seems that the vue devtools extension makes it's own call to the server onload. In Chrome there are multiple (many) requests to the server onload. I had to develop in Firefox because of this issue.Clarisclarisa
T
5

Any time an asset is requested from your server that results in an error, Nuxt will render and return an individual error for each file. Error pages are treated like any other page in Nuxt. This means nuxtSeverInit gets called for your initial request and gets called again for each error request on the server.

Check your Network requests to track down each error asset that is requested from your Nuxt server.

Tetrachloride answered 13/10, 2019 at 20:47 Comment(1)
Thank you much! This looks to be my exact scenario. Before I address the root cause I would like to identify these "error requests" so I can skip the app initialization code. How can I identify these requests as "error requests"? Thanks!Stoneblind
J
0

Just discovered that with nuxt all internal links should be created with NuxtLink, not href's, I had a menu bar with hrefs and saw api requests where I did not expect them, as I used NuxtServerInit in the store, but some other links did not result in extra api calls, these links were NuxtLink's.

Jejune answered 7/10, 2021 at 10:28 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Welloiled

© 2022 - 2024 — McMap. All rights reserved.