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

Vue: Fix out of memory error when using vue-component-meta #28589

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

larsrickert
Copy link
Contributor

@larsrickert larsrickert commented Jul 13, 2024

Closes #26647
Closes #26935
Based on discussions on #28462

What I did

This PR fixes the "out of memory" issue when running storybook build when using complex property types like HTMLElement with the vue-component-meta docgen plugin.

The root cause is that vue-component-meta includes all recursive schemas for object types which can be very complex and large (e.g. HTMLElement). Since the nested schema is not needed inside Storybok because we don't generate UI controls for object properties, we should be able to safely omitting them without any side effects.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run a sandbox for template, e.g. yarn task --task sandbox --start-from auto --template vue3-vite/default-ts
  2. In .storybook/main.ts, set the framework.options.docgen option to vue-component-meta
  3. Add new property test?: HTMLElement to any Vue component
  4. Run build-storybook

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

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/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 76.5 MB 76.5 MB 1.99 kB 1.83 0%
initSize 198 MB 198 MB 3.45 kB -0.78 0%
diffSize 121 MB 121 MB 1.46 kB -0.8 0%
buildSize 7.59 MB 7.59 MB 1 B 4.54 0%
buildSbAddonsSize 1.63 MB 1.63 MB 0 B 4.36 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.3 MB 2.3 MB 1 B Infinity 0%
buildSbPreviewSize 349 kB 349 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.47 MB 4.47 MB 1 B 4.54 0%
buildPreviewSize 3.12 MB 3.12 MB 0 B - 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 25.5s 23.7s -1s -764ms 1.41 🔰-7.4%
generateTime 20s 24.9s 4.8s 1.22 19.5%
initTime 20.6s 23.7s 3s 0.23 13%
buildTime 13.9s 15.6s 1.7s 1.11 11%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 8.2s 10.2s 1.9s 1.96 🔺18.8%
devManagerResponsive 5.6s 6.2s 629ms 1.51 🔺10.1%
devManagerHeaderVisible 799ms 1s 259ms 4.73 🔺24.5%
devManagerIndexVisible 828ms 1s 271ms 4.9 🔺24.7%
devStoryVisibleUncached 1.2s 1.8s 595ms 2.5 🔺31.8%
devStoryVisible 860ms 1.1s 263ms 4.8 🔺23.4%
devAutodocsVisible 715ms 847ms 132ms 2.22 🔺15.6%
devMDXVisible 696ms 943ms 247ms 3.46 🔺26.2%
buildManagerHeaderVisible 782ms 956ms 174ms 1.94 🔺18.2%
buildManagerIndexVisible 784ms 961ms 177ms 1.87 🔺18.4%
buildStoryVisible 852ms 1s 153ms 1.86 🔺15.2%
buildAutodocsVisible 697ms 842ms 145ms 1.39 🔺17.2%
buildMDXVisible 700ms 825ms 125ms 3.36 🔺15.2%

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.

PR Summary

  • /code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts: Removed nested object schemas not used in Storybook to reduce memory usage.
  • /code/renderers/vue3/src/docs/extractArgTypes.ts: Avoided recursive mapping of object schemas to prevent out-of-memory errors.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

nx-cloud bot commented Jul 13, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 9601e82. 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.

@et84121
Copy link

et84121 commented Jul 15, 2024

@larsrickert, I want to express my sincere gratitude for your thorough investigation and solution to this issue. Your approach of addressing the problem within Storybook's processing, rather than limiting vue-component-meta's capabilities, is indeed a much better solution than what I initially proposed.

Your work here not only solves the immediate problem but also maintains the full functionality of vue-component-meta, which is crucial for many projects. This fix will be incredibly helpful for teams like mine who are looking to adopt or continue using Storybook for component documentation.

Thank you for your dedication to improving Storybook and for fostering such a collaborative environment for problem-solving. Your efforts are truly appreciated!

},
{}
),
// Storybook does not generate controls for object properties so we don't need to recursively map the object schema here
Copy link
Contributor

@chakAs3 chakAs3 Jul 15, 2024

Choose a reason for hiding this comment

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

I'm not entirely sure what you mean here. it's true that complex objects won't have proper controls, Storybook does generate controls for simple objects (JSON object controls). However, it doesn't require or use nested schemas. I think you meant controls for the properties of objects rather than props of the object type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly, I updated the comment so I hope its clearer now :)

@larsrickert larsrickert requested a review from chakAs3 July 16, 2024 18:44
Copy link
Contributor

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kasperpeulen
Copy link
Contributor

Could you check the CI failures @larsrickert

