-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Leaving templateUrl empty in $routeProvider.when() crashes the browser #12176
Comments
Can you elaborate on "crash"? If the browser crashes, that's a Firefox bug you should report on bugzilla.mozilla.org. If you just mean it throws, that seems expected |
If we're doing some string processing that blocks the browser, then we should fix that, though. |
When I first noticed the problem (by clicking on a link whose routing was set to a In subsequent tests, I can replicate the unresponsiveness and high CPU usage every time, but I no longer get the option to stop the script; the browser just crashes and the Crash Reporter opens. This only happens when templateUrl is an empty string. I chose to report it here because I suspected either an infinite loop in AngularJS or perhaps a lack of input validation for the function that uses the templateUrl setting to setup the route. |
Thanks for the details. And you're sure you can't replicate this on another browser? If we're blocking in an infinite loop somewhere you ought to be able to. I'll take a look when I can unless someone else gets to it first, or if it's been fixed already in 1.4.1 |
I have not tried it on another browser |
Do you think you could put together a simple reproduction? I've gotten it started at http://plnkr.co/edit/W9ES8v50DFHh3LWUa9N8?p=preview but so far haven't been able to break any browsers I've tried it with |
Nevermind, I've repro'ed it =) |
http://plnkr.co/edit/iBeXT1Y5I71jEdOB3D4w?p=preview this will break in all browsers --- so we never emit $routeChangeError in this case, but it looks like we should be taking that path since we get the 404 for the empty template string. This is not a regression, it's been broken since at least v1.2.0 |
This is pretty bad since it will affect all 404s, not just programming errors --- anyone want to fix this? |
I can't reproduce the broken-ness. 404 errors seem to be handled correctly (and |
It seems the issue arises when If we are talking about this error, then it's basically a nested |
I can reproduce the bug with the @caitp's plnkr or on my own by defining a route with an empty templateUrl option. Looking at the source code, we can see that the According to the doc this function determines if a reference is defined. In our case, with an empty However, the behavior in this case could be either to redirect to the URL displaying an empty html page without crash, or either to redirect anywhere else (default could be '/'). Throwing an error could also be done to trigger the Need feedbacks. |
As already mentioned, the problem I can see is that using The cause of the problem (afaict) is not related to routing, but to nested |
BTW, here is a quick-and-dirty fix (decorating the |
Indeed, the This could be fixed by adding a check before attaching the content view to the DOM inside the @gkalpak, what do you think? |
@gdangelo, imo the issue should be caught and prevented before reaching the That said, it is pretty difficult to have a reliable solution (taking into account corner-cases such as multiple apps on the page and |
I ran into this issue as well. The following code reproduces this problem reliably in all browsers (but not in codepen or plunkr). It is clearly an infinite loop issue as can be seen by repeated "Title" on page and repeated 'in modalCtrl' in console. <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="fragment" content="!">
<base href="/">
</head>
<body ng-app="Angular">
<h1>Title</h1>
<ng-view class="app-content"></ng-view>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.min.js"></script>
<script>
angular.module('g.modal', [
'ngRoute',
]).controller('modalCtrl', [function() {
console.log('in modalCtrl');
}]);
angular.module('Angular', [
'ngRoute',
'g.modal',
]).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/', {templateUrl: '', controller: 'modalCtrl'});
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}]);
</script>
</body>
</html> |
In what circumstances is an empty string a valid |
@petebacondarwin, yes it's due to programming bug - something that costed me more than 2 days to figure out. The same symptom occurs if the templateUrl points to a non-existent template. |
Not sure if throwing errors would be BC at this stage? But I guess if we know it would always infinitely loop then it doesn't matter. The question is whether that is always the case? |
I guess you could have a setup where an interceptor changes the url into something else? In that case an empty string would be okay. |
AngularJS 1.4.0
Firefox 38.0.5 (Privacy Mode)
When setting up routing (ngRoute) in the module's .config(), using an empty string as the templateUrl will force the browser into either an infinite loop or a crash.
$routeProvider.when('/custom/route' {templateUrl:'', controller:'', controllerAs:''})
will crash. Replacing templateUrl with a string (even a non-existing file) does not cause the crash.The text was updated successfully, but these errors were encountered: