-
-
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
Docs: Fix attachment logic #20531
Docs: Fix attachment logic #20531
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I only have one request. 👍
const resolved = this.resolveModuleExport(metaExports); | ||
if (resolved.type !== 'meta') | ||
throw new Error('Cannot reference a non-meta or module export in <Meta of={} />'); | ||
this.attachCSFFile(resolved.csfFile); | ||
} | ||
|
||
resolveModuleExport(moduleExport: ModuleExport, metaExports?: ModuleExports) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided that resolveModuleExport(undefined)
would:
- Unattached: throw a nice error like "Cannot resolve an undefined module export in an unattached doc" (a
useOf
hook in blocks would make this error more user-friendly) - Attached: return the primary story.
I think we should have that in this PR, along with an a matching test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 🤌
Merging this in to the parent PR for simplicity, thanks folks! |
Telescoping on #20517
What I did
Rationalized how attachment works:
For CSF (template) files, we attach to the (one or more) CSF files we are templating, immediately. (You can have more than one with autodocs and stories spread over > 1 CSF file.
For MDX files, we attach when you call
<Meta of={} />
.How to test