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] framework and addon preview annotations not automatically applied in portable stories #29781

Open
Tracked by #29770 ...
vanessayuenn opened this issue Dec 2, 2024 · 0 comments

Comments

@vanessayuenn
Copy link
Contributor

Apart from setting annotations in a set up file by importing them, users, addons or frameworks can also programatically add preview annotations via the previewAnnotations preset. Here's an example of what a user can do (though I think it's not so common):

// .storybook/main.js
export default {
  previewAnnotations: [
    "./src/stories/components",
    "./template-stories/core/preview.ts",
  ],  
}

And here's an example taken from our React renderer:

// Example taken from @storybook/react/preset
export const previewAnnotations: PresetProperty<'previewAnnotations'> = async (
  input = [],
  options
) => {
  const docsConfig = await options.presets.apply('docs', {}, options);
  const features = await options.presets.apply('features', {}, options);
  const docsEnabled = Object.keys(docsConfig).length > 0;
  const result: string[] = [];

  return result
    .concat(input)
    .concat([join(__dirname, 'entry-preview.mjs')])
    .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : [])
    .concat(features?.experimentalRSC ? [join(__dirname, 'entry-preview-rsc.mjs')] : []);
};

The react renderer example is interesting because the renderer has a portable stories entrypoint, which already adds the necessary annotations (and excludes the docs ones which are not needed), so that problem is solved when users call setProjectAnnotations coming from @storybook/react. However, this pattern would need to be documented for anyone creating community frameworks so that they can do the same thing.

💡 Solutions/Action items:

  • Do nothing, acknowledge this limitation
  • Document this properly. Users need to solve it by hand, framework authors need to provide the annotations (solved by CSF4 if the defineConfig function comes from frameworks)
  • Take this into account as part of a “preset handling” solution
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

1 participant