Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($location): prevent infinite digest error due to IE bug
Browse files Browse the repository at this point in the history
If an app uses HTML5 mode and we open an html5 url on IE8 or 9 which
don't support location href, we use location.replace to reload the page
with the hashbang equivalent of the url but this fails with infinite
digest. This is because location.replace doesn't update location.href
synchronously on IE8 and 9.

Closes #2802, #3305, #1417
  • Loading branch information
Pavel Vasek authored and IgorMinar committed Jul 24, 2013
1 parent 0a3ec5f commit dca2317
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function Browser(window, document, $log, $sniffer) {
//////////////////////////////////////////////////////////////

var lastBrowserUrl = location.href,
baseElement = document.find('base');
baseElement = document.find('base'),
replacedUrl = null;

/**
* @name ng.$browser#url
Expand Down Expand Up @@ -159,14 +160,21 @@ function Browser(window, document, $log, $sniffer) {
baseElement.attr('href', baseElement.attr('href'));
}
} else {
if (replace) location.replace(url);
else location.href = url;
if (replace) {
location.replace(url);
replacedUrl = url;
} else {
location.href = url;
replacedUrl = null;
}
}
return self;
// getter
} else {
// the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
return location.href.replace(/%27/g,"'");
// - the replacedUrl is a workaround for an IE8-9 issue with location.replace method that doesn't update
// location.href synchronously
// - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
return replacedUrl || location.href.replace(/%27/g,"'");
}
};

Expand Down

3 comments on commit dca2317

@jonbcard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I'm still running into a problem suspiciously similar to what @IgorMinar described on #1417 even after applying this patch ( though it seems to have prevented the infinite $digest in another case ). I'll see if I can isolate this a little bit more, but wanted to give I heads up that I think there is still an issue here.

@danielcha
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch (applied to 1.1.5) did fix all my $digest errors. However when I click the back button in IE8/IE9 you get scrolled to the top, but the previous page is not loaded/shown although the url changes as expected. Can anybody confirm this aswell? What I did:

  1. open an html5 url (i.e. domain.tld/blog)
  2. it gets succesfully (and without errors) rewritten tot domain.tld/blog/#/ (my base is /blog/)
  3. click any url (i.e. domain.tdl/blog/#/1234)
  4. blog article is shown and url changes as expected
  5. click the back button
  6. you jump to the top, the url changes, but the blog article still shows instead of the expected blog index page

@elemoine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch does not fix the problem raised by @IgorMinar in #1417. @IgorMinar, the issue you described in #1417 (using "Angular in an existing project that makes use of html5 history (goog.history.Html5History for example) is not IE-specific at all.

Please sign in to comment.