-
Notifications
You must be signed in to change notification settings - Fork 27.3k
fix($location): avoid unnecessary $locationChange* events due to empty hash
#16636
Changes from 1 commit
7f524c4
8f28de4
8053bc4
bbf6900
b085893
c37c2e4
cdd1f42
d736771
c3ca532
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
$locationChange* events du…
…e to empty hash
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| 'use strict'; | ||
| /* global stripHash: true, trimEmptyHash: true */ | ||
| /* global stripHash: true */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could move
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Even if we had imports/exports (which we don't because everything lives inside the great AngularJS IIFE 😁), I don't see two way importing going on. (We definitely have enough URL-specific helpers that we could move them into a separate file and "import" from there 😁)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a little weird having
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about "always", but it definitely was the case before this PR 😛 |
||
|
|
||
| var PATH_MATCH = /^([^?#]*)(\?([^#]*))?(#(.*))?$/, | ||
| DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21}; | ||
|
|
@@ -95,17 +95,11 @@ function stripBaseUrl(base, url) { | |
| } | ||
| } | ||
|
|
||
|
|
||
| function stripHash(url) { | ||
| var index = url.indexOf('#'); | ||
| return index === -1 ? url : url.substr(0, index); | ||
| } | ||
|
|
||
| function trimEmptyHash(url) { | ||
| return url.replace(/#$/, ''); | ||
| } | ||
|
|
||
|
|
||
| function stripFile(url) { | ||
| return url.substr(0, stripHash(url).lastIndexOf('/') + 1); | ||
| } | ||
|
|
@@ -944,7 +938,7 @@ function $LocationProvider() { | |
|
|
||
|
|
||
| // rewrite hashbang url <> html5 url | ||
| if (trimEmptyHash($location.absUrl()) !== trimEmptyHash(initialUrl)) { | ||
| if ($location.absUrl() !== initialUrl) { | ||
| $browser.url($location.absUrl(), true); | ||
| } | ||
|
|
||
|
|
@@ -963,7 +957,6 @@ function $LocationProvider() { | |
| var oldUrl = $location.absUrl(); | ||
| var oldState = $location.$$state; | ||
| var defaultPrevented; | ||
| newUrl = trimEmptyHash(newUrl); | ||
| $location.$$parse(newUrl); | ||
| $location.$$state = newState; | ||
|
|
||
|
|
@@ -991,8 +984,8 @@ function $LocationProvider() { | |
| if (initializing || $location.$$urlUpdatedByLocation) { | ||
| $location.$$urlUpdatedByLocation = false; | ||
|
|
||
| var oldUrl = trimEmptyHash($browser.url()); | ||
| var newUrl = trimEmptyHash($location.absUrl()); | ||
| var oldUrl = $browser.url(); | ||
| var newUrl = $location.absUrl(); | ||
| var oldState = $browser.state(); | ||
| var currentReplace = $location.$$replace; | ||
| var urlOrStateChanged = !urlsEqual(oldUrl, newUrl) || | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is
getHashused globally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is "used" in tests, in a mock window. The feature that relies on it is not actually used atm, so there were no breakages.
See 34fe24f (yes, there is a typo in that commit message 😁).