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

fix(ngInclude): do not compile template if original scope is destroyed #13543

Closed
wants to merge 1 commit into from
Closed

fix(ngInclude): do not compile template if original scope is destroyed #13543

wants to merge 1 commit into from

Conversation

zgmnkv
Copy link
Contributor

@zgmnkv zgmnkv commented Dec 15, 2015

With slow internet connection scope may be destroyed before template is loaded.
Previously in this case ngInclude compiled template that leaded to memory leaks
and errors in some cases.

Closes #13515

With slow internet connection scope may be destroyed before template is loaded.
Previously in this case ngInclude compiled template that leaded to memory leaks
and errors in some cases.

Closes #13515
@@ -253,6 +255,8 @@ var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate',
currentScope.$emit('$includeContentLoaded', src);
scope.$eval(onloadExp);
}, function() {
if (scope.$$destroyed) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this code path is not tested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is not tested. I think it is quite internal logic, the aim is not to perform unnecessary cleanup. By the time when scope is destroyed element should be also removed, so no need to call cleanupLastIncludeContent, and $emit on destroyed scope is useless. There are no changes visible from outside.
If test is required, I can try to spy on scope and element and check that scope.$destroy, scope.$emit and element.remove are not being called.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think there is a need for a lot of spying, you can have another test just like the one you have with these differences

  • same template but without the ng-if
  • creating a new scope from $rootScope, linking the template to it
  • registering a listener
  • destroying the scope
  • doing the http flush

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean listener to $includeContentError event? What should I expect in this case? this event will not fire anyway, because scope removes all listeners on destroy.
Or do you mean that we shouldn't make any expectations, just check that this code works?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are right, and nothing else is needed.

@lgalfaso
Copy link
Contributor

otherwise, LGTM

@zgmnkv
Copy link
Contributor Author

zgmnkv commented Dec 18, 2015

So would it be merged? As far as I understand we agreed that no more test is needed.
CI seems to have failed due to some internal error
15 Dec 10:30:41 - Response: {"error": "Too many active org tunnels: 30 >= 30"}.

@lgalfaso
Copy link
Contributor

Sorry for the delay, this landed into master

@lgalfaso lgalfaso closed this Dec 18, 2015
lgalfaso pushed a commit that referenced this pull request Dec 18, 2015
With slow internet connection scope may be destroyed before template is loaded.
Previously in this case ngInclude compiled template that leaded to memory leaks
and errors in some cases.

Closes: #13515
Closes: #13543
@zgmnkv
Copy link
Contributor Author

zgmnkv commented Dec 18, 2015

Thanks! Is it possible to merge it to stable branches 1.2, 1.3, 1.4 ? Should I create PRs to relevant branches?

@lgalfaso
Copy link
Contributor

I would be ok with 1.4 (even when I would like to avoid this as we are already in the final stages for a 1.5 release). All the other branches are only receiving security fixes or big regressions fixes.

@petebacondarwin WDYT?

gkalpak pushed a commit that referenced this pull request Dec 21, 2015
With slow internet connection scope may be destroyed before template is loaded.
Previously in this case ngInclude compiled template that leaded to memory leaks
and errors in some cases.

Closes: #13515
Closes: #13543
@gkalpak
Copy link
Member

gkalpak commented Dec 21, 2015

Backported to v1.4.x as 9590bcf (since @petebacondarwin said we should also backport "any bug fixes that do not change public API or make breaking change").

@zgmnkv
Copy link
Contributor Author

zgmnkv commented Dec 22, 2015

Thanks guys

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants