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

Storybook preview hooks can only be called inside decorators and story functions. #38

Closed
clayrisser opened this issue Nov 18, 2021 · 10 comments
Labels

Comments

@clayrisser
Copy link

I am getting the following error when using this plugin.

Storybook preview hooks can only be called inside decorators and story functions.

I am using . . .

{
    "@storybook/react": "^6.3.12",
    "@react-theming/storybook-addon": "^1.1.3"
}
@austinmccalley
Copy link

austinmccalley commented Dec 28, 2021

I am also having this error. I am using...

{
    "@storybook/react": "^6.4.9",
    "@react-theming/storybook-addon": "^1.1.3"
}

I am using it with MUIv5 and I am defining my preview.js as follows

// preview.js
import { theme as OverallTheme } from '../src/theme';

import { createTheme } from '@mui/material/styles';
import { ThemeProvider } from '@mui/material';
import { withThemes } from '@react-theming/storybook-addon';

const providerFn = ({ theme, children }) => {
  const muTheme = createTheme(theme);
  return <ThemeProvider theme={muTheme}>{children}</ThemeProvider>;
};

export const decorators = [withThemes(null, [OverallTheme], { providerFn })];
export const parameters = { docs: { source: { type: 'code' } } };

@Myzel394
Copy link

Another one facing the same issue, any progress on this?
@austinmccalley and @clayrisser did you find a solution?

@austinmccalley
Copy link

Another one facing the same issue, any progress on this?

@austinmccalley and @clayrisser did you find a solution?

No solution yet ☹️

@totszwai
Copy link

totszwai commented Mar 2, 2022

Same issue... what's more is that, there is no proper export from the addon... Is this thing still being maintained??
image

@majoncas-ue
Copy link

The plugin looks so nice but I cannot use it because of this issue. Any workaround that would help?

@oriooctopus
Copy link

@usulpro we could very much use your assistance

@usulpro
Copy link
Member

usulpro commented Apr 16, 2022

@totszwai This addon is being maintained. Not sure TS definition is related to this issue, but anyway PRs with fixes are always welcomed

@Mattias-Martens
Copy link

Same problem here. From a preliminary look it seems that context is not being passed in like it is in other decorators. Anything that relies on storybook context, like useArgs(), triggers the bug.

@Mattias-Martens
Copy link

could be related to this issue——storybookjs/storybook#12006

basically the decorator renders it like this:

<>{providerFn({ theme, children })}</>

making that internal react JSX the “root” of the story as far as Storybook is concerned.
Storybook doesn’t allow the use of any of its cool toys less than one level deep into a component tree. so this is what breaks it.

@stale
Copy link

stale bot commented Nov 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 25, 2022
@stale stale bot closed this as completed Dec 11, 2022
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

8 participants