[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F88MW18TWNXJP16DKTAK86":3,"skill-same:01M7F88MW18TWNXJP16DKTAK86":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7F88MW18TWNXJP16DKTAK86","component-refactoring",null,"Refactor high-complexity React components in Langflow frontend. Use when manual complexity assessment shows complexity > 50 or lineCount > 300, when the user asks for code splitting, hook extraction, or complexity reduction; avoid for simple\u002Fwell-structured components, third-party wrappers, or when the user explicitly wants testing without refactoring.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F06-前端与设计\u002Fcomponent-refactoring\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: component-refactoring\ndescription: Refactor high-complexity React components in Langflow frontend. Use when manual complexity assessment shows complexity > 50 or lineCount > 300, when the user asks for code splitting, hook extraction, or complexity reduction; avoid for simple\u002Fwell-structured components, third-party wrappers, or when the user explicitly wants testing without refactoring.\n---\n\n# Langflow Component Refactoring Skill\n\nRefactor high-complexity React components in the Langflow frontend codebase with the patterns and workflow below.\n\n> **Complexity Threshold**: Components with complexity > 50 (measured manually by counting conditionals, nesting levels, and lines) should be refactored before testing.\n\n## Quick Reference\n\n### Commands (run from `src\u002Ffrontend\u002F`)\n\n```bash\ncd src\u002Ffrontend\n\n# Lint with Biome\nnpm run lint\n\n# Type checking\nnpm run type-check\n\n# Run tests\nnpm test\n```\n\n### Manual Complexity Assessment\n\nSince Langflow does not have automated complexity analysis tools, assess components manually:\n\n1. **Count conditionals**: Each `if\u002Felse`, `switch\u002Fcase`, ternary, `&&`\u002F`||` chain adds +1.\n2. **Count nesting levels**: Each level of nesting within conditionals or loops adds +1.\n3. **Count total lines**: Target \u003C 300 lines per component file.\n4. **Count state hooks**: More than 5 `useState` calls suggests hook extraction.\n5. **Count effects**: More than 3 `useEffect` calls suggests effect consolidation.\n\n### Complexity Score Interpretation\n\n| Score | Level | Action |\n|-------|-------|--------|\n| 0-25 | Simple | Ready for testing |\n| 26-50 | Medium | Consider minor refactoring |\n| 51-75 | Complex | **Refactor before testing** |\n| 76-100 | Very Complex | **Must refactor** |\n\n## Core Refactoring Patterns\n\n### Pattern 1: Extract Custom Hooks\n\n**When**: Component has complex state management, multiple `useState`\u002F`useEffect`, or business logic mixed with UI.\n\n**Langflow Convention**: Place hooks in a `hooks\u002F` subdirectory or alongside the component as `use-\u003Cfeature>.ts`. Langflow uses kebab-case filenames with `use-` prefix.\n\n```typescript\n\u002F\u002F Before: Complex state logic in component\nconst FlowPage: FC = () => {\n  const [nodes, setNodes] = useState\u003CNode[]>([])\n  const [edges, setEdges] = useState\u003CEdge[]>([])\n  const [buildStatus, setBuildStatus] = useState\u003CBuildStatus>(BuildStatus.IDLE)\n\n  \u002F\u002F 50+ lines of state management logic...\n\n  return \u003Cdiv>...\u003C\u002Fdiv>\n}\n\n\u002F\u002F After: Extract to custom hook\n\u002F\u002F hooks\u002Fuse-flow-state.ts\nexport const useFlowState = (flowId: string) => {\n  const [nodes, setNodes] = useState\u003CNode[]>([])\n  const [edges, setEdges] = useState\u003CEdge[]>([])\n  const [buildStatus, setBuildStatus] = useState\u003CBuildStatus>(BuildStatus.IDLE)\n\n  \u002F\u002F Related state management logic here\n\n  return { nodes, setNodes, edges, setEdges, buildStatus, setBuildStatus }\n}\n\n\u002F\u002F Component becomes cleaner\nconst FlowPage: FC = () => {\n  const { nodes, setNodes, edges, setEdges } = useFlowState(flowId)\n  return \u003Cdiv>...\u003C\u002Fdiv>\n}\n```\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-add-component.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-unsaved-changes.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-refresh-model-inputs.ts`\n\n### Pattern 2: Extract Sub-Components\n\n**When**: Single component has multiple UI sections, conditional rendering blocks, or repeated patterns.\n\n**Langflow Convention**: Place sub-components in subdirectories or as separate files in the same directory. UI primitives go in `components\u002Fui\u002F`, domain components in `components\u002Fcore\u002F`, reusable components in `components\u002Fcommon\u002F`.\n\n```typescript\n\u002F\u002F Before: Monolithic JSX with multiple sections\nconst GenericNode = () => {\n  return (\n    \u003Cdiv>\n      {\u002F* 100 lines of header UI *\u002F}\n      {\u002F* 100 lines of parameter fields *\u002F}\n      {\u002F* 100 lines of output handles *\u002F}\n    \u003C\u002Fdiv>\n  )\n}\n\n\u002F\u002F After: Split into focused components\n\u002F\u002F CustomNodes\u002FGenericNode\u002F\n\u002F\u002F   generic-node.tsx       (orchestration only — kebab-case, descriptive name)\n\u002F\u002F   components\u002F\n\u002F\u002F     node-header.tsx\n\u002F\u002F     node-parameters.tsx\n\u002F\u002F     node-outputs.tsx\n\nconst GenericNode = () => {\n  return (\n    \u003Cdiv>\n      \u003CNodeHeader nodeData={data} \u002F>\n      \u003CNodeParameters fields={fields} \u002F>\n      \u003CNodeOutputs outputs={outputs} \u002F>\n    \u003C\u002Fdiv>\n  )\n}\n```\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002FCustomNodes\u002FGenericNode\u002Fcomponents\u002F`\n- `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcore\u002F`\n- `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fui\u002F`\n\n### Pattern 3: Simplify Conditional Logic\n\n**When**: Deep nesting (> 3 levels), complex ternaries, or multiple `if\u002Felse` chains.\n\n```typescript\n\u002F\u002F Before: Deeply nested conditionals\nconst getFieldComponent = (field: InputFieldType) => {\n  if (field.type === \"str\") {\n    if (field.multiline) {\n      return \u003CTextAreaComponent \u002F>\n    } else if (field.password) {\n      return \u003CPasswordInput \u002F>\n    } else if (field.options?.length) {\n      return \u003CDropdown options={field.options} \u002F>\n    } else {\n      return \u003CInputComponent \u002F>\n    }\n  } else if (field.type === \"int\") {\n    return \u003CIntComponent \u002F>\n  } else if (field.type === \"float\") {\n    return \u003CFloatComponent \u002F>\n  }\n  return null\n}\n\n\u002F\u002F After: Use lookup tables + early returns\nconst FIELD_COMPONENT_MAP: Record\u003Cstring, FC\u003CFieldProps>> = {\n  int: IntComponent,\n  float: FloatComponent,\n  bool: ToggleComponent,\n  code: CodeAreaComponent,\n}\n\nconst STR_VARIANT_MAP: Record\u003Cstring, FC\u003CFieldProps>> = {\n  multiline: TextAreaComponent,\n  password: PasswordInput,\n  options: Dropdown,\n}\n\nconst getFieldComponent = (field: InputFieldType) => {\n  if (field.type !== \"str\") {\n    const Component = FIELD_COMPONENT_MAP[field.type]\n    return Component ? \u003CComponent {...field} \u002F> : null\n  }\n\n  const variant = field.multiline ? \"multiline\"\n    : field.password ? \"password\"\n    : field.options?.length ? \"options\"\n    : \"default\"\n\n  const Component = STR_VARIANT_MAP[variant] ?? InputComponent\n  return \u003CComponent {...field} \u002F>\n}\n```\n\n### Pattern 4: Extract API\u002FData Logic\n\n**When**: Component directly handles API calls, data transformation, or complex async operations.\n\n**Langflow Convention**:\n- This skill is for component decomposition, not query\u002Fmutation design.\n- When refactoring data fetching, use `frontend-query-mutation` for query patterns, `UseRequestProcessor`, cache invalidation, and mutation error handling.\n- Do not create thin passthrough `useQuery` wrappers during refactoring; only extract a custom hook when it truly orchestrates multiple queries\u002Fmutations or shared derived state.\n- API hooks live in `controllers\u002FAPI\u002Fqueries\u002F{domain}\u002F`.\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Fflows\u002Fuse-post-add-flow.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Fvariables\u002Fuse-get-global-variables.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Ffolders\u002Fuse-get-folders.ts`\n\n### Pattern 5: Extract Modal\u002FDialog Management\n\n**When**: Component manages multiple modals with complex open\u002Fclose states.\n\n**Langflow Convention**: Modals should be extracted with their state management.\n\n```typescript\n\u002F\u002F Before: Multiple modal states in component\nconst FlowToolbar = () => {\n  const [showExportModal, setShowExportModal] = useState(false)\n  const [showShareModal, setShowShareModal] = useState(false)\n  const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)\n  const [showApiModal, setShowApiModal] = useState(false)\n  \u002F\u002F 5+ more modal states...\n}\n\n\u002F\u002F After: Extract to modal management hook\ntype ModalType = \"export\" | \"share\" | \"delete\" | \"api\" | null\n\nconst useFlowToolbarModals = () => {\n  const [activeModal, setActiveModal] = useState\u003CModalType>(null)\n\n  const openModal = useCallback((type: ModalType) => setActiveModal(type), [])\n  const closeModal = useCallback(() => setActiveModal(null), [])\n\n  return {\n    activeModal,\n    openModal,\n    closeModal,\n    isOpen: (type: ModalType) => activeModal === type,\n  }\n}\n```\n\n### Pattern 6: Extract Form Logic\n\n**When**: Complex form validation, submission handling, or field transformation.\n\n**Langflow Convention**: Extract form state and validation into hooks.\n\n```typescript\n\u002F\u002F Extract form validation and submission\nconst useFlowSettingsForm = (initialValues: FlowSettings) => {\n  const [values, setValues] = useState(initialValues)\n  const [errors, setErrors] = useState\u003CRecord\u003Cstring, string>>({})\n\n  const validate = useCallback(() => {\n    const newErrors: Record\u003Cstring, string> = {}\n    if (!values.name?.trim()) newErrors.name = \"Name is required\"\n    if (values.endpoint_name && !\u002F^[a-z0-9-]+$\u002F.test(values.endpoint_name)) {\n      newErrors.endpoint_name = \"Must be lowercase alphanumeric with hyphens\"\n    }\n    setErrors(newErrors)\n    return Object.keys(newErrors).length === 0\n  }, [values])\n\n  const handleChange = useCallback((field: string, value: any) => {\n    setValues((prev) => ({ ...prev, [field]: value }))\n  }, [])\n\n  return { values, errors, validate, handleChange }\n}\n```\n\n## Langflow-Specific Refactoring Guidelines\n\n### 1. Zustand Store Selectors\n\n**When**: Component reads many values from a Zustand store, causing unnecessary re-renders.\n\n```typescript\n\u002F\u002F Before: Selecting too many values\nconst Component = () => {\n  const flowStore = useFlowStore()\n  \u002F\u002F Component re-renders on ANY store change\n}\n\n\u002F\u002F After: Use individual selectors\nconst Component = () => {\n  const nodes = useFlowStore((state) => state.nodes)\n  const edges = useFlowStore((state) => state.edges)\n  \u002F\u002F Component only re-renders when nodes or edges change\n}\n```\n\n**Langflow Reference**: All stores in `src\u002Ffrontend\u002Fsrc\u002Fstores\u002F` follow this selector pattern.\n\n### 2. Custom Node Components\n\n**When**: Refactoring flow node components (`CustomNodes\u002FGenericNode\u002F`).\n\n**Conventions**:\n- Keep node logic in custom hooks\n- Extract parameter rendering to separate components\n- Use the existing `components\u002F` subdirectory for sub-components\n\n```\nCustomNodes\u002FGenericNode\u002F\n  generic-node.tsx             # Node registration and main render (kebab-case, NOT index.tsx)\n  components\u002F\n    handle-render.tsx           # Handle rendering\n    node-description.tsx        # Node description display\n    node-input-field.tsx        # Input field rendering\n    node-name.tsx               # Node name display\n    node-output-field.tsx       # Output field rendering\n    node-status.tsx             # Build status display\n```\n\n### 3. Flow Canvas Components\n\n**When**: Refactoring components related to the flow editor canvas.\n\n**Conventions**:\n- `@xyflow\u002Freact` v12 is the canvas library\n- Keep canvas event handlers separate from UI rendering\n- Use `useFlowStore` for flow state management\n- Use `useFlowsManagerStore` for multi-flow management\n\n### 4. API Query Hook Components\n\n**When**: Refactoring components that consume API data.\n\n**Conventions**:\n- Use existing query hooks from `controllers\u002FAPI\u002Fqueries\u002F`\n- Access `UseRequestProcessor` for new queries\u002Fmutations\n- Use query key arrays like `[\"useGetGlobalVariables\"]` for cache management\n- Cache invalidation belongs in mutation `onSettled` callbacks\n\n## Refactoring Workflow\n\n### Step 1: Assess Complexity\n\nManually count:\n- Total conditionals (if\u002Felse, switch, ternary, &&\u002F||)\n- Maximum nesting depth\n- Total lines of code\n- Number of useState\u002FuseEffect hooks\n- Number of distinct UI sections\n\n### Step 2: Plan\n\nCreate a refactoring plan based on detected features:\n\n| Detected Feature | Refactoring Action |\n|------------------|-------------------|\n| 5+ `useState` hooks with related state | Extract custom hook |\n| API calls in component body | Extract to query hook |\n| 3+ event handlers with logic | Extract event handlers to hook |\n| 300+ lines | Split into sub-components |\n| Deep conditional nesting (>3) | Simplify conditional logic |\n| Multiple modal states | Extract modal management |\n\n### Step 3: Execute Incrementally\n\n1. **Extract one piece at a time**\n2. **Run lint, type-check, and tests after each extraction**\n3. **Verify functionality before next step**\n\n```\nFor each extraction:\n  1. Extract code\n  2. Run: npm run lint\n  3. Run: npm run type-check\n  4. Run: npm test\n  5. Test functionality manually\n  6. PASS? -> Next extraction\n     FAIL? -> Fix before continuing\n```\n\n### Step 4: Verify\n\nAfter refactoring, re-assess complexity manually:\n\n- Target complexity \u003C 50\n- Target line count \u003C 300\n- Target max nesting depth \u003C= 3\n- Target max function length \u003C 30 lines\n\n## Common Mistakes to Avoid\n\n### Over-Engineering\n\n```typescript\n\u002F\u002F Too many tiny hooks\nconst useButtonText = () => useState(\"Click\")\nconst useButtonDisabled = () => useState(false)\nconst useButtonLoading = () => useState(false)\n\n\u002F\u002F Cohesive hook with related state\nconst useButtonState = () => {\n  const [text, setText] = useState(\"Click\")\n  const [disabled, setDisabled] = useState(false)\n  const [loading, setLoading] = useState(false)\n  return { text, setText, disabled, setDisabled, loading, setLoading }\n}\n```\n\n### Breaking Existing Patterns\n\n- Follow existing directory structures in `components\u002Fui\u002F`, `components\u002Fcore\u002F`, `components\u002Fcommon\u002F`\n- Maintain naming conventions (kebab-case files, PascalCase components)\n- Preserve export patterns for compatibility\n- Keep Zustand store selector patterns consistent\n\n### Premature Abstraction\n\n- Only extract when there is clear complexity benefit\n- Do not create abstractions for single-use code\n- Keep refactored code in the same domain area\n\n### Bypassing UseRequestProcessor\n\n- Do not call `useQuery` or `useMutation` directly for API calls\n- Always use the `UseRequestProcessor` pattern for consistency with retry and invalidation logic\n- See `frontend-query-mutation` skill for API hook patterns\n\n## References\n\n### Langflow Codebase Examples\n\n- **Hook extraction**: `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002F`\n- **Component splitting**: `src\u002Ffrontend\u002Fsrc\u002FCustomNodes\u002FGenericNode\u002Fcomponents\u002F`\n- **UI components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fui\u002F`\n- **Core components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcore\u002F`\n- **Common components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcommon\u002F`\n- **API query hooks**: `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002F`\n- **Zustand stores**: `src\u002Ffrontend\u002Fsrc\u002Fstores\u002F`\n\n### Related Skills\n\n- `frontend-query-mutation` - For API query and mutation patterns\n- `frontend-testing` - For testing refactored components\n","# Langflow Component Refactoring Skill\n\nRefactor high-complexity React components in the Langflow frontend codebase with the patterns and workflow below.\n\n> **Complexity Threshold**: Components with complexity > 50 (measured manually by counting conditionals, nesting levels, and lines) should be refactored before testing.\n\n## Quick Reference\n\n### Commands (run from `src\u002Ffrontend\u002F`)\n\n```bash\ncd src\u002Ffrontend\n\n# Lint with Biome\nnpm run lint\n\n# Type checking\nnpm run type-check\n\n# Run tests\nnpm test\n```\n\n### Manual Complexity Assessment\n\nSince Langflow does not have automated complexity analysis tools, assess components manually:\n\n1. **Count conditionals**: Each `if\u002Felse`, `switch\u002Fcase`, ternary, `&&`\u002F`||` chain adds +1.\n2. **Count nesting levels**: Each level of nesting within conditionals or loops adds +1.\n3. **Count total lines**: Target \u003C 300 lines per component file.\n4. **Count state hooks**: More than 5 `useState` calls suggests hook extraction.\n5. **Count effects**: More than 3 `useEffect` calls suggests effect consolidation.\n\n### Complexity Score Interpretation\n\n| Score | Level | Action |\n|-------|-------|--------|\n| 0-25 | Simple | Ready for testing |\n| 26-50 | Medium | Consider minor refactoring |\n| 51-75 | Complex | **Refactor before testing** |\n| 76-100 | Very Complex | **Must refactor** |\n\n## Core Refactoring Patterns\n\n### Pattern 1: Extract Custom Hooks\n\n**When**: Component has complex state management, multiple `useState`\u002F`useEffect`, or business logic mixed with UI.\n\n**Langflow Convention**: Place hooks in a `hooks\u002F` subdirectory or alongside the component as `use-\u003Cfeature>.ts`. Langflow uses kebab-case filenames with `use-` prefix.\n\n```typescript\n\u002F\u002F Before: Complex state logic in component\nconst FlowPage: FC = () => {\n  const [nodes, setNodes] = useState\u003CNode[]>([])\n  const [edges, setEdges] = useState\u003CEdge[]>([])\n  const [buildStatus, setBuildStatus] = useState\u003CBuildStatus>(BuildStatus.IDLE)\n\n  \u002F\u002F 50+ lines of state management logic...\n\n  return \u003Cdiv>...\u003C\u002Fdiv>\n}\n\n\u002F\u002F After: Extract to custom hook\n\u002F\u002F hooks\u002Fuse-flow-state.ts\nexport const useFlowState = (flowId: string) => {\n  const [nodes, setNodes] = useState\u003CNode[]>([])\n  const [edges, setEdges] = useState\u003CEdge[]>([])\n  const [buildStatus, setBuildStatus] = useState\u003CBuildStatus>(BuildStatus.IDLE)\n\n  \u002F\u002F Related state management logic here\n\n  return { nodes, setNodes, edges, setEdges, buildStatus, setBuildStatus }\n}\n\n\u002F\u002F Component becomes cleaner\nconst FlowPage: FC = () => {\n  const { nodes, setNodes, edges, setEdges } = useFlowState(flowId)\n  return \u003Cdiv>...\u003C\u002Fdiv>\n}\n```\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-add-component.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-unsaved-changes.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002Fuse-refresh-model-inputs.ts`\n\n### Pattern 2: Extract Sub-Components\n\n**When**: Single component has multiple UI sections, conditional rendering blocks, or repeated patterns.\n\n**Langflow Convention**: Place sub-components in subdirectories or as separate files in the same directory. UI primitives go in `components\u002Fui\u002F`, domain components in `components\u002Fcore\u002F`, reusable components in `components\u002Fcommon\u002F`.\n\n```typescript\n\u002F\u002F Before: Monolithic JSX with multiple sections\nconst GenericNode = () => {\n  return (\n    \u003Cdiv>\n      {\u002F* 100 lines of header UI *\u002F}\n      {\u002F* 100 lines of parameter fields *\u002F}\n      {\u002F* 100 lines of output handles *\u002F}\n    \u003C\u002Fdiv>\n  )\n}\n\n\u002F\u002F After: Split into focused components\n\u002F\u002F CustomNodes\u002FGenericNode\u002F\n\u002F\u002F   generic-node.tsx       (orchestration only — kebab-case, descriptive name)\n\u002F\u002F   components\u002F\n\u002F\u002F     node-header.tsx\n\u002F\u002F     node-parameters.tsx\n\u002F\u002F     node-outputs.tsx\n\nconst GenericNode = () => {\n  return (\n    \u003Cdiv>\n      \u003CNodeHeader nodeData={data} \u002F>\n      \u003CNodeParameters fields={fields} \u002F>\n      \u003CNodeOutputs outputs={outputs} \u002F>\n    \u003C\u002Fdiv>\n  )\n}\n```\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002FCustomNodes\u002FGenericNode\u002Fcomponents\u002F`\n- `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcore\u002F`\n- `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fui\u002F`\n\n### Pattern 3: Simplify Conditional Logic\n\n**When**: Deep nesting (> 3 levels), complex ternaries, or multiple `if\u002Felse` chains.\n\n```typescript\n\u002F\u002F Before: Deeply nested conditionals\nconst getFieldComponent = (field: InputFieldType) => {\n  if (field.type === \"str\") {\n    if (field.multiline) {\n      return \u003CTextAreaComponent \u002F>\n    } else if (field.password) {\n      return \u003CPasswordInput \u002F>\n    } else if (field.options?.length) {\n      return \u003CDropdown options={field.options} \u002F>\n    } else {\n      return \u003CInputComponent \u002F>\n    }\n  } else if (field.type === \"int\") {\n    return \u003CIntComponent \u002F>\n  } else if (field.type === \"float\") {\n    return \u003CFloatComponent \u002F>\n  }\n  return null\n}\n\n\u002F\u002F After: Use lookup tables + early returns\nconst FIELD_COMPONENT_MAP: Record\u003Cstring, FC\u003CFieldProps>> = {\n  int: IntComponent,\n  float: FloatComponent,\n  bool: ToggleComponent,\n  code: CodeAreaComponent,\n}\n\nconst STR_VARIANT_MAP: Record\u003Cstring, FC\u003CFieldProps>> = {\n  multiline: TextAreaComponent,\n  password: PasswordInput,\n  options: Dropdown,\n}\n\nconst getFieldComponent = (field: InputFieldType) => {\n  if (field.type !== \"str\") {\n    const Component = FIELD_COMPONENT_MAP[field.type]\n    return Component ? \u003CComponent {...field} \u002F> : null\n  }\n\n  const variant = field.multiline ? \"multiline\"\n    : field.password ? \"password\"\n    : field.options?.length ? \"options\"\n    : \"default\"\n\n  const Component = STR_VARIANT_MAP[variant] ?? InputComponent\n  return \u003CComponent {...field} \u002F>\n}\n```\n\n### Pattern 4: Extract API\u002FData Logic\n\n**When**: Component directly handles API calls, data transformation, or complex async operations.\n\n**Langflow Convention**:\n- This skill is for component decomposition, not query\u002Fmutation design.\n- When refactoring data fetching, use `frontend-query-mutation` for query patterns, `UseRequestProcessor`, cache invalidation, and mutation error handling.\n- Do not create thin passthrough `useQuery` wrappers during refactoring; only extract a custom hook when it truly orchestrates multiple queries\u002Fmutations or shared derived state.\n- API hooks live in `controllers\u002FAPI\u002Fqueries\u002F{domain}\u002F`.\n\n**Langflow Examples**:\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Fflows\u002Fuse-post-add-flow.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Fvariables\u002Fuse-get-global-variables.ts`\n- `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002Ffolders\u002Fuse-get-folders.ts`\n\n### Pattern 5: Extract Modal\u002FDialog Management\n\n**When**: Component manages multiple modals with complex open\u002Fclose states.\n\n**Langflow Convention**: Modals should be extracted with their state management.\n\n```typescript\n\u002F\u002F Before: Multiple modal states in component\nconst FlowToolbar = () => {\n  const [showExportModal, setShowExportModal] = useState(false)\n  const [showShareModal, setShowShareModal] = useState(false)\n  const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)\n  const [showApiModal, setShowApiModal] = useState(false)\n  \u002F\u002F 5+ more modal states...\n}\n\n\u002F\u002F After: Extract to modal management hook\ntype ModalType = \"export\" | \"share\" | \"delete\" | \"api\" | null\n\nconst useFlowToolbarModals = () => {\n  const [activeModal, setActiveModal] = useState\u003CModalType>(null)\n\n  const openModal = useCallback((type: ModalType) => setActiveModal(type), [])\n  const closeModal = useCallback(() => setActiveModal(null), [])\n\n  return {\n    activeModal,\n    openModal,\n    closeModal,\n    isOpen: (type: ModalType) => activeModal === type,\n  }\n}\n```\n\n### Pattern 6: Extract Form Logic\n\n**When**: Complex form validation, submission handling, or field transformation.\n\n**Langflow Convention**: Extract form state and validation into hooks.\n\n```typescript\n\u002F\u002F Extract form validation and submission\nconst useFlowSettingsForm = (initialValues: FlowSettings) => {\n  const [values, setValues] = useState(initialValues)\n  const [errors, setErrors] = useState\u003CRecord\u003Cstring, string>>({})\n\n  const validate = useCallback(() => {\n    const newErrors: Record\u003Cstring, string> = {}\n    if (!values.name?.trim()) newErrors.name = \"Name is required\"\n    if (values.endpoint_name && !\u002F^[a-z0-9-]+$\u002F.test(values.endpoint_name)) {\n      newErrors.endpoint_name = \"Must be lowercase alphanumeric with hyphens\"\n    }\n    setErrors(newErrors)\n    return Object.keys(newErrors).length === 0\n  }, [values])\n\n  const handleChange = useCallback((field: string, value: any) => {\n    setValues((prev) => ({ ...prev, [field]: value }))\n  }, [])\n\n  return { values, errors, validate, handleChange }\n}\n```\n\n## Langflow-Specific Refactoring Guidelines\n\n### 1. Zustand Store Selectors\n\n**When**: Component reads many values from a Zustand store, causing unnecessary re-renders.\n\n```typescript\n\u002F\u002F Before: Selecting too many values\nconst Component = () => {\n  const flowStore = useFlowStore()\n  \u002F\u002F Component re-renders on ANY store change\n}\n\n\u002F\u002F After: Use individual selectors\nconst Component = () => {\n  const nodes = useFlowStore((state) => state.nodes)\n  const edges = useFlowStore((state) => state.edges)\n  \u002F\u002F Component only re-renders when nodes or edges change\n}\n```\n\n**Langflow Reference**: All stores in `src\u002Ffrontend\u002Fsrc\u002Fstores\u002F` follow this selector pattern.\n\n### 2. Custom Node Components\n\n**When**: Refactoring flow node components (`CustomNodes\u002FGenericNode\u002F`).\n\n**Conventions**:\n- Keep node logic in custom hooks\n- Extract parameter rendering to separate components\n- Use the existing `components\u002F` subdirectory for sub-components\n\n```\nCustomNodes\u002FGenericNode\u002F\n  generic-node.tsx             # Node registration and main render (kebab-case, NOT index.tsx)\n  components\u002F\n    handle-render.tsx           # Handle rendering\n    node-description.tsx        # Node description display\n    node-input-field.tsx        # Input field rendering\n    node-name.tsx               # Node name display\n    node-output-field.tsx       # Output field rendering\n    node-status.tsx             # Build status display\n```\n\n### 3. Flow Canvas Components\n\n**When**: Refactoring components related to the flow editor canvas.\n\n**Conventions**:\n- `@xyflow\u002Freact` v12 is the canvas library\n- Keep canvas event handlers separate from UI rendering\n- Use `useFlowStore` for flow state management\n- Use `useFlowsManagerStore` for multi-flow management\n\n### 4. API Query Hook Components\n\n**When**: Refactoring components that consume API data.\n\n**Conventions**:\n- Use existing query hooks from `controllers\u002FAPI\u002Fqueries\u002F`\n- Access `UseRequestProcessor` for new queries\u002Fmutations\n- Use query key arrays like `[\"useGetGlobalVariables\"]` for cache management\n- Cache invalidation belongs in mutation `onSettled` callbacks\n\n## Refactoring Workflow\n\n### Step 1: Assess Complexity\n\nManually count:\n- Total conditionals (if\u002Felse, switch, ternary, &&\u002F||)\n- Maximum nesting depth\n- Total lines of code\n- Number of useState\u002FuseEffect hooks\n- Number of distinct UI sections\n\n### Step 2: Plan\n\nCreate a refactoring plan based on detected features:\n\n| Detected Feature | Refactoring Action |\n|------------------|-------------------|\n| 5+ `useState` hooks with related state | Extract custom hook |\n| API calls in component body | Extract to query hook |\n| 3+ event handlers with logic | Extract event handlers to hook |\n| 300+ lines | Split into sub-components |\n| Deep conditional nesting (>3) | Simplify conditional logic |\n| Multiple modal states | Extract modal management |\n\n### Step 3: Execute Incrementally\n\n1. **Extract one piece at a time**\n2. **Run lint, type-check, and tests after each extraction**\n3. **Verify functionality before next step**\n\n```\nFor each extraction:\n  1. Extract code\n  2. Run: npm run lint\n  3. Run: npm run type-check\n  4. Run: npm test\n  5. Test functionality manually\n  6. PASS? -> Next extraction\n     FAIL? -> Fix before continuing\n```\n\n### Step 4: Verify\n\nAfter refactoring, re-assess complexity manually:\n\n- Target complexity \u003C 50\n- Target line count \u003C 300\n- Target max nesting depth \u003C= 3\n- Target max function length \u003C 30 lines\n\n## Common Mistakes to Avoid\n\n### Over-Engineering\n\n```typescript\n\u002F\u002F Too many tiny hooks\nconst useButtonText = () => useState(\"Click\")\nconst useButtonDisabled = () => useState(false)\nconst useButtonLoading = () => useState(false)\n\n\u002F\u002F Cohesive hook with related state\nconst useButtonState = () => {\n  const [text, setText] = useState(\"Click\")\n  const [disabled, setDisabled] = useState(false)\n  const [loading, setLoading] = useState(false)\n  return { text, setText, disabled, setDisabled, loading, setLoading }\n}\n```\n\n### Breaking Existing Patterns\n\n- Follow existing directory structures in `components\u002Fui\u002F`, `components\u002Fcore\u002F`, `components\u002Fcommon\u002F`\n- Maintain naming conventions (kebab-case files, PascalCase components)\n- Preserve export patterns for compatibility\n- Keep Zustand store selector patterns consistent\n\n### Premature Abstraction\n\n- Only extract when there is clear complexity benefit\n- Do not create abstractions for single-use code\n- Keep refactored code in the same domain area\n\n### Bypassing UseRequestProcessor\n\n- Do not call `useQuery` or `useMutation` directly for API calls\n- Always use the `UseRequestProcessor` pattern for consistency with retry and invalidation logic\n- See `frontend-query-mutation` skill for API hook patterns\n\n## References\n\n### Langflow Codebase Examples\n\n- **Hook extraction**: `src\u002Ffrontend\u002Fsrc\u002Fhooks\u002F`\n- **Component splitting**: `src\u002Ffrontend\u002Fsrc\u002FCustomNodes\u002FGenericNode\u002Fcomponents\u002F`\n- **UI components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fui\u002F`\n- **Core components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcore\u002F`\n- **Common components**: `src\u002Ffrontend\u002Fsrc\u002Fcomponents\u002Fcommon\u002F`\n- **API query hooks**: `src\u002Ffrontend\u002Fsrc\u002Fcontrollers\u002FAPI\u002Fqueries\u002F`\n- **Zustand stores**: `src\u002Ffrontend\u002Fsrc\u002Fstores\u002F`\n\n### Related Skills\n\n- `frontend-query-mutation` - For API query and mutation patterns\n- `frontend-testing` - For testing refactored components\n",{"name":5,"description":7},"main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","06-前端与设计\u002Fcomponent-refactoring",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill component-refactoring",{"tool":38,"command":39},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill component-refactoring",{"tool":41,"command":42},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill component-refactoring","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F06-前端与设计\u002Fcomponent-refactoring\u002FSKILL.md",true,[46,52,56],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Fcomplexity-patterns.md","REFERENCE","参考文档",12933,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F06-前端与设计\u002Fcomponent-refactoring\u002Freferences\u002Fcomplexity-patterns.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"references\u002Fcomponent-splitting.md",17102,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F06-前端与设计\u002Fcomponent-refactoring\u002Freferences\u002Fcomponent-splitting.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Fhook-extraction.md",13097,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F06-前端与设计\u002Fcomponent-refactoring\u002Freferences\u002Fhook-extraction.md",[61,68,73,80,87,94],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],{"skillNo":69,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":19},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]