Subscriptions bug when unmounting elm apps

I have an idea for a workaround for a long-standing issue with unmounting Html-based elm apps, curious to hear feedback on where this could go wrong. The issue is described here: and the fix is here:

AFAIK, this bug is the main thing keeping us from being able to mount multiple Elm apps on the same page. I’m looking into a possible architecture that would rely on this ability. Since it’s not very easy to contribute bug fixes to Elm libraries atm, I thought I’d try to come up with a workaround.

The basic idea is to wrap Html programs with a new program that does 3 things:

  1. Tracks whether or not the app is mounted by wrapping the app’s model with an isMounted property
  2. Renders a web component that dispatches a custom event when it’s detached from the DOM
  3. Makes subscriptions Sub.none when the isMounted property returns False, otherwise returns the app’s subscriptions

UPDATE: I’ve simplified and ellie-ified my example to something one could implement in any app. Appreciate any feedback on this anyone has.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.