storybook: [Bug]: Unable to use Description without a Story in MDX
Describe the bug
An MDX (docs only) story with a Description errors with:
No primary story defined for docs entry. Did you forget to use `<Meta>`
To Reproduce
Create an MDX story file with Meta and a Description of a component:
import { Description, Meta } from "@storybook/addon-docs";
import { Button } from "./Button";
<Meta title="Button" />
<Description of={Button} />
Reproduction: https://github.com/will-stone/storybook-description-bug
System
Environment Info:
System:
OS: macOS 12.6.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 16.18.1 - ~/.local/share/nvm/v16.18.1/bin/node
npm: 8.19.2 - ~/.local/share/nvm/v16.18.1/bin/npm
Browsers:
Chrome: 107.0.5304.110
Firefox: 107.0
Safari: 16.1
npmPackages:
@storybook/addon-essentials: ^7.0.0-alpha.53 => 7.0.0-alpha.53
@storybook/addon-interactions: ^7.0.0-alpha.53 => 7.0.0-alpha.53
@storybook/addon-links: ^7.0.0-alpha.53 => 7.0.0-alpha.53
@storybook/react: ^7.0.0-alpha.53 => 7.0.0-alpha.53
@storybook/react-vite: ^7.0.0-alpha.53 => 7.0.0-alpha.53
@storybook/testing-library: ^0.0.13 => 0.0.13
Additional context
This used to work (I last tested on alpha 48 but not sure which alpha between then and now was the one that changed). It is useful to be able to grab the JSDoc description of components/functions without having a Story. For example, we use this as a way to document our hooks and utility functions.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 43 (16 by maintainers)
Commits related to this issue
- Simulate rendering doc blocks "unattached" Via `relativeCsfPaths: []`. This demonstrates the issue from https://github.com/storybookjs/storybook/issues/19964 — committed to storybookjs/storybook by tmeasday 4 years ago
- Add `useThrottleFunction` and `useThrottleValue` hooks (#48) - Closes #35 - Add `useThrottleValue` and `useThrottleFunction` hooks to `too-many-hooks` - Create docs for `useThrottleFunction` and m... — committed to yobgob/too-many-hooks by PatrickDeVries 4 years ago
- feat: enable Icons gallery in Storybook Enable `*.stories.mdx` in Storybook config. Comment out Subtitle from Icons story to avoid error: "Error: No primary story defined for docs entry. Did you forg... — committed to fintraffic-design/fds-coreui-components by Haprog 3 years ago
- feat: enable Icons gallery in Storybook Enable `*.stories.mdx` in Storybook config. Comment out Subtitle from Icons story to avoid error: "Error: No primary story defined for docs entry. Did you forg... — committed to fintraffic-design/fds-coreui-components by Haprog 3 years ago
I browsed the docs for 7.0 and got an impression that it’s totally possible to use doc blocks in documentation-only mdx pages, but then run into this issue 😢 Would be a really useful feature, looking forward to it!
In
7.0.0-beta.8, I also have a similar error but this time related to the<Canvas>component. Based on the doc here, I should be able to use the folowing without issue.I’m running into this issue again with
Canvasafter upgrading to Storybook 8.I’m just trying to wrap a piece of JSX in a
Canvasinside a documentation-only MDX file. I’ve tried importingCanvasandMetafrom@storybook/addon-docsand from@storybook/blocks(I tried all possible import combinations) but in all cases I get the same error: “No primary story defined for docs entry. Did you forget to use<Meta>?”. Same if I don’t useMetaat all and let the title be inferred from the first heading.For someone still face the problem
Did you forget to use <Meta>?, placeMetatag before other tags likeTitle,Primary😂Thanks for the update! I upgraded my project to
beta.25and it seems to have fixedDescription. However I’m still seeing the original error forArgsTable,Source, andCanvas. Are there plans to fix these components as well?I’m having the same issue after upgrading to v8. Should this issue be reopened or should we raise a new one?
Seems to work fine for
Titlebut not forSubtitleyet. Stacktrace still showsstoryByIdis called from theSubtitle2component.Thanks @mdaoust-sidlee, I’ve fixed it in #20803, should be released in the next couple of days.
@JReinhold using doc blocks in docs-only mdx files works great, the only caveat that i have run into is that you cannot import stories in
.mdxdocs-only files using the webpack aliases you defined inmain.ts.Something like this in a
.mdxfile:will render correctly, while this:
will fail with
Invalid value passed to the 'of' prop. The value was resolved to a 'component or unknown' type but the only types for this block are: storyA little debug reveals that with the second scenario
csfFilespassed toDocsContextis empty and thenresolveOfthrows.The aliases itself are resolved because i can
console.login themdxfiles the imported stories definitions, the problem is thatexportsToCSFFilemap is simply empty inDocsContextwhen using these aliases.Did i run into some known limitation or is it a problem with my setup and you would need a reproduction from me?
@JReinhold yes. I looked into doing that first, but I wanted it to look the same as the actual canvases I used. And looking at the code, there’s quite a bit involved in getting the same style as the builtin blocks:
I guess what I really would want is a block that has this “preview” view, as just a simple styled component.
@JReinhold it’s mostly a visual thing. What we have currently is this:
which renders as following:
While also producing 2 stories. I use the same pattern multiple places:
I mostly just care about the border/look of the
Canvas, not the source and features like that - so I’d be completely OK with not usingCanvasbut something else. It would be even better if that “something” had unstyled set on it.The last example I have is this:
This more or less shows what I really want. The “look” of a canvas, with no storybook styling inside, and then showing multiple stories in that “box”. In this case:
Showing all the variants of a small component (e.g. a button) in a summary view at the top of a document.
The issue here will be that we need to interpret that import in the story indexer (which reads your MDX file statically). I’m not sure it is feasible for it to understand things like aliases. WDYT @shilman?
@JReinhold does that mean you can no longer do multiple stories in one canvas?
Ah yes that makes sense. Passing children to Canvas has been deprecated, moving forward you should use the
ofprop to reference a story. That also means that it can’t be used to wrap arbitrary content as before, but only to show a single story.See the migration notes for more. The docs haven’t yet been updated to reflect this. https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#canvas-block
And your example is nether attached to stories with
ofon Meta or Canavs nor does it have any stories as children, so Canvas fails to find any stories.With that said it should all be deprecations, and still support old behavior. Did this work in 6.5, a canvas without stories? Then we might have introduced a bug.
Still no luck with
7.0.0-beta.34. I still encounter the following error when I try to use the following mdx file :Ahh, so are you using
<Source code="..." />in an unattached docs file (i.e plain.mdxfile) @dryton? I think this is a bug for sure, I’ll open a new ticket for it.We’ve finished migrating all the blocks to the new API, so this should be fixed.
We’ve changed the API for many of the blocks (with deprecation warnings), we’re not ready with the new docs for them, but in the mean time you can check the migration notes which should give a sense of the changes.
Whoopee!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.25 containing PR #20563 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
Don’t know if my issue is related, but I’ll add it here too.
After upgrading to Storybook 7 I am noticing that my docs-only pages are no longer working if they have Story objects in them.
In our application we have 3 basic pages to describe the use of typography, icons and color. all of these pages work fine if I remove any Story-blocks, if story-blocks are defined then the page raises the following error:
I have tried using the Story and Canvas components from 2 different places, both without success:
Rendering the components without a story (so
<Loading />seems to work fine for now so I’ll fallback to that)System specifications: