You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During development (nuxt dev), if using nuxt-i18n (more specifically vue-i18n) and navigating to a route in another locale, the asyncData of the page component is called twice.
(And also the route object within the asyncData is not set up correctly.)
This is only a problem during development since it's related to "hot reload" which is not enabled otherwise.
That custom $forceUpdate function also does set the route on the context which doesn't seem right in this case as there is a pending transition to another route at that time already.
Maybe the $forceUpdate logic should be skipped entirely if there is a pending route transition? Can't say for sure as I don't know that code but that's the first thing that came to my mind.
The text was updated successfully, but these errors were encountered:
I've recently discovered this, too. This is indeed the case for development mode only. What's even more awkward - asyncData on the page is being called when navigating away from that page.
I have a single page app that loads all page contents in asyncData. My vue-i18n locale is updated inside asyncData of the page. That creates an endless http request loop in dev mode until the locale is finally set inside the watcher by $set(): locale changes -> patched $forceUpdate called -> asyncData called again -> locale changes ... and so on.
Thanks for your contribution to Nuxt!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Verify that you can still reproduce the issue in the latest version of nuxt-edge
Comment the steps to reproduce it
Issues that are labeled as pending will not be automatically marked as stale.
During development (
nuxt dev
), if usingnuxt-i18n
(more specificallyvue-i18n
) and navigating to a route in another locale, theasyncData
of the page component is called twice.(And also the
route
object within theasyncData
is not set up correctly.)Versions
Reproduction
https://codesandbox.io/s/nuxtjs-bug-dev-vue-i18n-asyncdata-5fwl7
Steps to reproduce
nuxt-i18n
with two localesasyncData
hooknuxt-link
that navigates to a route in another locale.What is Expected?
asyncData
is triggered oncecontext.route.path
fromasyncData
reports the new (target) route path.What is actually happening?
asyncData
is triggered twicecontext.route.path
fromasyncData
reports a wrong (old) route both times.Additional details
See also nuxt-modules/i18n#1160
Here is what is happening:
vue-i18n
callsVueComponent.$forceUpdate()
on locale change: https://github.com/kazupon/vue-i18n/blob/13f3e618d5a7c3c32fe99f156d1ee2b4e199a5a4/src/index.js#L250-L259In dev mode, Nuxt implements/overrides
$forceUpdate
to trigger, amongst others, anasyncData
call: https://github.com/nuxt/nuxt.js/blob/8e2cad5a8fd7c4fa731fea92d762b650ee5ce095/packages/vue-app/template/client.js#L740-L746This is only a problem during development since it's related to "hot reload" which is not enabled otherwise.
That custom
$forceUpdate
function also does set the route on the context which doesn't seem right in this case as there is a pending transition to another route at that time already.Maybe the
$forceUpdate
logic should be skipped entirely if there is a pending route transition? Can't say for sure as I don't know that code but that's the first thing that came to my mind.The text was updated successfully, but these errors were encountered: