Normally compose applications should behave the sa...
# compose-web
m
Normally compose applications should behave the same on all platforms. However I just realized that this is not always the case and may spoil your whole program logic. I developed an application on desktop for better developer experience but actually want to deploy it as a Wasm PWA. This normally works nicely but I now stumbled over an annoying inconsistency. The problem is that on desktop DisposableEffects are always executed when the composition is left even if the user just closes the window completely and thus terminates the application. On the wasmJs platform however this is not the case. If the user just closes the browser window then any pending DisposableEffects are not executed. In my case this had the effect that some important values were not persisted. This inconsistent behaviour may spoil your whole program logic if you rely in this way on the execution of DisposableEffects. I just wrote this up because it may possibly help someone else to avoid this pitfall.
👍 3
👀 1
d
Note that on desktop, you're not guaranteed against crashes (app crashes, system crashes, battery out of power, etc.) and so it is customary for desktop application to have a periodic save of the application state, or some other recovery policy. Also on web, IIRC you can always open a background job (with workers) that is not tied to the browser window to do cleanups. (To be verified)
m
Sure, you could all do that and in a way that’s what I am doing now. Nevertheless, it means you have to be prepared for such surprises and when something works on desktop this doesn’t automatically mean it will work on web too even if it compiles 🤨.
👍 2
l
This page has a lot of details about the differences in lifecycle between platforms: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-lifecycle.html