@kasperpeulen kasperpeulen merged commit 3590a1c into next Jul 17, 2024
52 of 53 checks passed
@kasperpeulen kasperpeulen deleted the larsrickert/26647-out-of-memory branch July 17, 2024 13:23
@github-actions github-actions bot mentioned this pull request Jul 17, 2024
12 tasks
@MathiasCiarlo
Copy link

Thank you so much @larsrickert! We are waiting eagerly for this release. It will make our static bundle go frow 84 to 4 MB, greatly reducing build time 🥳

@Adamlb
Copy link

Adamlb commented Jul 19, 2024

I have tried the new alpha.2 release that included this PR but I am still experiencing the memory issues. Has this solved it for others? I'm wondering if I have something else going on.

@ericvel
Copy link

ericvel commented Jul 19, 2024

@Adamlb Sadly still experiencing the same issue 😢

@larsrickert
Copy link
Contributor Author

@Adamlb @ericvel I updated @storybook/vue3 and @storybook/vue3-vite to version 8.3.0-alpha.2 and it worked perfectly fine in my tests.

Could you share a reproduction example?

@ericvel
Copy link

ericvel commented Jul 22, 2024

@larsrickert It does in fact seem to have fixed the issue in places where I use the HTMLElement and InputHTMLAttributes types.

The only type still causing memory issues for me now is MouseEvent. See example:

const onClick = (event: MouseEvent) => {
  // do something
};

In any case, thank you for the quick alpha release! 🙏 Let me know if you need more details.

@Adamlb
Copy link

Adamlb commented Jul 22, 2024

@larsrickert We don't specifically pull in the types in our components yet but we are using shadcn and radix-vue which does.

If I give the build 8gb of ram, it does complete, and the most egregious file is full of repeated documentation around event things, so its likely the same thing as ericvel.

I will try and determine something more specific, but may not be able to get to it until this evening.

@larsrickert
Copy link
Contributor Author

@ericvel @Adamlb Thanks for your feedback! I fixed the out of memory issue only for props and exposed but forgot that you can also have complex types for event and slots (e.g. MouseEvent) which I guess causes the remaining issues that you have.

I created a follow up fix to apply the same fix also for events and slots: #28674

larsrickert added a commit to SchwarzIT/onyx that referenced this pull request Jul 30, 2024
Update Storybook to version `8.3.0-alpha.3` which includes a bug fix
which reduced the bundle size of our build Storybok from 26MB to 6MB and
reduced build time from 37s to 10s.

If you are interested, the bug was caused by the `vue-component-meta`
package which included ALL schema definitions for props, events, slots
and exposed so if e.g. `HTMLElement` was used, it included all nested
props, JSDocs etc. although they are not needed/used by Storybook, see
[Storybook PR](storybookjs/storybook#28589)
@Walnussbaer
Copy link

Walnussbaer commented Aug 22, 2024

Is there a working workaround for this problem? Since our upgrade to storybook 8.2.9 and using vue-component-meta, we cannot build storybook for production anymore.

I tried using storybook 8.3.0-alpha.8, but npm install reports conflicting peer dependencies (although I upgraded every storybook dependency we use to 8.3.0-alpha.8 - I guess that's why it's called alpha ^^)

UPDATE: build ist working now with 8.3.0-alpha.8 after setting the following in package.json

 "overrides": {
    "@storybook/preview-api": "8.3.0-alpha.8",
    "@storybook/vue3": "8.3.0-alpha.8"
  },

larsrickert added a commit to SchwarzIT/onyx that referenced this pull request Sep 11, 2024
Update Storybook to version 8.3.0-alpha.5 which includes a bug fix which
reduced the bundle size of our build Storybook from 26MB to 6MB and
reduced build time from 37s to 10s.

This change also significantly improves the loading performance of the
onyx Storybook.

If you are interested, the bug was caused by the vue-component-meta
package which included ALL schema definitions for props, events, slots
and exposed so if e.g. HTMLElement was used, it included all nested
props, JSDocs etc. although they are not needed/used by Storybook, see
[Storybook PR](storybookjs/storybook#28589)
@larsrickert
Copy link
Contributor Author

Is there a working workaround for this problem?
@Walnussbaer Hey, the issue should be fixed now. Can you try out the latest version 8.3.0-beta.5?

@Walnussbaer
Copy link

@larsrickert I just upgraded to the final release yesterday (8.3.0) and everything worked like a charm. We also had a bug in 8.3.0-alpha.8 that the controls for argTypes weren't created automatically, but this was also fixed with 8.3.0. So far, really good work. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
9 participants