-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: array or object with JSX elements in context causes Storybook to hang indefinitely #19575
Comments
I am also running into this issue, passing an array of JSX elements as a prop to a component in Storybook. The following works well in a fresh Create React App, but hangs in Storybook, locking up my browser when I try to click any of the buttons. One of my projects is not able to update Storybook because of #17413, and this component works without issue in that project (Storybook 6.3.12). The only workaround I have found is sending the array of JSX as This issue looks like it also may be related to #17877. My Component: export default function Slideshow({ pages, page }) {
return <div>{pages[page]}</div>;
} And in my Storybook file: const Template = (args) => {
const [page, setPage] = useState(0);
return (
<Slideshow
{...args}
page={page}
pages={[
<button onClick={() => setPage(1)}>Go to page 2</button>,
<button onClick={() => setPage(2)}>Go to Page 3</button>,
<div>Page Three</div>,
]}
/>
);
}; System
|
@alicnik Thanks for the comment. Adding this does indeed solve this on my end. |
@alicnik thanks, added to global parameters in preview.js and it worked
|
Setting the By I still don't understand what's the difference between |
The explanation for this issue is that See algolia/react-element-to-jsx-string#681 We already filter out pure elements and arrays that contain elements (#17482). It seems we still have an issue with objects that contain elements. It sounds like maybe pinning the version of |
The element doesn't have to be in a context to reproduce. See e.g. duplicate #17720. |
Can folks who are seeing this try pinning the version of npm: "overrides": {
"react-element-to-jsx-string": "14.3.2"
} yarn: "resolutions": {
"react-element-to-jsx-string": "14.3.2"
} |
@tmeasday Thanks, that seems to have fixed the issue. |
@tmeasday this fixed it for me as well! |
@shilman shall we pin the version then? |
Hmm, yeah I am not seeing it in your example either. Can someone provide a working reproduction in 7.x? |
This also affects v8.1.0 |
@jleider can you (a) provide a reproduction if possible? (b) confirm if pinning the version resolves it? |
a) Its in a private repo and I don't have a simple reproduction case at this time. Although, I can see if we can make one for you. b) Yes, the pinning of the version resolves it. We had previously had it pinned and I was hoping that the issue was resolved when upgrading storybook from v7 to v8 but the issue is still present. |
Hi @tmeasday, I've managed to get a minimal working reproduction for the bug in Storybook 8, which you can see here: https://github.com/SuttonKyle/storybook-bug-repro In this case, the response is very slow the first time you change the |
Thank you for the reproduction @SuttonKyle. Can confirm both the bug and that pinning the version fixes it. @shilman I think we should change the version of |
@tmeasday I'm OK with that. Perhaps we can handle it properly later this year. |
Btw my project is using Storybook 6.5.9 which uses Is there a plan to patch this problem in Storybook v6 as well? |
Describe the bug
Providing an array of JSX elements, or an object containing JSX elements, as the
value
in a context provider causes Storybook to hang indefinitely. The UI may load but it cannot be interacted with once you click on the story with the context issue.This only happens with arrays/objects. Passing a JSX element as the
value
in context works fine.Example code of adding context in a story (with an array):
This also happens if the context is placed in decorators, e.g. (with an object):
One solution is to use the
storybook-react-context
add-on, however if there is something I have missed that is causing this issue I would welcome guidance on solving it without using an add-on.To Reproduce
System
Additional context
No response
The text was updated successfully, but these errors were encountered: