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

[Bug]: Adding a decorator breaks Show Code view #21456

Closed
MarcusNotheis opened this issue Mar 7, 2023 · 7 comments
Closed

[Bug]: Adding a decorator breaks Show Code view #21456

MarcusNotheis opened this issue Mar 7, 2023 · 7 comments

Comments

@MarcusNotheis
Copy link

Describe the bug

When adding a decorator in the Preview file, the Show Code view in the Docs View is breaking.

Show Code without Decorator:
image

Show Code with Decorator:
image

Instead of showing the component name with computed args, <No Display Name /> is shown.

To Reproduce

Repo: https://github.com/MarcusNotheis/sb-code-repro
Deployed: https://marcusnotheis.github.io/sb-code-repro/?path=/docs/example-button--docs

To reproduce:

  1. Install dependencies with yarn
  2. Start Storybook with yarn storybook and open the Button Docs story.
  3. Expand the Show Code Panel and see the error.
  4. Optional: Remove the decorators array from the preview file, then the Show Code panel is displayed correctly:
    https://github.com/MarcusNotheis/sb-code-repro/blob/5f94ba62da2083cc89c30ba5122192a10fee1fe3/.storybook/preview.tsx#L27

System

System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 18.14.1 - ~/.nvm/versions/node/v18.14.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.1/bin/yarn
    npm: 9.5.0 - ~/.nvm/versions/node/v18.14.1/bin/npm
  Browsers:
    Chrome: 110.0.5481.177
    Edge: 110.0.1587.63
    Firefox: 110.0
    Safari: 16.3
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/addon-interactions: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/addon-links: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/blocks: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/react: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/react-vite: ^7.0.0-beta.61 => 7.0.0-beta.62 
    @storybook/testing-library: ^0.0.14-next.1 => 0.0.14-next.1

Additional context

No response

@MarcusNotheis MarcusNotheis changed the title [Bug]: Decorator breaks Show Code view. [Bug]: Adding a decorator breaks Show Code view. Mar 7, 2023
@MarcusNotheis MarcusNotheis changed the title [Bug]: Adding a decorator breaks Show Code view. [Bug]: Adding a decorator breaks Show Code view Mar 7, 2023
@valentinpalkovic
Copy link
Contributor

valentinpalkovic commented Mar 7, 2023

Hi @MarcusNotheis

Could you try to set the following code in your .storybook/preview.tsx:

export const parameters = {
  docs: {
    source: {
      excludeDecorators: true,
    },
  },
};

This excludes the decorators from the Show Code view. Does this workaround solve your problem until the issue is fixed?

@MarcusNotheis
Copy link
Author

Thanks for your suggestion @valentinpalkovic!
Adding this parameter resolves the issue for me.

@MarcusNotheis
Copy link
Author

Hi @shilman,
is this issue really resolved? The workaround @valentinpalkovic proposed is working absolutely fine for me, but is it really the desired behavior to show <No Display Name /> in the code view when using a decorator without the workaround?

@shilman shilman reopened this Mar 8, 2023
HeartSquared added a commit to cultureamp/kaizen-design-system that referenced this issue Apr 6, 2023
Storybook changes:
- Update Storybook to v`7.0.0`
- Update `preview.tsx` to use default export
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#default-export-in-previewjs
- Remove `--no-manager-cache` flag from storybook build as it no longer exists (broke the build)
- Add new local script `storybook:preview` to locally develop with docs view (same nav structure as release build)
- Remove `preview-head.html` as the font source has been deactivated and the TS hack doesn't appear needed
- Update all titles to not use string literals
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
	- Delete constants used for titles as they are no longer usable
	- Fix sort order to not use constants
- Remove usage of `withDesign` and `figmaEmbed`
	- Broken with update. Discussed with Kaizen team and we would prefer it gone instead.
	- Remove `storybook-addon-designs` (plugin for this feature)
