Skip to content
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

Nested ContentChildren have wrong content in Angular #14402

Closed
Jakob-em opened this issue Mar 30, 2021 · 2 comments
Closed

Nested ContentChildren have wrong content in Angular #14402

Jakob-em opened this issue Mar 30, 2021 · 2 comments

Comments

@Jakob-em
Copy link
Contributor

Describe the bug
When angular components/directives are nested and use the ContentChildren decorator the inner component/directive
has a reference to itself as part of contentChildren.

When the same code snippet is used in a new angular application the inner component/directive doesn't have a reference to itself. (as it would be expected)

To Reproduce
A reproduction can be found here

  1. Open DevTools
  2. Go to Basics / Component / With ContentChildren / Default
  3. See that children: [ChildDirective] is logged

Expected behavior
The ChildDirective should not have any children and therefore log children: []

Code snippets

@Directive({
  selector: '[storybook-child]',
})
class ChildDirective implements AfterContentInit {
  @ContentChildren(ChildDirective)
  children: QueryList<ChildDirective>;

  ngAfterContentInit(): void {
    this.children.changes.subscribe((c) => console.log(c.toArray()));
    console.log('children:', this.children.toArray());
  }
}

@Component({
  selector: 'storybook-with-content-children',
  template: ` <div></div>`,
})
class ComponentWithContentChildren implements AfterContentInit {
  @ContentChildren(ChildDirective)
  children: QueryList<ChildDirective>;

  ngAfterContentInit(): void {
    console.log('parent:', this.children.toArray());
  }
}

System
System:
OS: macOS 11.2.3
CPU: (8) arm64 Apple M1
Binaries:
Node: 15.9.0 - ~/.nvm/versions/node/v15.9.0/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v15.9.0/bin/yarn
npm: 7.5.3 - ~/.nvm/versions/node/v15.9.0/bin/npm
Browsers:
Chrome: 89.0.4389.114
Safari: 14.0.3
npmPackages:
@storybook/eslint-config-storybook: ^2.4.0 => 2.4.0
@storybook/linter-config: ^2.5.0 => 2.5.0
@storybook/semver: ^7.3.2 => 7.3.2

Additional context
I would be happy to help out with this issue if somebody could give me any hints where to start.

@github-actions
Copy link
Contributor

Automention: Hey @Marklb @MaximSagan @kroeder, you've been tagged! Can you give a hand here?

@Jakob-em
Copy link
Contributor Author

After digging a bit more I found out that this was the default angular behaviour before Ivy: angular/angular#10098 (comment)

And because storybook is not using Ivy the behaviour is different than in a real angular app.
So it should be fixed with #13768

@Jakob-em Jakob-em closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants