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

Breaks Angular components using arrays #18198

Closed
Fydon opened this issue May 11, 2022 · 8 comments
Closed

Breaks Angular components using arrays #18198

Fydon opened this issue May 11, 2022 · 8 comments

Comments

@Fydon
Copy link

Fydon commented May 11, 2022

Describe the bug
Storybook replaces array values with a string containing the array as text. A value initialised to an empty array in the component, i.e. [], is replaced with the string "[]" by Storybook. A value initialised to ['foo', 'bar'] is changed to "['foo', 'bar']".

To Reproduce
I've taken an example from Angular Material and added Storybook. DefaultWithErrors is a story with the default setup, which displays correctly but has errors in the browser console. Better is a story that fixes the errors by duplicating the initial state of the component in the story, but this breaks the Control for dataSource. The Stackblitz of this may require running turbo run storybook, if it the attempt on load fails.

System
npx sb info

  System:
    OS: Windows 10 10.0.19043
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.6.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.39)    
  npmPackages:
    @storybook/addon-actions: 6.4.22 => 6.4.22
    @storybook/addon-essentials: 6.4.22 => 6.4.22
    @storybook/addon-interactions: 6.4.22 => 6.4.22
    @storybook/addon-links: 6.4.22 => 6.4.22
    @storybook/angular: 6.4.22 => 6.4.22
    @storybook/builder-webpack5: 6.4.22 => 6.4.22
    @storybook/manager-webpack5: 6.4.22 => 6.4.22
    @storybook/testing-library: 0.0.11 => 0.0.11
@Fydon Fydon changed the title Breaks components using arrays Breaks Angular components using arrays May 11, 2022
@Fydon
Copy link
Author

Fydon commented May 16, 2022

I have found a complete workaround for this simple example, which I've pushed to the repository. However this workaround does not work for more complex components. I also added stories showing that disabling controls or manually defining the type still results in error in the browser console, which result in errors for more complex components.

@szykov
Copy link

szykov commented May 22, 2022

I confirm that too:
Cannot find a differ supporting object '[1, 2, 3]' of type 'string'. NgFor only supports binding to Iterables such as Arrays.

I have updated from 6.4.22 to 6.5.3

In the code I have a property like this:
public foo: number[] = [1, 2, 3];

@Squixx
Copy link

Squixx commented Aug 15, 2022

This is even worse, and also happens in storybook 6.4.22

When properties are not explicitly set in your storyfiles
e.g.

fromModule.args = {
  showOverview$: new BehaviorSubject<boolean>(true),
  destroy$: new Subject<boolean>(),
};

storybook will just replace object files with a string value.

[] => "[]"
new BehaviorSubject(true) => "new BehaviorSubject(true),"
new Subject() => "new Subject()"

@Squixx
Copy link

Squixx commented Aug 15, 2022

should prob refer to #17004

@khepf
Copy link

khepf commented Aug 22, 2022

any updates on this issue?

@Fydon
Copy link
Author

Fydon commented Jan 26, 2023

In theory #19935 has probably fixed this, but I can't get Storybook 7 to work. It may be because I use @angular-builders/custom-webpack as my builder.

@Fydon
Copy link
Author

Fydon commented May 24, 2023

Since updating to Storybook 7.0 I'm no longer experiencing this problem. Thank you.

@Fydon Fydon closed this as completed May 24, 2023
@paddotk
Copy link

paddotk commented Dec 7, 2023

I'm on Storybook 7.5.2 and am experiencing the same issue. It keeps giving me the error Error: Missing expected ] at column 9 in [[object Object]]

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

5 participants