-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngTransclude): correctly support fallback content #14775
Conversation
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
9b4db0c
to
facad29
Compare
// 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); |
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.
Should probably check to see if any contents exist prior to calling $compile
.
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.
This is not semantically necessary as the compile bails out if there is nothing to compile.
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.
although it could improve performance slightly
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(); |
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.
So, this is essentially fixing a leak, right ? Cool
I moved the tests into their own specs. |
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
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