Ship features quickly, then deliberately refactor so components stay easy to maintain.
Use this skill when a component was expanded to land functionality and now mixes concerns (data parsing, state orchestration, rendering, modal UX, pointer math, timers, etc.).
Trigger Signals
A file grows past ~200 LOC.
One component manages multiple feature islands.
Repeated toolbar/action button markup appears in multiple places.
Event math (zoom/pan/drag) lives inline with UI markup.
Multiple timeout/reset effects exist without centralized cleanup.
Core Policy
Rough-in is acceptable for momentum.
Before finishing, refactor to trim and isolate responsibilities.
Keep parent component thin: detect mode and delegate.
Move interaction math/state into a hook (useX).
Move repeated control groups into small presentational components.
Keep each extracted file focused on one concern.
Add cleanup ownership
Centralize timeouts/subscriptions in the component or hook that creates them.
Ensure onCleanup clears timers and detaches stateful side effects.
Verify and size-check
Run pnpm type-check.
Re-check file sizes and keep components near/under 200 LOC when practical.
If one file remains larger, split one more layer (usually modal shell or action group).
Structural Patterns
Thin router component
Detect content type and render one of specialized children.
Behavior hook
Store + handlers + computed outputs for interaction-heavy logic.
Presentational controls
Stateless components for repeated button trays/toolbars.
Feature block component
Owns lifecycle and feature state, delegates controls and viewport math.
Guardrails
Do not change behavior while splitting unless required to fix a known issue.
Prefer additive extraction over in-place rewrites.
Keep props explicit and typed; avoid prop-shape ambiguity.
Preserve SSR/hydration-safe baseline markup for markdown-rendered content.
Done Criteria
Parent/orchestrator component is short and readable.
Interaction-heavy logic is not embedded in large JSX trees.
Repeated button groups are extracted.
Timer and async cleanup is explicit.
Type check passes.
Example Prompts
"Use component-trim-refactor on this oversized component after feature work."
"I roughed this in; now split it into thin router + feature blocks + hooks."
"Refactor this markdown renderer so each feature island is isolated and maintainable."
1---2name: component-trim-refactor3description: Component Trim Refactor4---56# Component Trim Refactor78## Goal910Ship features quickly, then deliberately refactor so components stay easy to maintain.1112Use this skill when a component was expanded to land functionality and now mixes concerns (data parsing, state orchestration, rendering, modal UX, pointer math, timers, etc.).1314## Trigger Signals1516- A file grows past ~200 LOC.17- One component manages multiple feature islands.18- Repeated toolbar/action button markup appears in multiple places.19- Event math (zoom/pan/drag) lives inline with UI markup.20- Multiple timeout/reset effects exist without centralized cleanup.2122## Core Policy23241. Rough-in is acceptable for momentum.252. Before finishing, refactor to trim and isolate responsibilities.263. Preserve behavior first; improve structure second.2728## Refactor Workflow29301. Stabilize current behavior31- Run a quick verify (`pnpm type-check`).32- Keep existing UX working before moving code.33342. Identify natural boundaries35- Router/orchestrator logic36- Feature-specific view (e.g., code block vs mermaid block)37- Interaction logic (zoom/pan/keyboard)38- Reusable presentational controls (action trays, header actions)39403. Split by responsibility41- Keep parent component thin: detect mode and delegate.42- Move interaction math/state into a hook (`useX`).43- Move repeated control groups into small presentational components.44- Keep each extracted file focused on one concern.45464. Add cleanup ownership47- Centralize timeouts/subscriptions in the component or hook that creates them.48- Ensure `onCleanup` clears timers and detaches stateful side effects.49505. Verify and size-check51- Run `pnpm type-check`.52- Re-check file sizes and keep components near/under 200 LOC when practical.53- If one file remains larger, split one more layer (usually modal shell or action group).5455## Structural Patterns5657- **Thin router component**58 - Detect content type and render one of specialized children.59- **Behavior hook**60 - Store + handlers + computed outputs for interaction-heavy logic.61- **Presentational controls**62 - Stateless components for repeated button trays/toolbars.63- **Feature block component**64 - Owns lifecycle and feature state, delegates controls and viewport math.6566## Guardrails6768- Do not change behavior while splitting unless required to fix a known issue.69- Prefer additive extraction over in-place rewrites.70- Keep props explicit and typed; avoid prop-shape ambiguity.71- Preserve SSR/hydration-safe baseline markup for markdown-rendered content.7273## Done Criteria7475- Parent/orchestrator component is short and readable.76- Interaction-heavy logic is not embedded in large JSX trees.77- Repeated button groups are extracted.78- Timer and async cleanup is explicit.79- Type check passes.8081## Example Prompts8283- "Use component-trim-refactor on this oversized component after feature work."84- "I roughed this in; now split it into thin router + feature blocks + hooks."85- "Refactor this markdown renderer so each feature island is isolated and maintainable."
Run npx skillmds@latest add byronwall/component-trim-refactor in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Component Trim Refactor It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
byronwall (@byronwall) published this skill. Their other Agent Skills are listed on their SkillMD profile.