Overwolf windows close without running componentWillUnmount lifecycle methods

Issue Description:

When using React, you have 2 methods to cleanup side effects from components:

  • componentWillUnmount
  • useEffect’s cleanup function

When a window in overwolf is closed, the window is closed directly without running this react flow

Can you reproduce it:

yes.

  1. Create a simple OW app using react (“Hello world” window)
  2. Add a console.log to one of the mounted components’s componentWillUnmount lifecycle
  3. Observe the logs.

At this point, you’ll notice that the log is written (as the method did not run)

Impact for my app:

Medium-High
We have some functionalities that don’t run due to that and it may cause data corruption/ missing analytics

Do you currently have a workaround?

Not really.
The closest workaround we have involves registering to beforeunload, which means potentially running these flows twice or more sometimes.

1 Like

Generally - it is a good idea to decouple presentation from data - especially when a corruption can occur.

It’s recommended using a background page that is not affected by the relevant window closure and can listen to such events and clean the relevant components.

In the (not near) future we’ll try adding an onbeforeunload event (but it’s still not a best practice).

Sounds good to me, you can close the issue :slight_smile:


For future readers of this topic, I found a Stack Overflow question that answers this issue in browser based environments too:
https://stackoverflow.com/questions/61409648