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

Upgrade to Storybook v7 with Vite #9019

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Upgrade to Storybook v7 with Vite #9019

merged 1 commit into from
Dec 15, 2023

Conversation

jesstelford
Copy link
Contributor

@jesstelford jesstelford commented Apr 19, 2023

Screenshot 2023-04-19 at 4 44 50 pm


See it in action: https://5d559397bae39100201eedc1-otbapvfeve.chromatic.com

Upgrades Storybook to v7 so we can benefit from Vite's improved build times over Webpack, plus be closer aligned to how we build our components for production in @shopify/polaris.

Performance

main

Benchmark 1: yarn workspace @shopify/polaris run storybook:build --quiet
  Time (mean ± σ):     17.833 s ±  0.192 s    [User: 64.729 s, System: 3.628 s]
  Range (min … max):   17.506 s … 18.067 s    10 runs

storybook-v7

Benchmark 1: yarn workspace @shopify/polaris run storybook:build --quiet
  Time (mean ± σ):     17.798 s ±  0.551 s    [User: 30.510 s, System: 2.862 s]
  Range (min … max):   17.225 s … 19.239 s    10 runs

That's a total saving of 35ms! 🎉 ... 🤔

Update: Re-ran the perf test, and this time... it's 1s slower 😓

❯ hyperfine --parameter-list branch main,storybook-v7 --setup='git checkout {branch} && yarn && yarn build --filter=@shopify/polaris' --prepare='rm -rf polaris-react/build-internal/storybook/' --warmup 1 'yarn workspace @shopify/polaris run storybook:build --quiet'
Benchmark 1: yarn workspace @shopify/polaris run storybook:build --quiet (branch = main)
  Time (mean ± σ):     16.509 s ±  0.253 s    [User: 65.154 s, System: 3.320 s]
  Range (min … max):   16.200 s … 17.073 s    10 runs

Benchmark 2: yarn workspace @shopify/polaris run storybook:build --quiet (branch = storybook-v7)
  Time (mean ± σ):     17.011 s ±  0.192 s    [User: 30.488 s, System: 2.655 s]
  Range (min … max):   16.632 s … 17.270 s    10 runs

Summary
  yarn workspace @shopify/polaris run storybook:build --quiet (branch = main) ran
    1.03 ± 0.02 times faster than yarn workspace @shopify/polaris run storybook:build --quiet (branch = storybook-v7)

Tophatting

  • Is POLARIS_VERSION being replaced within the JS in dev + prod builds?
  • Check all stories render correctly
  • Check the STORYBOOK_ env vars are making their way into the bundle in CI (for the GitHub icon/link in the toolbar)

@github-actions
Copy link
Contributor

github-actions bot commented Apr 19, 2023

size-limit report 📦

Path Size
polaris-react-cjs 240.81 KB (0%)
polaris-react-esm 156.93 KB (0%)
polaris-react-esnext 219.13 KB (0%)
polaris-react-css 47.27 KB (0%)

@jesstelford jesstelford marked this pull request as draft April 19, 2023 07:12
@jesstelford jesstelford added the 🤖Skip Comment Check Skip the migrator comment CI check label Apr 20, 2023
@BPScott
Copy link
Member

BPScott commented Apr 20, 2023

With the addition of polaris-patterns stuff, it feels like this would be a good opportunity to pull the storybook stuff into the root of the repo rather than be within polaris-react. Then polaris could have one storybook instance that can serve up content from multiple packages, instead of each package needing to maintain its own storybook config (or even weirder, the storybook in polaris-react loading stories from other packages)

I'd be tempted to pull the .scss -> .module.scss renaming out into a separate PR once this is all ready to keep "boring automations" all in one PR separate to the more interesting shuffling.


import {defineConfig} from 'vite';

import {generateScopedName} from './config/rollup/namespaced-classname-module.mjs';
Copy link
Member

@BPScott BPScott Apr 20, 2023

Choose a reason for hiding this comment

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

I think there's a world where you don't need this namespaced-classname-module.mjs file. node should be fine with importing commonjs files within a esmodules file using import.

import {generateScopedName} from './config/rollup/namespaced-classname.js'; should work. It it doesn't then you could make that be the default export, or you might need to fiddle with how the export is defined to make it more statically analysable. If you need to do that, I think it's a case of doing module.exports = {generateScopedName} at the bottom of the file instead of module.exports.generateScopedName = BLAH

