Skip to content

Commit 49fa2b1

Browse files
committedApr 22, 2015
fix($browser): prevent infinite $digest from no trailing slash in IE9
fix($browser): prevent infinite $digest from no trailing slash in IE9 This fix prevents IE9 from throwing an infinite $digest error when the user accesses the base URL of the site without a trailing slash. Suppose you owned http://www.mysite.com/app and had an Angular app hosted in a subdirectory "app". If an IE9 user accessed http://www.mysite.com/app infinite $digest errors would be thrown on the console, but the app itself would eventually resolve properly and work fine. Now the infinite $digest errors will not be thrown. Closes angular#11439
1 parent b64519f commit 49fa2b1

File tree

3 files changed

+407
-1
lines changed

3 files changed

+407
-1
lines changed
 

‎src/ng/browser.js

+20
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ function Browser(window, document, $log, $sniffer) {
135135
cacheState();
136136
lastHistoryState = cachedState;
137137

138+
/**
139+
* @name $browser#forceReloadLocationUpdate
140+
*
141+
* @description
142+
* This method is a setter.
143+
*
144+
* If the reloadLocation variable is already set, it will be reset to
145+
* the passed-in URL.
146+
*
147+
* NOTE: this api is intended for use only by the $location service in the
148+
* $locationWatch function.
149+
*
150+
* @param {string} url New url
151+
*/
152+
self.forceReloadLocationUpdate = function(url) {
153+
if (reloadLocation) {
154+
reloadLocation = url;
155+
}
156+
};
157+
138158
/**
139159
* @name $browser#url
140160
*

‎src/ng/location.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ function $LocationProvider() {
883883
$browser.url($location.absUrl(), true);
884884
}
885885

886-
var initializing = true;
886+
var initializing = true, previousOldUrl = null, previousNewUrl = null;
887887

888888
// update $location when $browser url changes
889889
$browser.onUrlChange(function(newUrl, newState) {
@@ -918,6 +918,15 @@ function $LocationProvider() {
918918
$rootScope.$watch(function $locationWatch() {
919919
var oldUrl = trimEmptyHash($browser.url());
920920
var newUrl = trimEmptyHash($location.absUrl());
921+
if ($location.$$html5 && !$sniffer.history) {
922+
if (previousOldUrl === oldUrl && previousNewUrl === newUrl) {
923+
// break out of infinite $digest loops caused by default routes in hashbang mode
924+
$browser.forceReloadLocationUpdate(newUrl);
925+
previousOldUrl = previousNewUrl = null;
926+
return;
927+
}
928+
previousOldUrl = oldUrl, previousNewUrl = newUrl;
929+
}
921930
var oldState = $browser.state();
922931
var currentReplace = $location.$$replace;
923932
var urlOrStateChanged = oldUrl !== newUrl ||

0 commit comments

Comments
 (0)