Nuxt.js: created() hook is running on server-side AND client-side

Created on 15 Mar 2019  路  2Comments  路  Source: nuxt/nuxt.js

Version

v2.4.5

Reproduction link

https://github.com/HapLifeMan/nuxt-ssr-created-issue

Steps to reproduce

  1. Clone and install the repo
  2. Run yarn run dev and see an error in full page
  3. Run yarn run build && yarn run start and see that works but throws an error in the console

What is expected ?

It is expected that the created hook is only executed once (from the SSR only) if the page is loaded from the server.

What is actually happening?

The created hook is running on server-side AND client-side when loading a page.
If we mutate a variable in the created, the server-side will do it correctly, but when the client-side will do it, as the variable has been already mutated, it will not recognize it and throw an error.

It throws a full-page error in dev environment but only displays an error in the console in prod.

Additional comments?

Thanks!

This bug report is available on Nuxt community (#c8843)
bug-report

Most helpful comment

This is intended behavior. beforeCreate and created are called on server and on client side :wink:

Further read:

All 2 comments

This is intended behavior. beforeCreate and created are called on server and on client side :wink:

Further read:

Hi @manniL, then I will change the way I developed it, thanks for your reply! 馃槉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

bimohxh picture bimohxh  路  3Comments

surmon-china picture surmon-china  路  3Comments

jaredreich picture jaredreich  路  3Comments