You might need to fiddle with how the modules are declared

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to revisit this one because I'd forgotten the reason we'd gone this route. Turns out it's unfortunately not as simple as node's file type detection; Vite is baulking on the require('path') within config/rollup/namespaced-classname.js:

ERR! Error: Dynamic require of "node:path" is not supported
ERR!     at file:///Users/jess/dev/polaris/polaris-react/vite.config.mjs.timestamp-1682311621838.mjs:12:9
ERR!     at config/rollup/namespaced-classname.js (/Users/jess/dev/polaris/polaris-react/config/rollup/namespaced-classname.js:1:369)
ERR!     at __require2 (file:///Users/jess/dev/polaris/polaris-react/vite.config.mjs.timestamp-1682311621838.mjs:15:50)
ERR!     at <anonymous> (/Users/jess/dev/polaris/polaris-react/vite.config.mjs:7:34)
ERR!     at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
ERR!     at async Promise.all (index 0)
ERR!     at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
ERR!     at async loadConfigFromBundledFile (file:///Users/jess/dev/polaris/node_modules/vite/dist/node/chunks/dep-d305c21f.js:63967:21)
ERR!     at async Module.loadConfigFromFile (file:///Users/jess/dev/polaris/node_modules/vite/dist/node/chunks/dep-d305c21f.js:63852:28)
ERR!     at commonConfig (/Users/jess/dev/polaris/node_modules/@storybook/builder-vite/dist/index.js:161:5305)

It looks like Storybook is doing some kind of pre-processing on the files (see the .timestamp-XXXXX suffixes) which might be messing with it 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An easy fix: The only other place this functionality is requires is in the rollup.config.mjs file which doesn't error when importing namespaced-classname-module.mjs 🎉

I've made that changed and pushed it to this branch.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! great spot realising that the only other place we use this is an esmodules file. I'd forgotten that polaris moved its rollup files over to be mjs.

@jesstelford
Copy link
Contributor Author

good opportunity to pull the storybook stuff into the root of the repo rather than be within polaris-react

Agreed! We started exploring this a bit in another branch, but it rapidly got more complex than one PR should contain, hence this first step. Future PRs could even build polaris-react with Vite also (since Vite uses rollup under the hood), which means our Storybook & our npm build would share a config. But that's for the future / another discussion 👍

@jesstelford
Copy link
Contributor Author

jesstelford commented Apr 24, 2023

I'd be tempted to pull the .scss -> .module.scss renaming out into a separate PR

This could be possible, but it would mean messing with the webpack config in Storybook v6 to ensure that commit is atomic which I didn't want to bother with given it's immediately going to be deleted by this PR.

It's a good point though about keeping the changes seperate; if you think it's worth it to preserve the history like that, I could be persuaded 👍

@jesstelford jesstelford force-pushed the storybook-v7 branch 2 times, most recently from 99c9adf to 2c6b81b Compare April 24, 2023 05:07
@jesstelford jesstelford requested a review from BPScott April 24, 2023 05:08
@BPScott
Copy link
Member

BPScott commented Apr 24, 2023

This could be possible, but it would mean messing with the webpack config in Storybook v6 to ensure that commit is atomic which I didn't want to bother with given it's immediately going to be deleted by this PR.

The storybook config on main uses the auto option to control what get passed through css modules. Currently it is set up so every scss file should use modules, with the exception of paths containing global, and it looks like that's only the AppProvider global file. Switching that over to true should result in the same logic as Vite - files with only .module. in the filename get passed through. I think things should continue to work as expected if you only renamed the files and didn't touch the webpack config at all.

Obviously I'm not on polaris anymore so I'm just an interested observer - the final call is very munch in your hands :) but I suspect splitting the renames out, wouldn't require the extra work you're concerned about as I don't think we'd actually need to touch the webpack css-loader config when doing the mass rename.

@jesstelford
Copy link
Contributor Author

@BPScott With your help I was able to pull out the file renames to a separate PR which is now merged 🎉
#11340

@jesstelford jesstelford added the 🤖Skip Changelog Causes CI to ignore changelog update check. label Dec 15, 2023
@jesstelford jesstelford marked this pull request as ready for review December 15, 2023 02:11
@jesstelford jesstelford force-pushed the storybook-v7 branch 2 times, most recently from 12b6e7d to 1d1183b Compare December 15, 2023 02:34
Copy link
Member

@aaronccasanova aaronccasanova left a comment

Choose a reason for hiding this comment

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

Amazing! 👏

@jesstelford
Copy link
Contributor Author

Thanks for the review and suggestions @aaronccasanova!

I realized there was a small bug with replacing the magic string {{POLARIS_VERSION}} in storybook; it wasn't being replace 😓

So I've fixed that up by leveraging https://www.npmjs.com/package/vite-plugin-replace (which ultimately just does code.replace()). Can confirm by looking at the CSS Custom property --polaris-version-number on the :root element:

Screenshot 2023-12-15 at 16 52 27

@jesstelford jesstelford linked an issue Dec 15, 2023 that may be closed by this pull request
@jesstelford
Copy link
Contributor Author

@BPScott @alex-page I've created https://github.com/Shopify/temp-project-mover-Archetypically-20250305131128/issues/176 to track the next logical step of this work.

@jesstelford jesstelford merged commit ba1c813 into main Dec 15, 2023
@jesstelford jesstelford deleted the storybook-v7 branch December 15, 2023 06:14
sophschneider pushed a commit that referenced this pull request Jan 10, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris@12.7.0

### Minor Changes

- [#11304](#11304)
[`9c57cc1c2`](9c57cc1)
Thanks [@yurm04](https://github.com/yurm04)! - [Tooltip] Added
`min-width` to `TooltipOverlay`


- [#11403](#11403)
[`2bcc7bda5`](2bcc7bd)
Thanks [@yurm04](https://github.com/yurm04)! - [Navigation] Updated
`padding-top` to `space-100` for small viewports


- [#11231](#11231)
[`3a0228815`](3a02288)
Thanks [@thyleung](https://github.com/thyleung)! - - Added the
`paddingBlockEnd` prop to the `IndexTableHeading` interface to support
additional right padding
- Fixed sortable `IndexTable` headings with a tooltip not being right
aligned properly


- [#9019](#9019)
[`ba1c813c2`](ba1c813)
Thanks [@jesstelford](https://github.com/jesstelford)! - Upgrade to
Storybook v7 with Vite


- [#11400](#11400)
[`befded29d`](befded2)
Thanks [@yurm04](https://github.com/yurm04)! - [Dialog] Removed
`sizeSmall` max-width for small viewports


- [#11374](#11374)
[`f631b229f`](f631b22)
Thanks [@kyledurand](https://github.com/kyledurand)! - Added as prop to
InlineStack
    Added span and list item element types to BlockStack


- [#11212](#11212)
[`7d056dea2`](7d056de)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Refactored
`Button` styles and bevel

### Patch Changes

- [#11411](#11411)
[`7202e1605`](7202e16)
Thanks [@sophschneider](https://github.com/sophschneider)! - Changed
`IndexTable` scroll bar container z-index so that it is under the `Card`
shadow bevel


- [#11363](#11363)
[`c356dd5e5`](c356dd5)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed Button
padding regression in Safari 14


- [#11364](#11364)
[`bf9539536`](bf95395)
Thanks [@heyjoethomas](https://github.com/heyjoethomas)! - Fixes shadow
and bevel of basic button


- [#11224](#11224)
[`ea8e5510e`](ea8e551)
Thanks [@sophschneider](https://github.com/sophschneider)! - Updated
margins for TextField prefixes


- [#11366](#11366)
[`b62cf7356`](b62cf73)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed segmented
button divider regression


- [#11383](#11383)
[`a1c141669`](a1c1416)
Thanks [@jhalvorson](https://github.com/jhalvorson)! - [IndexTable] use
the correct index for the sticky header when rows are selectable


- [#11373](#11373)
[`97c3979ba`](97c3979)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed Button
active state regression when used with activators such as Popover


- [#11342](#11342)
[`9484d55ca`](9484d55)
Thanks [@jhalvorson](https://github.com/jhalvorson)! - [IndexTable]
Fixed aligment issues with the sticky header


- [#11401](#11401)
[`5604728ee`](5604728)
Thanks [@ardakaracizmeli](https://github.com/ardakaracizmeli)! - Changed
the icon color from icon-magic to text-magic for the Magic tone of the
Badge component.

- Updated dependencies
\[[`9f7e5b682`](9f7e5b6)]:
    -   @shopify/polaris-tokens@8.5.0

## @shopify/polaris-tokens@8.5.0

### Minor Changes

- [#11345](#11345)
[`9f7e5b682`](9f7e5b6)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Added missing
color tokens for Shopify Mobile

## @shopify/polaris-migrator@0.26.7

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](9f7e5b6)]:
    -   @shopify/polaris-tokens@8.5.0
    -   @shopify/stylelint-polaris@15.0.7

## @shopify/stylelint-polaris@15.0.7

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](9f7e5b6)]:
    -   @shopify/polaris-tokens@8.5.0

## polaris-for-vscode@0.9.3

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](9f7e5b6)]:
    -   @shopify/polaris-tokens@8.5.0

## polaris.shopify.com@0.61.5

### Patch Changes

- [#11402](#11402)
[`8fc829d39`](8fc829d)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed html output
for examples that have portals


- [#11385](#11385)
[`7bfb9bd48`](7bfb9bd)
Thanks [@kyledurand](https://github.com/kyledurand)! - Removed props
table feedback link, added footer link to create component issues

- Updated dependencies
\[[`9c57cc1c2`](9c57cc1),
[`7202e1605`](7202e16),
[`2bcc7bda5`](2bcc7bd),
[`c356dd5e5`](c356dd5),
[`bf9539536`](bf95395),
[`ea8e5510e`](ea8e551),
[`3a0228815`](3a02288),
[`b62cf7356`](b62cf73),
[`a1c141669`](a1c1416),
[`97c3979ba`](97c3979),
[`ba1c813c2`](ba1c813),
[`befded29d`](befded2),
[`9484d55ca`](9484d55),
[`f631b229f`](f631b22),
[`5604728ee`](5604728),
[`7d056dea2`](7d056de),
[`9f7e5b682`](9f7e5b6)]:
    -   @shopify/polaris@12.7.0
    -   @shopify/polaris-tokens@8.5.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ascherkus pushed a commit to ascherkus/polaris that referenced this pull request Feb 19, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris@12.7.0

### Minor Changes

- [Shopify#11304](Shopify#11304)
[`9c57cc1c2`](Shopify@1fdb180)
Thanks [@yurm04](https://github.com/yurm04)! - [Tooltip] Added
`min-width` to `TooltipOverlay`


- [Shopify#11403](Shopify#11403)
[`2bcc7bda5`](Shopify@d13af64)
Thanks [@yurm04](https://github.com/yurm04)! - [Navigation] Updated
`padding-top` to `space-100` for small viewports


- [Shopify#11231](Shopify#11231)
[`3a0228815`](Shopify@728a418)
Thanks [@thyleung](https://github.com/thyleung)! - - Added the
`paddingBlockEnd` prop to the `IndexTableHeading` interface to support
additional right padding
- Fixed sortable `IndexTable` headings with a tooltip not being right
aligned properly


- [Shopify#9019](Shopify#9019)
[`ba1c813c2`](Shopify@d9178be)
Thanks [@jesstelford](https://github.com/jesstelford)! - Upgrade to
Storybook v7 with Vite


- [Shopify#11400](Shopify#11400)
[`befded29d`](Shopify@a5bcdca)
Thanks [@yurm04](https://github.com/yurm04)! - [Dialog] Removed
`sizeSmall` max-width for small viewports


- [Shopify#11374](Shopify#11374)
[`f631b229f`](Shopify@6229245)
Thanks [@kyledurand](https://github.com/kyledurand)! - Added as prop to
InlineStack
    Added span and list item element types to BlockStack


- [Shopify#11212](Shopify#11212)
[`7d056dea2`](Shopify@9e0ad2b)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Refactored
`Button` styles and bevel

### Patch Changes

- [Shopify#11411](Shopify#11411)
[`7202e1605`](Shopify@b3ede5a)
Thanks [@sophschneider](https://github.com/sophschneider)! - Changed
`IndexTable` scroll bar container z-index so that it is under the `Card`
shadow bevel


- [Shopify#11363](Shopify#11363)
[`c356dd5e5`](Shopify@af66cc6)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed Button
padding regression in Safari 14


- [Shopify#11364](Shopify#11364)
[`bf9539536`](Shopify@f3a22e0)
Thanks [@heyjoethomas](https://github.com/heyjoethomas)! - Fixes shadow
and bevel of basic button


- [Shopify#11224](Shopify#11224)
[`ea8e5510e`](Shopify@785951b)
Thanks [@sophschneider](https://github.com/sophschneider)! - Updated
margins for TextField prefixes


- [Shopify#11366](Shopify#11366)
[`b62cf7356`](Shopify@3b96ff2)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed segmented
button divider regression


- [Shopify#11383](Shopify#11383)
[`a1c141669`](Shopify@fad62e1)
Thanks [@jhalvorson](https://github.com/jhalvorson)! - [IndexTable] use
the correct index for the sticky header when rows are selectable


- [Shopify#11373](Shopify#11373)
[`97c3979ba`](Shopify@42bf65e)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed Button
active state regression when used with activators such as Popover


- [Shopify#11342](Shopify#11342)
[`9484d55ca`](Shopify@812a04e)
Thanks [@jhalvorson](https://github.com/jhalvorson)! - [IndexTable]
Fixed aligment issues with the sticky header


- [Shopify#11401](Shopify#11401)
[`5604728ee`](Shopify@f3add43)
Thanks [@ardakaracizmeli](https://github.com/ardakaracizmeli)! - Changed
the icon color from icon-magic to text-magic for the Magic tone of the
Badge component.

- Updated dependencies
\[[`9f7e5b682`](Shopify@69cad76)]:
    -   @shopify/polaris-tokens@8.5.0

## @shopify/polaris-tokens@8.5.0

### Minor Changes

- [Shopify#11345](Shopify#11345)
[`9f7e5b682`](Shopify@69cad76)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Added missing
color tokens for Shopify Mobile

## @shopify/polaris-migrator@0.26.7

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](Shopify@69cad76)]:
    -   @shopify/polaris-tokens@8.5.0
    -   @shopify/stylelint-polaris@15.0.7

## @shopify/stylelint-polaris@15.0.7

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](Shopify@69cad76)]:
    -   @shopify/polaris-tokens@8.5.0

## polaris-for-vscode@0.9.3

### Patch Changes

- Updated dependencies
\[[`9f7e5b682`](Shopify@69cad76)]:
    -   @shopify/polaris-tokens@8.5.0

## polaris.shopify.com@0.61.5

### Patch Changes

- [Shopify#11402](Shopify#11402)
[`8fc829d39`](Shopify@11cb418)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed html output
for examples that have portals


- [Shopify#11385](Shopify#11385)
[`7bfb9bd48`](Shopify@94b768b)
Thanks [@kyledurand](https://github.com/kyledurand)! - Removed props
table feedback link, added footer link to create component issues

- Updated dependencies
\[[`9c57cc1c2`](Shopify@1fdb180),
[`7202e1605`](Shopify@b3ede5a),
[`2bcc7bda5`](Shopify@d13af64),
[`c356dd5e5`](Shopify@af66cc6),
[`bf9539536`](Shopify@f3a22e0),
[`ea8e5510e`](Shopify@785951b),
[`3a0228815`](Shopify@728a418),
[`b62cf7356`](Shopify@3b96ff2),
[`a1c141669`](Shopify@fad62e1),
[`97c3979ba`](Shopify@42bf65e),
[`ba1c813c2`](Shopify@d9178be),
[`befded29d`](Shopify@a5bcdca),
[`9484d55ca`](Shopify@812a04e),
[`f631b229f`](Shopify@6229245),
[`5604728ee`](Shopify@f3add43),
[`7d056dea2`](Shopify@9e0ad2b),
[`9f7e5b682`](Shopify@69cad76)]:
    -   @shopify/polaris@12.7.0
    -   @shopify/polaris-tokens@8.5.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖Skip Changelog Causes CI to ignore changelog update check. 🤖Skip Comment Check Skip the migrator comment CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Prototype] Update storybook
3 participants