nuxt: nuxtServerInit triggers twice
nuxtServerInit({ dispatch, commit }, { req, isServer }) {
if (req.session && req.session.access_token) {
if (isServer) {
return dispatch('user', req.session.access_token)
} else {
delete req.session.access_token
return commit('destroy')
}
}
}
this is triggering the user action twice …
note: the user action is returning a promise.
<div align="right">This bug report is available on Nuxt.js community (#c1674)</div>About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 15 (3 by maintainers)
Related to #4016. Working on a fix to prevent SSR renders for 404 hits inside
_nuxt. Actually, serve-placeholder implemented a long time ago, it should be only integrated.as it states in this comment it only happens when developers tools are opened
v2.2 doesn’t solve it
I had this issue where my NuxtServerInit was being called twice when I was loading up a page. The first call had the correct query params I was trying to load, the second call did not. When I had the dev tools open I had 3 calls. 1 with the query params of the page I was opening, 2 without.
After viewing more of the
contexttoo see what was going on. I realised the additional call was for an image, but my image was 404’ing so Nuxt was returning the 404 page on that request, which explains why I was getting a second request going through the NuxtServerInit call. My 404 image was returning the full 404 page.I think it might be a similar situation when the dev tools is open. Chrome may be making a secondary server call to get the source of the page, or other things regarding the Network tab. If this is the case, Nuxt would be functioning exactly as normal.
Edit: When I have the devtools open, I get a third request that is for the map file to my JS. But when I try to access that file directly I am getting a 404. I am guessing Chrome is just taking a guess as to where the file might be, and it is getting a 404 instead. This request for the map file is not shown in the dev tools when the 404 is encountered. Seems normal to me 😃
Why this issue is marked as closed? It’s still reproducible with Nuxt 2.2.0 when the console is opened. Please, reopen. Console should not affect Nuxt internal behavior.
@solonik1 could be caused by this -> https://github.com/nuxt/nuxt.js/issues/4016
Hi @cayaner
It’s not possible that
nuxtServerInitis called twice on server-side.Please check your code, or create a small repository to reproduce this issue, then re-open this issue.