Skip to content

[feat] Add Storybook setup and NodePreview story #4861

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

Merged
merged 20 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7be97b3
[feat] Add Storybook setup and NodePreview story
snomiao Aug 9, 2025
308b3cd
[feat] Improve Storybook configuration and setup
snomiao Aug 10, 2025
6244caf
[docs] Add comprehensive Storybook documentation
snomiao Aug 10, 2025
2b86f41
[refactor] Remove ts-expect-error comment from Storybook preview
snomiao Aug 11, 2025
88baf87
[bugfix] Fix TypeScript errors in Load3D components and GLTF test
snomiao Aug 12, 2025
799b760
[feat] Add Chromatic GitHub Action for Storybook visual testing
snomiao Aug 12, 2025
1411481
[docs] Add Chromatic documentation to Storybook README
snomiao Aug 12, 2025
1e93567
chore(chromatic.yaml): restrict push branches to main only for better…
snomiao Aug 12, 2025
ac37a5e
[feat] Rebase branch onto main and update Storybook configuration
snomiao Aug 13, 2025
cd787c5
[bugfix] Fix TypeScript errors in SubgraphNode type checking
snomiao Aug 13, 2025
cf4ab95
fix(vite.config.mts): correct path alias for src directory to ensure …
snomiao Aug 13, 2025
ceec83b
[feat] Remove bun.lock as it's now ignored
snomiao Aug 14, 2025
b2a97ee
[bugfix] Fix Storybook builder require() error by converting main.ts …
snomiao Aug 14, 2025
62747ec
chore(storybook): replace main.mjs with main.ts for improved type saf…
snomiao Aug 15, 2025
205f455
[feat] Optimize Chromatic workflow with automated PR status comments
snomiao Aug 15, 2025
a89b9e8
chore(chromatic.yaml): move permissions section inside the chromatic-…
snomiao Aug 15, 2025
74a83fa
[fix] Resolve Vite CJS deprecation warning in Storybook config
snomiao Aug 15, 2025
171d096
fix(chromatic.yaml): change edit-mode from replace to append to prese…
snomiao Aug 15, 2025
c877223
[fix] Replace __dirname with process.cwd() in Storybook config
snomiao Aug 16, 2025
26dbbb1
feature: storybook-setting (#5088)
viva-jinyi Aug 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/chromatic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: 'Chromatic'

# - [Automate Chromatic with GitHub Actions β€’ Chromatic docs]( https://www.chromatic.com/docs/github-actions/ )

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
chromatic-deployment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for Chromatic baseline

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Get current time
id: current-time
run: echo "time=$(date -u '+%m/%d/%Y, %I:%M:%S %p')" >> $GITHUB_OUTPUT

- name: Comment PR - Build Started
if: github.event_name == 'pull_request'
uses: edumserrano/find-create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '<!-- STORYBOOK_BUILD_STATUS -->'
comment-author: 'github-actions[bot]'
edit-mode: append
body: |
<!-- STORYBOOK_BUILD_STATUS -->
## 🎨 Storybook Build Status

πŸ”„ **Building Storybook and running visual tests...**

⏳ Build started at: ${{ steps.current-time.outputs.time }} UTC

---
*This comment will be updated when the build completes*

- name: Install dependencies
run: npm ci

- name: Build Storybook and run Chromatic
id: chromatic
uses: chromaui/action@latest
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
buildScriptName: build-storybook
autoAcceptChanges: 'main' # Auto-accept changes on main branch
exitOnceUploaded: true # Don't wait for UI tests to complete

- name: Get completion time
id: completion-time
if: always()
run: echo "time=$(date -u '+%m/%d/%Y, %I:%M:%S %p')" >> $GITHUB_OUTPUT

- name: Comment PR - Build Complete
if: github.event_name == 'pull_request' && always()
uses: edumserrano/find-create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '<!-- STORYBOOK_BUILD_STATUS -->'
comment-author: 'github-actions[bot]'
edit-mode: replace
body: |
<!-- STORYBOOK_BUILD_STATUS -->
## 🎨 Storybook Build Status

${{ steps.chromatic.outcome == 'success' && 'βœ…' || '❌' }} **${{ steps.chromatic.outcome == 'success' && 'Build completed successfully!' || 'Build failed!' }}**

⏰ Completed at: ${{ steps.completion-time.outputs.time }} UTC

### πŸ“Š Build Summary
- **Components**: ${{ steps.chromatic.outputs.componentCount || '0' }}
- **Stories**: ${{ steps.chromatic.outputs.testCount || '0' }}
- **Visual changes**: ${{ steps.chromatic.outputs.changeCount || '0' }}
- **Errors**: ${{ steps.chromatic.outputs.errorCount || '0' }}

### πŸ”— Links
${{ steps.chromatic.outputs.buildUrl && format('- [πŸ“Έ View Chromatic Build]({0})', steps.chromatic.outputs.buildUrl) || '' }}
${{ steps.chromatic.outputs.storybookUrl && format('- [πŸ“– Preview Storybook]({0})', steps.chromatic.outputs.storybookUrl) || '' }}

---
${{ steps.chromatic.outcome == 'success' && 'πŸŽ‰ Your Storybook is ready for review!' || '⚠️ Please check the workflow logs for error details.' }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ vite.config.mts.timestamp-*.mjs

# Linux core dumps
./core

*storybook.log
storybook-static

197 changes: 197 additions & 0 deletions .storybook/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Storybook Development Guidelines for Claude

## Quick Commands

- `npm run storybook`: Start Storybook development server
- `npm run build-storybook`: Build static Storybook
- `npm run test:component`: Run component tests (includes Storybook components)

## Development Workflow for Storybook

1. **Creating New Stories**:
- Place `*.stories.ts` files alongside components
- Follow the naming pattern: `ComponentName.stories.ts`
- Use realistic mock data that matches ComfyUI schemas

2. **Testing Stories**:
- Verify stories render correctly in Storybook UI
- Test different component states and edge cases
- Ensure proper theming and styling

3. **Code Quality**:
- Run `npm run typecheck` to verify TypeScript
- Run `npm run lint` to check for linting issues
- Follow existing story patterns and conventions

## Story Creation Guidelines

### Basic Story Structure

```typescript
import type { Meta, StoryObj } from '@storybook/vue3'
import ComponentName from './ComponentName.vue'

const meta: Meta<typeof ComponentName> = {
title: 'Category/ComponentName',
component: ComponentName,
parameters: {
layout: 'centered' // or 'fullscreen', 'padded'
}
}

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {
args: {
// Component props
}
}
```

### Mock Data Patterns

For ComfyUI components, use realistic mock data:

```typescript
// Node definition mock
const mockNodeDef = {
input: {
required: {
prompt: ["STRING", { multiline: true }]
}
},
output: ["CONDITIONING"],
output_is_list: [false],
category: "conditioning"
}

// Component instance mock
const mockComponent = {
id: "1",
type: "CLIPTextEncode",
// ... other properties
}
```

### Common Story Variants

Always include these story variants when applicable:

- **Default**: Basic component with minimal props
- **WithData**: Component with realistic data
- **Loading**: Component in loading state
- **Error**: Component with error state
- **LongContent**: Component with edge case content
- **Empty**: Component with no data

### Storybook-Specific Code Patterns

#### Store Access
```typescript
// In stories, access stores through the setup function
export const WithStore: Story = {
render: () => ({
setup() {
const store = useMyStore()
return { store }
},
template: '<MyComponent :data="store.data" />'
})
}
```

#### Event Testing
```typescript
export const WithEvents: Story = {
args: {
onUpdate: fn() // Use Storybook's fn() for action logging
}
}
```

## Configuration Notes

### Vue App Setup
The Storybook preview is configured with:
- Pinia stores initialized
- PrimeVue with ComfyUI theme
- i18n internationalization
- All necessary CSS imports

### Build Configuration
- Vite integration with proper alias resolution
- Manual chunking for better performance
- TypeScript support with strict checking
- CSS processing for Vue components

## Troubleshooting

### Common Issues

1. **Import Errors**: Verify `@/` alias is working correctly
2. **Missing Styles**: Ensure CSS imports are in `preview.ts`
3. **Store Errors**: Check store initialization in setup
4. **Type Errors**: Use proper TypeScript types for story args

### Debug Commands

```bash
# Check TypeScript issues
npm run typecheck

# Lint Storybook files
npm run lint .storybook/

# Build to check for production issues
npm run build-storybook
```

## File Organization

```
.storybook/
β”œβ”€β”€ main.ts # Core configuration
β”œβ”€β”€ preview.ts # Global setup and decorators
β”œβ”€β”€ README.md # User documentation
└── CLAUDE.md # This file - Claude guidelines

src/
β”œβ”€β”€ components/
β”‚ └── MyComponent/
β”‚ β”œβ”€β”€ MyComponent.vue
β”‚ └── MyComponent.stories.ts
```

## Integration with ComfyUI

### Available Context

Stories have access to:
- All ComfyUI stores (widgetStore, colorPaletteStore, etc.)
- PrimeVue components with ComfyUI theming
- Internationalization system
- ComfyUI CSS variables and styling

### Testing Components

When testing ComfyUI-specific components:
1. Use realistic node definitions and data structures
2. Test with different node types (sampling, conditioning, etc.)
3. Verify proper CSS theming and dark/light modes
4. Check component behavior with various input combinations

### Performance Considerations

- Use manual chunking for large dependencies
- Minimize bundle size by avoiding unnecessary imports
- Leverage Storybook's lazy loading capabilities
- Profile build times and optimize as needed

## Best Practices

1. **Keep Stories Focused**: Each story should demonstrate one specific use case
2. **Use Descriptive Names**: Story names should clearly indicate what they show
3. **Document Complex Props**: Use JSDoc comments for complex prop types
4. **Test Edge Cases**: Create stories for unusual but valid use cases
5. **Maintain Consistency**: Follow established patterns in existing stories
Loading