zurb / foundation-apps

The first front-end framework created for developing fully responsive web apps.
http://foundation.zurb.com/apps
MIT License
1.58k stars 216 forks source link

Bug: FoundationApi.unsubscribe causes potential leaks and unintended sideffects #804

Open aptogo opened 8 years ago

aptogo commented 8 years ago

From a code inspection, Foundation.unsubscribe(name, callback) removes ALL listeners for the specified name. This works as intended in the case where 'name' is the ID of a specific element (for example, in modal.js or notification.js). However, the subscribe/unsubscribe mechanism is also used for the global 'resize' event. In several places in the codebase, Foundation.unsubscribe('resize') is used. This will detach ALL listeners of the resize event, not just the intended listener (e.g interchange.js line 233).

In addition, in iconic.js, the zfIconic directive subscribes to 'resize' but does not 'unsubscribe' when it is destroyed. This will lead to leaking of detached DOM elements.

The Foundation.unsubscribe method should be changed to allow un-subscription of a specific listener and all subscriptions should be checked for matching un-subscriptions to prevent leaks.

aptogo commented 8 years ago

You can demonstrate the leak from zfIconic by using the Chrome Dev timeline while viewing http://foundation.zurb.com/apps/docs and repeatedly switching between the Iconic tab and the Typography tab.

screenshot 2016-04-09 11 18 52
soumak77 commented 8 years ago

ZURB has basically dropped support for this framework and it is now being maintained by the community as https://github.com/base-apps/angular-base-apps.

I've gone through the entire codebase and wrote an unsubscribed method for every subscribe method. Feel free to run the same analytics against v1.2.5 and create issues as needed.