-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Addons: error Converting circular structure to JSON for Angular mat-table #16855
Comments
Args must be JSON-serializable (ish). To use complex structures, we have a |
@shilman could you please provide an example of mapping for my case? |
Untested: const dataSource = new MatTableDataSource(ELEMENT_DATA);
export default {
title: 'foo',
argTypes: {
testDataSource: {
mapping: { Default: dataSource }
}
}
}
export const Primary = Template.bind({});
Primary.args = {
testDataSource: 'Default'
} |
@shilman it helped, thank you, should I close the issue or any fix is expected (e.g. provide a message in addon about required mapping instead of story crash?) |
Helpful error message is a great idea. I'll follow up, thanks!! 🙏 |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
The @shilman pattern also works for Angular Reactive Forms |
Edit/
|
After having a chat internally, we figured out a workaround: https://stackblitz.com/edit/github-3znyoe-aebjsf?file=src%2Fstories%2Finput.component.stories.ts So instead of using the native mapping functionality of Storybook, you can use the ...
const mapping = {...};
const meta: Meta<InputField> = {
...
argTypes: {
control: {
options: ['Marty', 'Jennifer', 'Doc'],
control: {
type: 'select',
},
},
},
render: ({ control }: {control: any}) => {
const controlKey = control as keyof typeof mapping
return ({
props: {
control: mapping[controlKey]?.(),
},
})
},
};
... The main issue is that the To circumvent this issue, we want to pass a new instance every time the ...
render: ({ control }: {control: any}) => {
const controlKey = control as keyof typeof mapping
return ({
props: {
control: mapping[controlKey]?.(),
},
})
}, So the Let's take a look at the const mapping = {
Marty: () =>
new FormControl({ value: 'Marty McFly', disabled: false }, [
Validators.required,
]),
Jennifer: () =>
new FormControl({ value: 'Jennifer Parker', disabled: true }, [
Validators.required,
]),
Doc: () =>
new FormControl({ value: 'Doc Brown', disabled: false }, [
Validators.required,
]),
}; This object maps the control: mapping[controlKey]?.(), If I hope all of this makes sense and the workaround works sufficiently for you. |
Because the |
I tried this solution, but i think the issue does occur when trying to provision a FormGroup into a Story.. |
@work933k could you provide a reproduction? |
@storybook/[email protected] Errors on JSON.stringify:
|
@valentinpalkovic Why did this issue get closed? |
Couldn’t you use the same mapping workaround with the FormGroup as well, like shown with the FormControl? |
I tried, but i wasn't able to get it to work. I'll try it again. |
@valentinpalkovic I modified the provided Stackblitz: https://stackblitz.com/edit/github-3znyoe-6cjwh3?file=src/stories/input.component.stories.ts In the browser-console you should see errors about the formgroup. |
@work933k Thank you for the reproduction. Indeed, I could reproduce it for |
@valentinpalkovic I'm not too sure if the FormGroup issue is exactly the same as with MatTable. |
It is not clear what the complete workaround/fix for this is.
Workaround 2:
I've tested using the code from your https://github.com/Tatsianacs/storybook--bug demo, Angular & Material v14, Storybook v7. Here is a Stackblitz link: https://stackblitz.com/edit/angular-material-storybook. Could you or anyone please share more details about how you solved the issue? Thank you 🙏 |
Does this help: #15602 (comment)? |
Is this solution compatible with Storybook version 6.5? |
Hi ! I had this annoying issue as well with my Form stories... But I found a trick which maintains a fully fonctionnal FormGroup (with valueChanges working properly) in stories 🎉 Storybook tries to stringify any args you pass to a component. const MY_FORM = new FormGroup({
a: new FormControl('A'),
b: new FormControl('B'),
})
// Tell JSON.stringify to serialize it as null > No circular dependency
// You could return any value you like though
MY_FORM['toJSON'] = () => null;
export const FormStory: Story = {
name: 'FormStory',
args: {
form: MY_FORM
},
}; Note that this would work for ANY object that circles when stringified |
Describe the bug
When MatTableDataSource is used in addons arguments, the story is broken
To Reproduce
=> story load is broken
Repo:
https://github.com/Tatsianacs/storybook--bug
System
Environment Info:
System:
OS: Windows Server 2016 10.0.14393
CPU: (6) x64 Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 3.1.1 - ~\node_modules.bin\yarn.CMD
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 95.0.4638.69
npmPackages:
@storybook/addon-actions: ^6.4.2 => 6.4.2
@storybook/addon-essentials: ^6.4.2 => 6.4.2
@storybook/addon-links: ^6.4.2 => 6.4.2
@storybook/angular: ^6.4.2 => 6.4.2
@storybook/builder-webpack5: ^6.4.2 => 6.4.2
@storybook/manager-webpack5: ^6.4.2 => 6.4.2
Additional context
It doesn't work at least for Controls and accessibility addons, it worked for Knobs and nothing is broken if addon is disabled OR dataSource is removed from the table (workaround:
The text was updated successfully, but these errors were encountered: