Skip to content

Commit

Permalink
feat(storybook): Remove consideration of mjs from docgen plugin (#11346)
Browse files Browse the repository at this point in the history
We created out Storybook framework package by starting with the
[official framework package for React
Vite](https://github.com/storybookjs/storybook/blob/next/code/frameworks/react-vite/).

Included in this is a Vite plugin for [React
Docgen](https://react-docgen.dev), which is used by Storybook to know
what the "controls" are (aka props) for a given component.

This is simply a QOL thing —

With docgen:
<img width="937" alt="Screenshot 2024-08-22 at 14 45 24"
src="https://github.com/user-attachments/assets/273a12a2-0382-4df4-845b-f50f141747b5">

Without docgen:
<img width="764" alt="Screenshot 2024-08-22 at 14 43 50"
src="https://github.com/user-attachments/assets/c1ec00be-6bdc-4ba8-99f7-a5360cecbcb9">

With or without docgen, in order to be able to have interactive
controls, you still need to [configure
them](https://storybook.js.org/docs/essentials/controls).

Docgen is mostly just used for [automatic argType
inference](https://storybook.js.org/docs/api/arg-types#automatic-argtype-inference).

The docgen plugin that we originally included in our framework package
matches components in `mjs`, `tsx`, and `jsx` files. `tsx` and `jsx` are
obvious requirements, and we didn't give any additional thought to the
inclusion of `mjs`, though it now seems that if you *do* have any `.mjs`
files that *aren't* components, [it'll completely break your ability to
load
stories](https://community.redwoodjs.com/t/storybook-in-redwood-is-moving-to-vite/7212/22?u=arimendelow),
as discovered by @simoncrypta.

Therefore, this PR simply removes the inclusion of those files.

---------

Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
  • Loading branch information
arimendelow and Josh-Walker-GM authored Aug 23, 2024
1 parent fc880b2 commit bae7f9d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/storybook/src/plugins/react-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Options = {
}

export function reactDocgen({
include = /\.(mjs|tsx?|jsx?)$/,
include = /\.(tsx?|jsx?)$/,
exclude = [/node_modules\/.*/],
}: Options = {}): PluginOption {
const cwd = process.cwd()
Expand Down
6 changes: 1 addition & 5 deletions packages/storybook/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config) => {
const { plugins = [] } = config

// Needs to run before the react plugin, so add to the front
plugins.unshift(
reactDocgen({
include: /\.(mjs|tsx?|jsx?)$/,
}),
)
plugins.unshift(reactDocgen())

return mergeConfig(config, {
// This is necessary as it otherwise just points to the `web` directory,
Expand Down

0 comments on commit bae7f9d

Please sign in to comment.