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

6.2.0-alpha.14 Angular props are reinitialized by StorybookWrapperComponent #13645

Closed
vprothais opened this issue Jan 15, 2021 · 2 comments
Closed
Labels

Comments

@vprothais
Copy link

Describe the bug
When we have a component with a prop, not declared as an input, it is reinitialized to its default value even if the ngOnInit set a value.
In the example below I assign an array to the prop. I should have the "Hello" text displayed, but I have an empty view for the component.

To Reproduce
Create a simple component with a prop assigned in the ngOnInit :

import {Component, OnInit} from "@angular/core";

@Component({
    selector: "test",
    template:  `<p *ngFor="let entry of prop">{{entry.value}}</p>`
})
export class TestComponent implements OnInit {
    private prop = [];

    public ngOnInit() {
        this.prop = [{value: "Hello"}];
    }
}

Expected behavior
I should have in my canvas a p tag with "Hello" as innerText.

System
System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
CPU: (2) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Binaries:
Node: 12.18.4 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.125
Firefox: 78.0.2
npmPackages:
@storybook/addon-actions: ^6.2.0-alpha.14 => 6.2.0-alpha.14
@storybook/addon-essentials: ^6.2.0-alpha.14 => 6.2.0-alpha.14
@storybook/addon-links: ^6.2.0-alpha.14 => 6.2.0-alpha.14
@storybook/addons: ^6.2.0-alpha.14 => 6.2.0-alpha.14
@storybook/angular: ^6.2.0-alpha.14 => 6.2.0-alpha.14
@storybook/theming: ^6.2.0-alpha.14 => 6.2.0-alpha.14

Can also be reproduced in alpha.15.

Additional context
This issue is probably linked to this PR : #13507

The prop is reset by the ngAfterViewInit call of StorybookWrapperComponent.
On the following lines :

initialOtherProps.forEach(function (p) {
  _this.storyComponentElementRef[p] = initialProps[p];
});

initialProps contains an empty array for prop in my example.

ping @ThibaudAV

@ThibaudAV
Copy link
Contributor

There are several issues more or less related to the same problem (ex: #11613, #12946)

If we change this it causes braking changes.
Which IMHO would be good things. And would "force" users to interact only with Angular Input/Output.
And we could add something like this overrideComponentProps which would overload component props as before (even if it's bad to do it)

@valentinpalkovic
Copy link
Contributor

valentinpalkovic commented May 10, 2023

Not reproducible in Storybook 7 / Angular 15 anymore. Therefore, I am closing this. Please reopen the issue if you still encounter it. Please provide a Stackblitz reproduction in this case (https://storybook.new)

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

No branches or pull requests

3 participants