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

Docs: Fix attachment logic #20531

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Jan 7, 2023

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

  • See unit tests
  • Check doc blocks stories
  • Check docs pages

Copy link
Contributor

@JReinhold JReinhold left a 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) {
Copy link
Contributor

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.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 🤌

@tmeasday
Copy link
Member Author

Merging this in to the parent PR for simplicity, thanks folks!

@tmeasday tmeasday merged commit 666b503 into add-componentOrStoryIdByModuleExport Jan 10, 2023
@tmeasday tmeasday deleted the tom/sb-1122-sb19964-bug-unable-to-use-description-2 branch January 10, 2023 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants