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

fix(ngTransclude): correctly support fallback content #14775

Closed
wants to merge 1 commit into from

Conversation

dcherman
Copy link
Contributor

If the transclude function did not return content, then the transcluded
scope that was created needs to be cleaned up in order to avoid a slight
amount of unnecessary overhead since the additional scope is no longer
needed.

If the transcluded content did return content, the the fallback content
should never have been linked in the first place as it was intended to be
immediately removed.

Fixes #14768
Fixes #14765

If the transclude function did not return content, then the transcluded
scope that was created needs to be cleaned up in order to avoid a slight
amount of unnecessary overhead since the additional scope is no longer
needed.

If the transcluded content did return content, the the fallback content
should never have been linked in the first place as it was intended to be
immediately removed.

Fixes angular#14768
Fixes angular#14765
@dcherman dcherman changed the title fix(ngTransclude): correct support fallback content fix(ngTransclude): correctly support fallback content Jun 14, 2016
// Since this is the fallback content rather than the transcluded content,
// we compile against the scope we were linked against rather than the transcluded
// scope since this is the directive's own content
$compile($element.contents())($scope);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should probably check to see if any contents exist prior to calling $compile.

Copy link
Member

Choose a reason for hiding this comment

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

This is not semantically necessary as the compile bails out if there is nothing to compile.

Copy link
Member

Choose a reason for hiding this comment

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

although it could improve performance slightly

@Narretz
Copy link
Contributor

Narretz commented Jun 15, 2016

Could you please create new tests for this instead of modifying the old ones?

$element.append(clone);
// There is nothing linked against the transcluded scope since no content was available,
// so it should be safe to clean up the generated scope.
transcludedScope.$destroy();
Copy link
Member

Choose a reason for hiding this comment

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

So, this is essentially fixing a leak, right ? Cool

@petebacondarwin
Copy link
Member

I moved the tests into their own specs.

petebacondarwin pushed a commit that referenced this pull request Jun 17, 2016
If the instance of the directive does provide transcluded content, then the fallback
content should not be compiled and linked as it will never be used.

If the instance of the directive does not provide transcluded content, then the
transcluded scope that was created for this non-existent content is never used,
so it should be destroy in order to clean up unwanted memory use and digests.

Fixes #14768
Fixes #14765
Closes #14775
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