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]: Docs stories filtered with '!autodocs' behaves weird in Primary, Stories, Controls, etc. components #27048

Open
JReinhold opened this issue May 7, 2024 · 5 comments

Comments

@JReinhold
Copy link
Contributor

JReinhold commented May 7, 2024

Describe the bug

In 8.1, we introduced the autodocs tag per story. It introduces a slightly inconsistent behavior:

  1. The Stories doc block automatically filters out any stories that don't have 'autodocs' - even if it is in a manually written attached MDX. Is that weird? Somewhat fixed in Docs: Fix MDX Stories block tag-filtering behavior #27144
  2. The Primary doc block doesn't take the filter into account at all, meaning that if the primary story has '!autodocs' it will still be selected as the primary story. Should it?
  3. 👆 Same for Controls and any other doc block supporting primary stories.
  4. useOf and resolveOf doesn't do any automatic filtering, causing the issue with 2 and 3 above. We briefly explored filtering out all '!autodocs' stories internally in DocsContext to solve all problems above, but that wasn't the best idea. It would make it impossible to resolve a story with '!autodocs' in a manual MDX, which seems counter intuitive.

I don't know what the right solution is here, or if there even is any, but we should be aware of this.

Additional context

@shilman proposes that all Storybook-provided doc blocks should automatically filter out '!autodocs' stories - even when used manually in MDX/DocsPage, S a way for users to easily re-create the autodocs experience.
But all user-written doc blocks (those that use useOf() or resolveOf()) should not do automatic filtering. Instead we should provide the tools to apply a filter if needed, either by passing a filter: true boolean somewhere, or make the filter function easily accessible.

@tmeasday
Copy link
Member

tmeasday commented May 7, 2024

I would have suggested instead we set a react context when rendering the autodocs container that applies that filter to all doc blocks? Something like:

export const Stories = () => {
  const inAutodocs = useContext(InAutodocsContext);
  const { componentStories, projectAnnotations, getStoryContext } = useContext(DocsContext);

  const stories = componentStories({ inAutodocs });
}

Did y'all consider that option?

@JReinhold
Copy link
Contributor Author

That's interesting @tmeasday , we didn't consider that. It would mean that a custom docs page with parameters.docs.page would also get the filter, right? Maybe that's also what makes the most sense.

@tmeasday
Copy link
Member

tmeasday commented May 8, 2024

@JReinhold well that depends on where we put the InAutodocProvider - we could put it either in the DocsContainer or the default DocsPage.

I don't recall in enough detail how you configure things of the top of my head but I suspect there'd be pros/cons to either one in terms of configurability.

@tmeasday
Copy link
Member

tmeasday commented May 8, 2024

Possibly if we put it in the container we could actually alter the context which would would avoid the need to alter the individual blocks?

<DocsContext.Provider value={context}>

We could set context.inAutodocs = true or similar around this line?

@shilman
Copy link
Member

shilman commented May 15, 2024

Related fix but a slightly different problem: #27143

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

3 participants