Skip to content

fix(upgrade): fix empty transclusion content with AngularJS@>=1.5.8 #22167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Feb 12, 2018

PR Checklist

PR Type

[x] Bugfix
[x] Build related changes

What is the current behavior?

The function provided by ngUpgrade as parentBoundTranscludeFn when upgrading a component with transclusion, will break in AngularJS v1.5.8+ if no transclusion content is provided. The reason is that AngularJS will try to destroy the transclusion scope (which would not be needed any more). But since the transcluded content comes from Angular, not AngularJS, there is no transclusion scope to destroy.

Issue Number: #22175

What is the new behavior?

Transclusion works even if no content is provided with AngularJS v1.5.8+. ngUpgrade provides a dummy scope object with a no-op $destroy() method to avoid throwing an error.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Fixes #22175.
This commit also upgrades AngularJS to the latest stable version.

@gkalpak gkalpak added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer comp: upgrade/dynamic freq1: low target: patch This PR is targeted for the next patch release labels Feb 12, 2018
@mary-poppins
Copy link

You can preview 5e5cda5 at https://pr22167-5e5cda5.ngbuilds.io/.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

WOT NO TEST?

@gkalpak gkalpak added state: WIP and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 12, 2018
@gkalpak
Copy link
Member Author

gkalpak commented Feb 12, 2018

The tests we had were sufficient (as long as we use an AngularJS version >=1.5.8). Upgrading AngularJS was my test 😛
(But now some other tests fail. Fixing...)

@gkalpak gkalpak force-pushed the fix-upgrade-empty-transclusion branch from 5e5cda5 to 2e8c09e Compare February 12, 2018 22:26
@mary-poppins
Copy link

You can preview 2e8c09e at https://pr22167-2e8c09e.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-upgrade-empty-transclusion branch 3 times, most recently from a93c31f to de6bbdb Compare February 15, 2018 18:11
@gkalpak gkalpak closed this Feb 15, 2018
@gkalpak gkalpak reopened this Feb 15, 2018
@gkalpak
Copy link
Member Author

gkalpak commented Feb 15, 2018

I managed to get karma to run tests for multiple AngularJS versions (currently 1.5.x and 1.6.x) and then I realized I have no idea what to do with bazel 😞

@petebacondarwin, feel free to PTAL anyway 😁
(The first 4 commits are new. You have already reviewed the 5th one.)

@gkalpak gkalpak force-pushed the fix-upgrade-empty-transclusion branch 2 times, most recently from 6a6738b to 6f4cecb Compare February 15, 2018 19:04
@mary-poppins
Copy link

You can preview 6f4cecb at https://pr22167-6f4cecb.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-upgrade-empty-transclusion branch from 6f4cecb to 3cc204d Compare February 16, 2018 08:03
@mary-poppins
Copy link

You can preview 3cc204d at https://pr22167-3cc204d.ngbuilds.io/.

@@ -123,8 +123,14 @@ export class UpgradeHelper {
const transclude = this.directive.transclude;
const contentChildNodes = this.extractChildNodes();
let $template = contentChildNodes;
let attachChildrenFn: angular.ILinkFn|undefined = (scope, cloneAttach) =>
cloneAttach !($template, scope);
let attachChildrenFn: angular.ILinkFn = (scope, cloneAttachFn) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It still can be undefined, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see how 😕 (TypeScript agrees 😃)
It is assigned a (defined) value and is never re-assigned. It should actually be const 😁

@gkalpak gkalpak force-pushed the fix-upgrade-empty-transclusion branch from 3cc204d to 36f4f4f Compare February 16, 2018 08:20
This was referenced Mar 15, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes freq1: low target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgraded components with ng-transclude throw an error if there is no content
8 participants