Skip to content

Vue3: Add test for generic components with CSF factories#33685

Merged
shilman merged 1 commit into
nextfrom
kasper/csf-factories-generic-vue-components
Jan 28, 2026
Merged

Vue3: Add test for generic components with CSF factories#33685
shilman merged 1 commit into
nextfrom
kasper/csf-factories-generic-vue-components

Conversation

@kasperpeulen
Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen commented Jan 28, 2026

Related to #24238

What I did

This PR adds a unit test demonstrating that generic Vue components (using <script lang="ts" setup generic="T">) work correctly with CSF Next.

The key finding: With CSF Next, you can pass the type parameter directly:

const meta = preview.meta({
  component: GenericComponent<{ id: number; name: string }>,
});

const Story = meta.story({
  args: {
    items: [{ id: 1, name: 'John Doe' }],
    getLabel: (item) => item.name, // item is correctly typed!
  },
});

This addresses the long-standing issue #24238 where generic Vue components had type inference issues with traditional CSF3 (the generic type T would default to unknown).

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

No manual testing required - this PR adds a type-level unit test that verifies TypeScript inference works correctly with generic Vue components.

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 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 publish.yml --field pr=<PR_NUMBER>

This adds a unit test demonstrating that generic Vue components work
correctly with CSF factories by passing the type parameter directly:
`GenericComponent<{ id: number; name: string }>`.

This addresses issue #24238 where generic Vue components had type
inference issues with traditional CSF3.
@kasperpeulen kasperpeulen added build Internal-facing build tooling & test updates ci:normal labels Jan 28, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 28, 2026

View your CI Pipeline Execution ↗ for commit 35318b6

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 7m 17s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-28 11:30:47 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

Adds a new generic Vue 3 single-file component GenericComponent.vue that renders a selectable list and emits a 'select' event, updates a test file to import and type-check the generic component, and updates a test import to remove unused type names.

Changes

Cohort / File(s) Summary
New Vue 3 Component
code/renderers/vue3/src/__tests__/GenericComponent.vue
New generic Vue SFC (script setup with generic T). Renders an <ul> of items, uses getLabel(item) for labels, tracks selectedItem initialized from defaultSelected, and emits (e: 'select', item: T) when an item is clicked.
Test File Updates
code/renderers/vue3/src/csf-factories.test.ts
Removed unused type imports (ComponentAnnotations, StoryAnnotations) from 'storybook/internal/types'. Added GenericComponent import and new tests validating TypeScript generics for the component (including getLabel typing and items length); the new tests appear duplicated.
Documentation
docs/api/csf/csf-next.mdx
Added "How do I use generic Vue components?" section under CSF Next docs with a TypeScript example showing passing a generic type to a Vue component in CSF meta and typing args/getLabel.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


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

@kasperpeulen kasperpeulen added documentation and removed build Internal-facing build tooling & test updates labels Jan 28, 2026
@kasperpeulen kasperpeulen force-pushed the kasper/csf-factories-generic-vue-components branch from 5c8d2be to 35318b6 Compare January 28, 2026 11:21
@kasperpeulen kasperpeulen added build Internal-facing build tooling & test updates and removed documentation labels Jan 28, 2026
@shilman shilman merged commit e71f280 into next Jan 28, 2026
134 of 146 checks passed
@shilman shilman deleted the kasper/csf-factories-generic-vue-components branch January 28, 2026 11:51
@github-actions github-actions Bot mentioned this pull request Jan 28, 2026
24 tasks
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants