nanojsx / nano

🎯 SSR first, lightweight 1kB JSX library.
http://nanojsx.io
MIT License
1.46k stars 38 forks source link

[Bug] didUnmount() event console.log() fired too late on page change #87

Closed jrson83 closed 2 years ago

jrson83 commented 2 years ago

Describe the bug Install the router listener example and add a didUnmount() with console.log() to every component, like there is already for the didMount():

didUnmount() {
  console.log('[HomePage] didUnmount')
}

Run the app, click on About then Blog 219. You will see the console output in this order:

07:52:14.738 [HomePage] constructor
07:52:14.741 [HomePage] didMount
-> Click About

07:52:17.285 [AboutPage] constructor
07:52:17.285 [AboutPage] didMount
07:52:17.285 [HomePage] didUnmount
-> Click Blog 219

07:52:19.238 [BlogPage] constructor
07:52:19.238 [BlogPage] didMount
07:52:19.239 [AboutPage] didUnmount

Have a question? This might not be a big issue but this is very confusing. I spent hours testing with jest why components on my adapter unmount for no reason. Finally when I reproduced with router listener example, I recognized this is default behaviour. It would be great if we can fix this issue, since it might confuse people when debugging. If this is and should be default behaviour this should be written as notice in the docs.

yandeu commented 2 years ago

This is the normal behavior. didMount() will only be called once the node has been detached from the DOM. Yes, maybe we should add a notice to the documentation.