Skip to content

Vue3: Use component's name as displayName if available#34008

Merged
Sidnioulz merged 5 commits into
nextfrom
fix/vue3_docgen
Mar 6, 2026
Merged

Vue3: Use component's name as displayName if available#34008
Sidnioulz merged 5 commits into
nextfrom
fix/vue3_docgen

Conversation

@huang-julien
Copy link
Copy Markdown
Contributor

@huang-julien huang-julien commented Mar 4, 2026

Closes #30455

What I did

Hey 👋 this PR makes the vue-component-meta plugin use the component's name if provided at runtime. By default, Vue will auto fill the __name property of the component, users usually define thename property directly

#33428

Checklist for Contributors

Testing

It seems like there's no unit test for vue=-component-meta plugin.

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

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

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

image

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-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 pull request has been released as version 0.0.0-pr-34008-sha-fc2f9bf0. Try it out in a new sandbox by running npx storybook@0.0.0-pr-34008-sha-fc2f9bf0 sandbox or in an existing project with npx storybook@0.0.0-pr-34008-sha-fc2f9bf0 upgrade.

More information
Published version 0.0.0-pr-34008-sha-fc2f9bf0
Triggered by @yannbf
Repository storybookjs/storybook
Branch fix/vue3_docgen
Commit fc2f9bf0
Datetime Wed Mar 4 10:51:49 UTC 2026 (1772621509)
Workflow run 22666159839

To request a new release of this pull request, mention the @storybookjs/core team.

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

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Component metadata now always includes a displayName derived from each component's name with an automatic fallback, merged into existing documentation metadata so prior info is preserved.
    • No changes to public/exported APIs or runtime behavior; this only adjusts how component documentation metadata is constructed and exposed.

@Sidnioulz Sidnioulz self-requested a review March 4, 2026 10:44
@Sidnioulz Sidnioulz added build Internal-facing build tooling & test updates ci:normal labels Mar 4, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 4, 2026

View your CI Pipeline Execution ↗ for commit 8fbf977

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 11m 20s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-05 18:04:07 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 46378e26-bcf9-4127-982b-61c0a32835a7

📥 Commits

Reviewing files that changed from the base of the PR and between 29fd7a5 and 8fbf977.

📒 Files selected for processing (1)
  • code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts

📝 Walkthrough

Walkthrough

Merge a computed displayName into each component's __docgenInfo using Object.assign (derived from name or __name), replacing direct metadata assignment; also replace catch (e) with a bare catch in one plugin file.

Changes

Cohort / File(s) Summary
Vue3 Docgen Plugins
code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts, code/frameworks/vue3-vite/src/plugins/vue-docgen.ts
Replace direct __docgenInfo assignment with Object.assign(__docgenInfo, { displayName }) to merge a displayName (from name or __name) into existing metadata. Also change catch (e) to a bare catch in vue-component-meta.ts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts`:
- Around line 138-140: The generated Object.assign currently places
${JSON.stringify(meta)} last which overwrites the runtime displayName so update
the assignment to preserve runtime names by merging meta first and then the
runtime displayName (use an empty object target to avoid mutating meta). In
other words, change the Object.assign call that builds ${name}.__docgenInfo so
it merges {}, ${JSON.stringify(meta)}, and then { displayName: ${name}.name ??
${name}.__name } (so displayName from name/__name takes precedence).

In `@code/frameworks/vue3-vite/src/plugins/vue-docgen.ts`:
- Around line 22-24: The generated assignment to _sfc_main.__docgenInfo
currently does Object.assign({ displayName: runtime }, metaData) so
metaData.displayName overwrites the runtime/user name; change the merge order so
metaData is applied first and the runtime displayName wins — i.e. create the
docgen object by Object.assign({}, ${JSON.stringify(metaData)}, { displayName:
_sfc_main.name ?? _sfc_main.__name }) (update the s.append call that constructs
_sfc_main.__docgenInfo accordingly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d65016f4-c4f9-4371-a25a-8f2532eef92e

📥 Commits

Reviewing files that changed from the base of the PR and between 33e2117 and fc2f9bf.

📒 Files selected for processing (2)
  • code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts
  • code/frameworks/vue3-vite/src/plugins/vue-docgen.ts

Comment thread code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts
Comment thread code/frameworks/vue3-vite/src/plugins/vue-docgen.ts
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Mar 5, 2026
@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to In Progress in Core Team Projects Mar 5, 2026
@Sidnioulz Sidnioulz merged commit 6640a12 into next Mar 6, 2026
123 of 126 checks passed
@Sidnioulz Sidnioulz deleted the fix/vue3_docgen branch March 6, 2026 16:39
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:normal

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Name from defineOptions in Vue 3 Component is ignored in the Documentation Show Code preview

3 participants