-
-
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
Source: Dynamic snippets includes decorators #12022
Comments
Unrelated, but this is probably not a good idea:
|
I'm having the exact same issue. |
To add some info, if I use my decorator in the following format, it works: decorators: [
story => <div style={{height: "50vh"}}>{story()}</div>
] Hope this might help in debugging 🙂 |
Actually that seems to work... but it still wraps the story in the provided decorator, isn't it meant to only show the story |
Same here. I see this: <[object Object]
value={{
authenticated: {
id: 'test'
},
setUser: () => {},
signUp: function noRefCheck() {},
user: {
id: 'test'
}
}}
>
<ApolloProvider client={[object Object]}>
<MyComponent
...
/>
</ApolloProvider>
</[object Object]> When all I want to see is |
As a workaround you can set the |
@shilman doesn't work |
@Quadriphobs1 do you have a repro i can look at? |
Where can this be set? |
Something like:
|
@shilman Using that produces no code available actually when the decorator is still provided
|
When setting parameters as above "Show Code" window returns |
I'm still facing this issue, any workaround available |
Me too. What is the reason for that problem? Maybe a tsconfig or webpack problem? |
It's a bit hacky, but I got around this by adding a decorator to wrap the story with known strings. Then I used
|
Hi 👋 , I fixed this by replacing:
by: {Story()} |
I got this to work but only globally by adding a decorator to the .storybook/preview.js file. Mine looks like this. I needed to include global styles available for all components but was running into the same issue. I get the same "No Display Name" issue when trying to add to decorators at the individual story level. Using Storybook version 6.1.4.
|
When I use Thanks for all your support on storybook @shilman! UPDATE By configuring module.exports = {
addons: [
...
{
name: '@storybook/addon-storysource',
options: { loaderOptions: { injectDecorator: false } },
},
],
}; |
We want to address this in 6.3. If you want to contribute to Storybook, we'll prioritize PR review for any fixes here. And if you'd like any help getting started, please jump into the #support channel on our Discord: https://discord.gg/storybook |
I found a work around using transformSource that seems to solve the issue for stories using components with render props and doesn't require using a known string to search for in your decorator. The formatting isn't 100% perfect but it's usable.
This is assuming your story templates are written in the following manner:
|
Storybook's printing of elements to jsx in dynamic mode has a couple of quirks causing these problems: Function children are tricky because the AST stops when it reaches one. There are no more children to traverse unless it is called and its return value parsed, which may not be desirable in all cases. I propose the following solution: (2) Regarding function children, const ContextDecorator = (story) => <Consumer>{dynamic(ctx => story(ctx))}</Consumer>
// ...
const dynamic = (fn) => Object.assign((...args) => fn(...args), { sourceType: 'dynamic' }) Other modes could also be configurable: type Mode = "dynamic" | "code" | "none"
const docMode = (mode: Mode, fn: Function) => Object.assign((...args) => fn(...args), { sourceType: mode }) Then {
showFunctions: true,
functionValue(fn) {
const sourceType = fn.sourceType || 'none' // This is the current behavior for all functions
switch(sourceType) {
case 'dynamic': return fn({})
case 'none': return () => {}
case 'code': return fn
}
}
} |
This worked for me. |
Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.41 containing PR #14652 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Hi @shilman, I have upgraded to the latest version( Here is my stories: export default {
title: 'Components/Badge',
component: Badge,
decorators:[(Story) => <div className='wrapper'><Story/></div>],
parameters: {
docs: {
source: {
type: 'dynamic'
}
}
},
} as Meta
const Template: Story<BadgeProps> = (args) => (
<Badge {...args}>
<Box size='sm' />
</Badge>
)
export const Basic = Template.bind({}) |
@Mike-Han you need to opt-out
|
@shilman It works well, thanks! |
Solution: My issue doesn't seem to be decorator related but seeing This fixes it for me. docs: {
transformSource: (source, { title }) => {
return source.replaceAll('No Display Name', title.substring(title.lastIndexOf('/') + 1));
}
} |
Only @kinoli's solution worked for me. Thank you 👍 |
this solution does not work with Angular with compdoc |
Describe the bug
When using decorator, viewing of the story would show the wrapper markup of the decorator and
<No Display name />
for the story.Expected behavior
It should only render the Story and not show the markup of the decorator
Screenshots
Code snippets
System:
The text was updated successfully, but these errors were encountered: