created() hook is running on server-side AND client-side

HapLifeMan
0
HapLifeMan
commented 5 months ago

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!

bug
0
manniL
5.7k
manniL
commented 5 months ago

This is intended behavior. beforeCreate and created are called on server and on client side ๐Ÿ˜‰

Further read:

0
HapLifeMan
0
HapLifeMan
commented 5 months ago

Hi @manniL, then I will change the way I developed it, thanks for your reply! ๐Ÿ˜Š

0
Informations
Bug Report โ€ข Open
#c8843 - Created 5 months ago