- Fix stories using imported markdown
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#importing-plain-markdown-files-with-transcludemarkdown-has-changed
- Update type `ComponentMeta` to `Meta`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated
- Update types `ComponentStory` and `Story` to `StoryFn`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated
- Replace type `DecoratorFunction` with `Decorator`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#renamed-decoratorfn-to-decorator
- Move query decorator from global to `FilterMultiSelect` `Async` story
- Exclude decorators from code snippets
	- storybookjs/storybook#21456 (comment)
- Replace usages of `ArgsTable` with `Controls`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#argstable-block
- Wrap examples that do not live within a `Canvas` with `Unstyled`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#default-docs-styles-will-leak-into-non-story-user-components
- Update `.stories.mdx` files to `.mdx`
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mdx-docs-files
- Update local dev with story filtering to also search for MDX files
- Refactor default story paths to use globs
- Update Tailwind docs to work with the new `<Canvas>` structure (using `of` and referencing stories instead of `children`)
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#canvas-block
- Fix `Paragraph` story `Body Strong` example
- Fix most warnings/errors in the console
	- Change all functional components to not use default export, and fix exports for types (as args table missing props or controls)
	- Add missing `key`s to mapped components
	- Change `Paragraph` tag to `div` where it was wrapping elements which should not sit within a `p` (eg. `ul`)
	- Use `import` instead of `require`
	- Update import statement for storybook backgrounds
- Reorder nav structure (#3349)
	- Group Modals together
- Add theming (#3354)
- Remove extractComponentDescription as notes are deprecated
	- https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#description-block-parametersnotes-and-parametersinfo
- Add table of contents to docs (#3348)
- Hide stickersheets in the Stickersheets story category (#3348)
- Add new docs template (#3350)
- Cleaned up Color Tokens stories
- Add `LinkTo` component for navigation to relative paths
- Add styles for links

Other changes:
- Delete `isEnabled` function as it was for Elm
- Remove Google Tag Manager
- Delete old READMEs which were used for the site (not used here)

---------

Co-authored-by: Geoffrey Chong <gyfchong@users.noreply.github.com>
Co-authored-by: Natalie Loyzaga <48232362+NatalieLoyzaga@users.noreply.github.com>
@roymrinmoy
Copy link

I have the same issue but only when I am doing something like the following:

{/** When passing props like below, includes the decorator code */}
 <Story
    {...context}
    args={{ ...context.args, animationTriggerRef: buttonRef }}
/>

{/** Without passing any props, works as expected */}
<Story />

Full context:

export const TriggerWithRef = {
  args: {
    className: "h-10 w-10",
    animationTriggerEvent: "hover",
  },
  parameters: {
    controls: { exclude: ["animate"] },
  },
  decorators: [
    (Story, context) => {
      const buttonRef = useRef();
      return (
        <div>
          <button className="mb-5" ref={buttonRef}>
            hover me
          </button>
          <Story
            {...context}
            args={{ ...context.args, animationTriggerRef: buttonRef }}
          />
        </div>
      );
    },
  ],
};

Adding parameters.docs.source.excludeDecorators = true in .storybook/preview.js didn't help either.

@guillaume-g
Copy link

I have exactly the same issue as @roymrinmoy (same code almost) and doing the idea of @valentinpalkovic also didn't fix the issue.

When changing the args from a Story in a decorator, it breaks the show code.

@tmeasday
Copy link
Member

tmeasday commented May 12, 2023

This issue is a duplicate of #21649. In summary:

  1. The fact that you can't see "inside" decorators is a fairly fundamental issue that we worked around by moving the JSX decorator to the end of the decorator chain: React: Don't show decorators in JSX snippets #21907
  2. The fact that the StoryFn element (passed to a decorator) is rendered as <No Display Name /> is unfortunate, and we'd take a PR to fix it, but due to 1. the fix isn't really going to help much.
  3. @roymrinmoy's issue is [Bug]: Adding arguments in the decorator breaks the source code #22127, which I believe is already fixed! 🤞

@tmeasday tmeasday closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
@pedroleitaogls
Copy link

For anyone encountering a similar issue when using @storybook/angular I have opened this issue #25147.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants