-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
9518d9b
to
4cd8d63
Compare
size-limit report 📦
|
4cd8d63
to
163a558
Compare
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. |
polaris-react/vite.config.mjs
Outdated
|
||
import {defineConfig} from 'vite'; | ||
|
||
import {generateScopedName} from './config/rollup/namespaced-classname-module.mjs'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
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 👍 |
99c9adf
to
2c6b81b
Compare
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 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. |
38f5fb6
to
0854e30
Compare
0854e30
to
b8568b0
Compare
12b6e7d
to
1d1183b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! 👏
2721b4f
to
817f46e
Compare
Thanks for the review and suggestions @aaronccasanova! I realized there was a small bug with replacing the magic string So I've fixed that up by leveraging https://www.npmjs.com/package/vite-plugin-replace (which ultimately just does ![]() |
@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. |
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>
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>
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
storybook-v7
That's a total saving of
35ms
! 🎉 ... 🤔Update: Re-ran the perf test, and this time... it's 1s slower 😓
Tophatting
STORYBOOK_
env vars are making their way into the bundle in CI (for the GitHub icon/link in the toolbar)