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

feat: add sideeffects to addons; #29841

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

denisx
Copy link

@denisx denisx commented Dec 7, 2024

What I did

Add side effects to package.json, help bundlers cut unused code with treeshake. Good for esm, modules, named imports.

rollup https://rollupjs.org/configuration-options/#treeshake-modulesideeffects
webpack https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.7 MB 77.7 MB 0 B -0.82 0%
initSize 130 MB 130 MB 288 B 1.36 0%
diffSize 52.7 MB 52.7 MB 288 B 1.36 0%
buildSize 6.87 MB 6.86 MB -598 B 1.35 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.86 MB 1.86 MB 0 B 0.93 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.57 MB 3.57 MB 0 B 0.93 0%
buildPreviewSize 3.3 MB 3.3 MB -598 B 1.35 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.1s 15.1s 8s 0.52 52.9%
generateTime 20s 23s 3s 1.45 🔺13.2%
initTime 13.9s 15.2s 1.3s 1.46 🔺9%
buildTime 8.6s 8.1s -584ms -1.24 🔰-7.2%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.7s 5.4s -338ms 0.59 -6.2%
devManagerResponsive 4.2s 3.9s -247ms 0.82 -6.2%
devManagerHeaderVisible 634ms 716ms 82ms 2.47 🔺11.5%
devManagerIndexVisible 701ms 749ms 48ms 1.12 6.4%
devStoryVisibleUncached 2s 2s 21ms 1.04 1%
devStoryVisible 702ms 750ms 48ms 1.53 🔺6.4%
devAutodocsVisible 700ms 713ms 13ms 2.81 1.8%
devMDXVisible 588ms 664ms 76ms 2.46 🔺11.4%
buildManagerHeaderVisible 699ms 821ms 122ms 3.92 🔺14.9%
buildManagerIndexVisible 822ms 937ms 115ms 3.75 🔺12.3%
buildStoryVisible 629ms 776ms 147ms 4.63 🔺18.9%
buildAutodocsVisible 527ms 536ms 9ms 1.3 1.7%
buildMDXVisible 532ms 549ms 17ms 2.19 3.1%

Greptile Summary

Added sideEffects: false to multiple Storybook addon package.json files to enable better tree-shaking optimization, with potential risks identified in certain addons.

  • Test addon requires careful review due to Vitest integration files and setup scripts that likely have necessary initialization side effects
  • Onboarding addon may break due to dependencies like react-confetti and framer-motion that require runtime initialization
  • Docs addon needs thorough testing across frameworks due to MDX processing and framework-specific initialization code
  • Links addon could be problematic since preview/manager registration typically requires side effects
  • A11y addon may have critical initialization requirements for axe-core and accessibility testing functionality

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

@denisx denisx marked this pull request as ready for review December 7, 2024 14:08
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

19 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -43,6 +43,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider setting sideEffects to ['./dist/manager.js'] since manager entries often have initialization side effects

@@ -75,6 +75,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider setting sideEffects to an array of framework-specific files that do have side effects instead of false

@@ -75,6 +75,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Consider checking if any of the bundled addons (actions, backgrounds, controls etc.) have initialization side effects that need to be preserved. May need to be sideEffects: ["./dist/*/preview.js"] instead of false.

@@ -32,6 +32,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: react-confetti, framer-motion, and react-joyride may have side effects. Consider checking if these dependencies require side effects to function properly before marking the entire package as side-effect free.

@@ -65,6 +65,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Setting sideEffects to false here may be problematic since this addon has setup files, global setup, and postinstall scripts that likely have side effects. Consider reviewing the actual side effects in the codebase before marking as side-effect free.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

19 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -42,6 +42,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"sideEffects": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: axe-core and accessibility testing setup often requires initialization side effects - verify that tree-shaking doesn't break the accessibility testing functionality

@jonniebigodes jonniebigodes added ci:daily Run the CI jobs that normally run in the daily job. maintenance User-facing maintenance tasks addon: a11y addon: essentials addon: themes labels Dec 9, 2024
Copy link

nx-cloud bot commented Dec 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 70f10ba. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@storybook-pr-benchmarking
Copy link

Package Benchmarks

Commit: 70f10ba, ran on 9 December 2024 at 14:20:21 UTC

The following packages have significant changes to their size or dependencies:

@storybook/react-native-web-vite

Before After Difference
Dependency count 105 102 🎉 -3 🎉
Self size 42 KB 41 KB 🎉 -435 B 🎉
Dependency size 18.01 MB 17.86 MB 🎉 -154 KB 🎉
Bundle Size Analyzer Link Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: a11y addon: essentials addon: themes ci:daily Run the CI jobs that normally run in the daily job. maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants