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

Storybook 7 upgrade #1134

Merged
merged 47 commits into from
Mar 31, 2023
Merged

Storybook 7 upgrade #1134

merged 47 commits into from
Mar 31, 2023

Conversation

jattasNI
Copy link
Contributor

@jattasNI jattasNI commented Mar 24, 2023

Pull Request

🤨 Rationale

We want to be on the latest storybook version because it fixes issues we've had with dependencies and it enables more powerful docs pages via mdx and Component Story Format enhancements.

Notable changes:

👩‍💻 Implementation

Following the upgrade guide didn't work very well because it is buggy with a monorepo. Fred's general strategy was to run the upgrade command from within nimble-components then delete the node_modules and package-lock.json that it creates there, then re-install everything from the root. The migration tool is responsible for the changes to:

  1. storybook configuration files
  2. package.json
  3. renaming types like Story -> StoryFn and storyName to name
  4. deleting the withXD decorator which is no longer supported

Beyond that there were a few other manual changes:

  1. establish static dependencies on components needed by each story. Storybook seems to have gotten more aggressive about compiling away unneeded components so if something isn't imported, it won't be found and components won't render correctly. This meant:
    1. replacing a few literals for element tag names in stories with the elementTag export
    2. updating the nimble-menu to explicitly depend on nimble-anchored-region (see comment on menu/index.ts)
  2. Enable 'autodocs' for component and token stories but disable it for test stories
  3. Add a patch file to work around [Bug]: 7.0.0-rc.8 Cannot find module 'lib/types/dist' in @storybook/html storybookjs/storybook#21820
  4. simplified return types of story generation functions in storybook.ts in response to storybook type changes
  5. regenerated landing page screenshot and annotation now that docs tab is gone

🔜 Follow ups in future PRs

Fixing these issues is tracked by #1146 . I tried upgrading to ts 4.7 but it didn't fix any of them.

🧪 Testing

Chromatic caught several diffs which resulted in the manual changes described above 👍. It's still showing new stories for the wafer map and button. (The wafer map one is caused by Chromatic getting confused when I tried renaming that story, ran a Chromatic build, and then reverted that change. I don't know the cause of the button change.) <- this went away on a subsequent build

Also manually spot checked many of the stories across browsers, especially ones that have workarounds in them like table and theme-aware tokens.

✅ Checklist

  • I have updated the project documentation to reflect my changes or determined no changes are needed.

packages/nimble-components/.babelrc.json Outdated Show resolved Hide resolved
packages/nimble-components/.storybook/main.js Show resolved Hide resolved
packages/nimble-components/.babelrc.json Outdated Show resolved Hide resolved
packages/nimble-components/package.json Outdated Show resolved Hide resolved
packages/nimble-components/tsconfig.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@jattasNI jattasNI merged commit b2ab12c into main Mar 31, 2023
@jattasNI jattasNI deleted the users/fvisser/upgrade-to-storybook-7-beta branch March 31, 2023 14:43
rajsite added a commit that referenced this pull request Apr 3, 2023
# Pull Request

## 🤨 Rationale



## 👩‍💻 Implementation

As part of #1134 the menu element
definition added an import to the anchored region as an unused variable
for the element registration side-effect.

Build tooling with dead code elimination may try to strip out that
dependency under the assumption that imports do not have side effects so
they can safely remove an unused variable and the associated import
tree. Switched to the [side-effect only import
syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_a_module_for_its_side_effects_only)
which is a stronger declaration to bundling tools that the import has
side-effects.

## 🧪 Testing

Relying on CI, no additional tests added.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
@jattasNI jattasNI mentioned this pull request Apr 4, 2023
1 task
jattasNI added a commit that referenced this pull request Apr 4, 2023
# Pull Request

## 🤨 Rationale

After #1134, the Actions tab in Storybook was no longer displaying
events fired by components. This is one of the issues tracked in #1146.

As described in the [Storybook 7 migration
guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#removed-auto-injection-of-storybookaddon-actions-decorator),
the actions addon is no longer enabled by default and it must be enabled
by configuring the story with `decorators: [withActions]`. However, the
`withActions` decorator wasn't exported from Storybook in a way that we
could import it (see
storybookjs/storybook#21887). A Storybook dev
commented on that issue with a workaround that we can use until they fix
that bug.

## 👩‍💻 Implementation

1. Add a [TypeScript shorthand ambient module
declaration](https://www.typescriptlang.org/docs/handbook/modules.html#shorthand-ambient-modules)
for the import URL that contains `withActions`. See
`/utilities/tests/storybook-declarations.d.ts`.
2. Update all stories that expose an action to import `withActions` and
configure it as a decorator (also reordered a few imports to group them
by package)

## 🧪 Testing

Manually verified many of the stories that have actions are now firing
them.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
rajsite pushed a commit that referenced this pull request Apr 12, 2023
# Pull Request

## 🤨 Rationale

Right after I submitted the upgrade to a release candidate of Storybook
7 in #1134, I noticed they [released the official
7.0.0](https://github.com/storybookjs/storybook/releases). Adopting the
latest patch addresses some of the issues in #1146.

## 👩‍💻 Implementation

1. Update to latest non-RC build in package.json and regenerate
package-lock.json
2. Regenerate one patch file since the file it was patching has a new
name
3. Add another patch file since they introduced another instance of
storybookjs/storybook#21820
4. Move off deprecated API for specifying `sourceTransform` as described
in [migration
guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#source-block)
5. Delete `storybook-declarations.ts` since this bug was closed
storybookjs/storybook#21887

## 🧪 Testing

Explored Storybook.

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants