Search code examples
javascriptvuejs3nuxt3.jslifecyclepage-lifecycle

What happens inside javascript-based Pages if power goes off (PC shutting down suddently) (ex: Vue)


Maybe this is a silly question, Regarding Vue 3 lifecycle hooks. Any idea if a lifecycle hook of unmounted or something like the old Vue 2 destroyed is called, if there is a sudden power off (cut of electricity or batery died), and the computer shuts down before closing the page or the navigator. I'm not sure if the application interprets this a unmounted event + have time to execute within the unmounted hook.

This question presented itself while studying the possibility of saving the application data only inside this (unmounted) hook.

This question is also valid for other frameworks, such as Angular, but I'm more interested in Vue.

Thank you in advance,

Carlota


Solution

  • Nothing will have the time to do anything. Not even the OS. Yes it is that far deep.

    There is nothing you can do when the machine loses power because the CPU (and GPU if any) shuts down. The applications running on the OS and even the OS cannot do anything if the CPU is switched off.

    Losing power is not something a software engineer can handle because it is beyond the scope of any software to handle. If losing power is a possibility that will destroy any important work in progress, you have to consider other design possibilities and in many cases, there is none.

    I know how many times I had to create a fresh Ubuntu install on my machine because I lost power and my battery died in the process of an OS upgrade.