Skip to content

Commit 0893f54

Browse files
committed
fix(browser): fix location $digest() loop, ng-angular#3951
This is a refactor of the proposed solution, which guards against changing the url() from inside the location watcher.
1 parent 34b8650 commit 0893f54

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/ng/browser.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ function Browser(window, document, $log, $sniffer) {
125125

126126
var lastBrowserUrl = location.href,
127127
baseElement = document.find('base'),
128-
replacedUrl = null;
128+
replacedUrl = null,
129+
ignoreHashChange = false;
129130

130131
/**
131132
* @name ng.$browser#url
@@ -151,9 +152,13 @@ function Browser(window, document, $log, $sniffer) {
151152
// setter
152153
if (url) {
153154
if (lastBrowserUrl == url) return;
155+
ignoreHashChange = true;
156+
try{
157+
// Flag to ignore hashchange events occasionally generated in Android 2.2, 2.3
154158
lastBrowserUrl = url;
155159
if ($sniffer.history) {
156-
if (replace) history.replaceState(null, '', url);
160+
if (replace)
161+
history.replaceState(null, '', url);
157162
else {
158163
history.pushState(null, '', url);
159164
// Crazy Opera Bug: http://my.opera.com/community/forums/topic.dml?id=1185462
@@ -168,6 +173,9 @@ function Browser(window, document, $log, $sniffer) {
168173
replacedUrl = null;
169174
}
170175
}
176+
} finally {
177+
ignoreHashChange = false;
178+
}
171179
return self;
172180
// getter
173181
} else {
@@ -182,7 +190,7 @@ function Browser(window, document, $log, $sniffer) {
182190
urlChangeInit = false;
183191

184192
function fireUrlChange() {
185-
if (lastBrowserUrl == self.url()) return;
193+
if (lastBrowserUrl == self.url() || ignoreHashChange) return;
186194

187195
lastBrowserUrl = self.url();
188196
forEach(urlChangeListeners, function(listener) {

0 commit comments

Comments
 (0)