storybook: Component in object prop freezes the story
Describe the bug Component in object prop freezes the story. If I provide an object prop like this:
bottomLine={{
icon: <IconAgenda />,
text: args.bottomLineText,
}}
The component is not rendered or renders really slow. Also the actions don’t work. The following component renders as expected:
// works
<Button
topLine={args.topLineText}
/>
// does not render correctly (action add-on doesn't work)
<Button
topLine={args.topLineText}
bottomLine={{
icon: <Component />,
text: args.bottomLineText,
}}
/>
To Reproduce
Clone the repro -> npm install -> npm run storybook -> change text in action of DoesNotWorkButton story
System
Environment Info:
System:
OS: macOS 11.6.4
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Binaries:
Node: 16.2.0 - ~/.nvm/versions/node/v16.2.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 7.13.0 - ~/.nvm/versions/node/v16.2.0/bin/npm
Browsers:
Chrome: 99.0.4844.51
Firefox: 98.0.1
Safari: 14.1.2
npmPackages:
@storybook/addon-actions: ^6.4.19 => 6.4.19
@storybook/addon-essentials: ^6.4.19 => 6.4.19
@storybook/addon-interactions: ^6.4.19 => 6.4.19
@storybook/addon-links: ^6.4.19 => 6.4.19
@storybook/addon-toolbars: ^6.4.19 => 6.4.19
@storybook/builder-webpack5: ^6.4.19 => 6.4.19
@storybook/manager-webpack5: ^6.4.19 => 6.4.19
@storybook/node-logger: ^6.4.19 => 6.4.19
@storybook/preset-create-react-app: ^4.0.1 => 4.0.1
@storybook/react: ^6.4.19 => 6.4.19
@storybook/testing-library: ^0.0.9 => 0.0.9
Additional context
This pattern used to work in previous versions of Storybook. When '@storybook/addon-docs' is not used, everything works as expected.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 24
- Comments: 15 (3 by maintainers)
I noticed that the JSX rendering code sometimes gets stuck in an infinite recursion loop.
If you add this to preview.jsx does the problem go away?
If you’re using 7.0 you can disable per story like so:
For me, rendering the component outside the story helped:
Hangs:
Works:
@matthew-dean removing the story args like this fixed the issue
But this is really undesirable behaviour 😢
Note, we’re also seeing huge story freezes. Up to 40 seconds for a single story.
For us, it wasn’t related to component args. Changing from this:
to this:
…dropped the delay / render time from 40 seconds to zero!!
I encountered the same problem with having array of react elements in props and was trying to debug it. I didn’t find much but I saw that the infinite (or just extremely long running) loop begins from
renderJsxfunction fromjsxDecorator.tsxcalling thereactElementToJSXString.I have a hunch that the JSX which is being consumed by this function, is already rendered in the storybook, so it already has the
_ownerfield set to a Fiber node. And then the recursive logic that serializes the props, starts consuming the Fiber node which is a cyclic object, falling into infinite/expensive loop.Proably it’s the
react-element-to-jsx-stringpackage that could be blamed for that but I believe it would be better if Storybook could mitigate the issue instead on its side (probably by somehow transforming the props passed toreactElementToJSXString? Cloning them but with fiber nodes removed? cloning them but passing react elements throughReact.cloneElement?)– EDIT I just realized this issue is dead and it is being continued here: https://github.com/storybookjs/storybook/issues/19575