New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove popstate/hashchange event handler when app is torn down #9897

Closed
randombk opened this Issue Nov 4, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@randombk
Contributor

randombk commented Nov 4, 2014

When bootstrapping an app, angularjs adds an event listener to window to handle popstate and hashchange events (File /src/ng/browser.js on lines 285 and 287). This is not removed during teardown of the app, meaning that a later instance will be affected by the route/state configuration of the previous app (See issue #9877).

These handlers should be deregistered when the app's root DOM element is removed, or when $destroy() is called on an app's $rootScope. For the most part, this looks to be the only handler not attached to the app's DOM root, judging by a quick search for "jqLite(window).on", so fixing this should go a long way towards being able to fully tear down and remove every part of an angular application without requiring a page refresh.

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897
@randombk

This comment has been minimized.

Contributor

randombk commented Nov 4, 2014

I opened a pull request for a fix. I've already signed the CLA.

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

randombk added a commit to randombk/angular.js that referenced this issue Nov 4, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

@caitp caitp added this to the 1.3.x milestone Nov 11, 2014

randombk added a commit to randombk/angular.js that referenced this issue Dec 3, 2014

fix($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897

netman92 added a commit to netman92/angular.js that referenced this issue Aug 8, 2015

perf($rootScope): remove history event handler when app is torn down
Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes angular#9897
Closes angular#9905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment