Files
ComfyUI_frontend/.storybook/CLAUDE.md
snomiao 451ef24ea6 [feat] Add Storybook setup and NodePreview story (#4861)
* [feat] Add Storybook setup and NodePreview story

- Install and configure Storybook v9.1.1 for Vue 3
- Set up Storybook configuration with Vite integration
- Add Pinia store support for Storybook environment
- Create comprehensive NodePreview.stories.ts with multiple node examples:
  - KSampler node (complex node with multiple inputs/outputs)
  - CLIP Text Encode node (simple text input node)
  - VAE Decode node (image processing node)
  - Example with long markdown description
- Configure project paths and aliases for Storybook
- Stories demonstrate various ComfyUI node types with realistic mock data
- Update tsconfig.eslint.json to include Storybook files
- Fix ESLint issues with imports and number precision
- Add Storybook ESLint plugin configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [feat] Improve Storybook configuration and setup

- Add comprehensive PrimeVue theme setup with ComfyUI preset
- Configure proper Vue app setup with Pinia stores, i18n, and services
- Remove unused onboarding addon from Storybook dependencies
- Improve Vite configuration with better chunking and alias resolution
- Add proper CSS imports and styling for ComfyUI components

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [docs] Add comprehensive Storybook documentation

- Add README.md explaining Storybook usage, benefits, and comparison with other tools
- Add CLAUDE.md with development guidelines for working with Storybook
- Include best practices, troubleshooting tips, and integration notes
- Address PR review feedback for better developer onboarding

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [refactor] Remove ts-expect-error comment from Storybook preview

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [bugfix] Fix TypeScript errors in Load3D components and GLTF test

- Fix type mismatches in Load3DScene eventConfig by casting string values to proper enum types (MaterialMode, CameraType, UpDirection)
- Fix Uint8Array vs ArrayBuffer type issues in GLTF test by using .buffer property
- Remove unused @ts-expect-error comment in Rectangle.ts

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [feat] Add Chromatic GitHub Action for Storybook visual testing

- Add automated visual regression testing for Storybook components
- Configure workflow to run on main branch and PRs
- Auto-accept changes on main branch for baseline updates
- Uses build-storybook script for optimized builds

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [docs] Add Chromatic documentation to Storybook README

- Document Chromatic visual testing integration
- Add information about automated testing workflow
- Include best practices for visual regression testing
- Explain how to view and manage test results

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(chromatic.yaml): restrict push branches to main only for better workflow management

* [feat] Rebase branch onto main and update Storybook configuration

- Rebase sno-storybook branch onto origin/main with latest changes
- Update .storybook/main.ts with additional plugins and component configuration
- Add icons and component resolvers for Storybook support
- Update .gitignore with new entries
- Regenerate package-lock.json after rebase conflicts

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* [bugfix] Fix TypeScript errors in SubgraphNode type checking

Add proper type validation for subgraph node selection before calling
SubgraphNode-specific methods. This prevents undefined values from being
passed to functions expecting SubgraphNode parameters.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(vite.config.mts): correct path alias for src directory to ensure proper resolution in the project
refactor(vite.config.mts): adjust templates proxy configuration for better readability and maintainability

* [feat] Remove bun.lock as it's now ignored

* [bugfix] Fix Storybook builder require() error by converting main.ts to main.mjs

- Convert .storybook/main.ts to main.mjs to resolve ES module compatibility
- Use dynamic imports instead of static imports to avoid require() errors
- Add .storybook directory to tsconfig.json includes
- Storybook build and dev server now work correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(storybook): replace main.mjs with main.ts for improved type safety and maintainability
fix(storybook): remove unused import map plugins in Storybook configuration to prevent potential issues
fix(storybook): update color palette store initialization to streamline code and improve readability

* [feat] Optimize Chromatic workflow with automated PR status comments

- Replace complex GitHub Script actions with edumserrano/find-create-or-update-comment@v3
- Add comprehensive PR comments showing Storybook build progress and results
- Include build metrics: components, stories, visual changes, and errors
- Add direct links to Chromatic builds and Storybook previews
- Reduce workflow complexity by ~60 lines while maintaining functionality
- Use native GitHub Actions expressions for cleaner maintainability

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(chromatic.yaml): move permissions section inside the chromatic-deployment job for better organization and clarity

* [fix] Resolve Vite CJS deprecation warning in Storybook config

- Use dynamic import for mergeConfig to avoid CJS build warning
- Replace static import with dynamic import in viteFinal function
- Maintain type safety with separate type import
- Fixes "The CJS build of Vite's Node API is deprecated" warning

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(chromatic.yaml): change edit-mode from replace to append to preserve existing comments in pull request

* [fix] Replace __dirname with process.cwd() in Storybook config

__dirname is not available in all environments. Using process.cwd()
provides better compatibility and resolves path issues in Storybook.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feature: storybook-setting (#5088)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jin Yi <jin12cc@gmail.com>
2025-08-18 20:05:28 -07:00

4.9 KiB

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

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:

// 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

// 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

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

# 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