-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Angular 1.5.0's transclude lazy compilation is a breaking change #14343
Comments
I agree that this is unexpected behavior, but the "bug" can also be produced in 1.4.x by using a templateUrl instead of template. In that case, the transcluded content will also be compiled async, and the wizard won't be set in the link function. In general, it's safer to notify the parent when the child is actually available: http://plnkr.co/edit/bzliiP4lIWFm5auuAj6o?p=preview Basically, the parent should never assume that a child is available when the parent's link fn is called. |
@Narretz Yeah, I can agree with either changing my implementation or having Angular be more backwards compatible. On that note of Edit: Thanks for the example solution. I didn't know you can do that... it's interesting. But that solution seems kind of brittle because of the |
@moneytree-doug Less brittle actually. Not only will you appropriately notify the parent when you're actually available, but you'll also get errors in your console if the directive is used outside of its expected parent->child structure. |
"lazy transclusion" was originally pitched as a performance improvement. Most of the defense, that I see for the feature is about consistency with templateUrl when it doesn't have the template loaded. To me this seems like a slow down in performance. In the past, the compile happened from parent to child, and then link from child to parent before any digest cycles were run on the parent. Now, if it decides to go lazy, it will compile, link, and digest the parent before moving on to the child. I haven't benchmarked it, but this sounds a lot slower. Also, in my production environment, I always have my templates loaded. I don't want template calls slowing down my page. I'm sure there are some good use cases for loading html later, but I feel that in many situations, html templates are best loaded with the js module. So the argument of consistency is mute for people that pre-load templates. Does an angular member have any proof that this was a helpful change for performance? |
@mattslocum Well said. |
I don't quite agree 😃 My thoughts:
Just to be clear, what @Narretz said about
That is not exactly true. (Note that we are talking about transcluding directives.) Basically, it depends on when the transcluding directive decided to call the
The only difference WRT to eager vs lazy compilation, is when the compiling happens:
Nothing changes wrt to the work that is done, the only change is wrt to when this work is done and how it is being distributed throughout the lifecycle of the app. See below for more details on the timing of the various phases before and after.
The performance gains (both in terms of startup time and memory used) vary depending on the size of the app and directives used. The obvious benefit is that you don't have to compile subtrees that you aren't going to use (e.g. the contents of an Actually, there is one case where performance would be objectively worst: When actually fetching the HTML from the server at runtime. But this is not recommended anyway and it is still possible to fetch them eagerly and cache them anyway. Here are a few demos to show the differences in the order of operations (wrt digests) with eager and lazy compilation Example 1 -
|
Do you want to request a feature or report a bug?
Bug.
Correct me if I am wrong, but I think this is related to the "
Performance Improvements
" from the CHANGELOG for1.5.0-beta.1 dense-dispersion (2015-09-29)
What is the current behavior?
Angular 1.4.7: http://plnkr.co/edit/7ZPBgqpPnbXF57rvezPf?p=preview
In Angular 1.4.7, you'll see that a service is available because the transcluded element is compiled first therefore it is available later. Please refer to the
console.log
.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).
Angular 1.5.0: http://plnkr.co/edit/5Nh7EHLINDjMlaQ8dZbl?p=preview
In Angular 1.5.0, you'll see that a service is NOT available because the transcluded directive is lazily compiled. Please refer to the
console.log
.What is the expected behavior?
The behaviour in Angular 1.4.7.
What is the motivation / use case for changing the behavior?
I want the child directive with transclude to populate a service with data for a parent directive to access in the link function.
Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
It stopped working in the Angular 1.5.X series, but it previously worked in the 1.4.X series.
Other information (e.g. stacktraces, related issues, suggestions how to fix)
The text was updated successfully, but these errors were encountered: