Closed lindapaiste closed 9 months ago
There is no equivalent of the useBeforeUnload
hook in react-router v5 which we are using. We need to attach the handler directly to the window beforeunload
event. We were doing that previously in the class-component version.
Related to #2793. Here is the explanation of the current problem.
Originally posted by @lindapaiste in https://github.com/processing/p5.js-web-editor/issues/2590#issuecomment-1806901605
@raclim I realized that we lost the code which shows the alert when you try to close the entire window. 😠Not sure if I should add that in here or make a new PR?
https://github.com/processing/p5.js-web-editor/blob/d26d062d028ab97ca5a37ebf2b6805af26c3bcb1/client/modules/IDE/pages/IDEView.jsx#L94-L95
This was something that @dewanshDT and I discussed and I wrote a code to handle it using react-router v6 syntax. But then we ended up staying on v5 and I guess it got lost in the shuffle. I don't think either of us wrote a function component v5 version.
Here is some of our discussion and the v6 code: