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 2 years ago
- Reactions: 6
- Comments: 42 (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 2 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 a year 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 8 months 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 8 months 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
Canvas
after upgrading to Storybook 8.I’m just trying to wrap a piece of JSX in a
Canvas
inside a documentation-only MDX file. I’ve tried importingCanvas
andMeta
from@storybook/addon-docs
and 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 useMeta
at all and let the title be inferred from the first heading.Thanks for the update! I upgraded my project to
beta.25
and 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?Thanks @mdaoust-sidlee, I’ve fixed it in #20803, should be released in the next couple of days.
Seems to work fine for
Title
but not forSubtitle
yet. Stacktrace still showsstoryById
is called from theSubtitle2
component.@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
.mdx
docs-only files using the webpack aliases you defined inmain.ts
.Something like this in a
.mdx
file: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: story
A little debug reveals that with the second scenario
csfFiles
passed toDocsContext
is empty and thenresolveOf
throws.The aliases itself are resolved because i can
console.log
in themdx
files the imported stories definitions, the problem is thatexportsToCSFFile
map is simply empty inDocsContext
when 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?
For someone still face the problem
Did you forget to use <Meta>?
, placeMeta
tag before other tags likeTitle
,Primary
😂@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 usingCanvas
but 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?
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.mdx
file) @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
@next
NPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.