Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upjustification for adding app.kill() #886
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Jul 15, 2017
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Jul 15, 2017
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
evancz
changed the title from
Leaking Event handlers when using multiple elm apps with routing on page
to
Multiple Elm apps on the same page can leak event handlers / app.kill() justification
Jul 16, 2017
evancz
added
the
problem
label
Jul 16, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ChristophP
Jul 21, 2017
I actually found out that leaking stuff is not necessarily specific to multiple elm apps on the page, but more to reinitializing elm modules(calling Elm.<Module>.embed/fullscreen()). This can happen for example when using react-elm-components and mounting the component multiple times (i.e. by navigating to a part of the page where the component isn't shown and then back to where it is) if subscriptions are used without reloading the page.
I created an example here: https://ellie-app.com/3LHDqnYqD4za1/10
ChristophP
commented
Jul 21, 2017
•
|
I actually found out that leaking stuff is not necessarily specific to multiple elm apps on the page, but more to reinitializing elm modules(calling I created an example here: https://ellie-app.com/3LHDqnYqD4za1/10 |
evancz
changed the title from
Multiple Elm apps on the same page can leak event handlers / app.kill() justification
to
justification for adding app.kill()
May 2, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joefiorini
May 4, 2018
@ChristophP Almost a year later, but I just came up with a workaround for this issue; using web components, you can fire a custom event when the elm app is detached from the DOM. You could then create a custom program function that automatically disconnects subscriptions when the app is unmounted. I have not tested this extensively yet, but I can verify it fixes the ellie example you posted above. Here's the ellie:
joefiorini
commented
May 4, 2018
•
|
@ChristophP Almost a year later, but I just came up with a workaround for this issue; using web components, you can fire a custom event when the elm app is detached from the DOM. You could then create a custom program function that automatically disconnects subscriptions when the app is unmounted. I have not tested this extensively yet, but I can verify it fixes the ellie example you posted above. Here's the ellie: |
ChristophP commentedJul 15, 2017
•
edited by evancz
Edited 1 time
-
evancz
edited Jul 16, 2017 (most recent)
The problem
We have an app shell architecture, meaning a host app that loads several other apps on our page. This lets us maintain and deploy each app separately. The app shell routes to
/app1and App 1 will route to everything after/app1/.... Some of the loaded apps are usingNavigation.program. When the path changes from/app1to/app2, App 1 still listens to popstate events even though it should be idle.Possible workarounds
There are a couple of ways to circumvent this from being a problem.
Removing all subscriptions. => Won't work. There is no way to tell the
Navigation.programto stop listening to this event since the subscription is untouchable and always there https://github.com/elm-lang/navigation/blob/master/src/Navigation.elm#L73."Turning off" the App1 when routing away (with something like this
update = (\model msg -> if model.isMounted then update model msg else (model, Cmd.none))) => would work but bloats the model and update function a little bit.Making sure each app only parses routes that are within it's namespace (only parse stuff starting with
/app1)All these methods will just elimate the reaction to the event, rather than removing the actual event listener.