Vendor a React component
Third-party components arrive with their own aliases, animation libraries, colours and assumptions. The job is to make them native to the host project, not to paste them in.
Workflow
- Confirm the host.
components.jsonpresent?@/alias →src/?cninsrc/lib/utils.ts? Tailwind config withdarkMode: ["class"]? If any is missing, set it up first (npx shadcn@latest init). - Put it where shadcn expects it.
src/components/ui/<kebab-name>.tsx. Named export + default export. One component per file; demos do NOT get copied — they become the usage snippet. - Fix imports before anything else.
@workspace/ui/lib/utils,~/lib/utils→@/lib/utilsmotion/react→framer-motionif that is what the project uses (or installmotiondeliberately — never both)react-icons→lucide-reactequivalents when lucide is already a dependency- drop
'use client'in Vite/React Router apps
- Type it. Replace
any/untyped props with an exportedXPropsinterface. Keep prop names from the original so the upstream docs stay valid. - Re-token colours. Hard-coded
#e5e7eb,bg-gray-200,text-white→ project tokens (bg-background,text-foreground, accent colour). A component that hard-codes a page colour for a masking trick must readhsl(var(--background))instead. - Contain global side effects. Inline
<style>blocks: prefix every class/keyframe with the component name so two instances or two components never collide. Filters with hard-coded SVG ids: hoist the<defs>once at app root and reference the id. - Respect the platform. Add
prefers-reduced-motionhandling, pause canvas/rAF loops when off-screen (IntersectionObserver) and whendocument.hidden, clean up every listener/interval in the effect return. - Wire it in using the usage example from the prompt, adjusted to the page's real data. Keep a
keyon previews that must re-run per selection. - Verify with the type-checker (
tsc --noEmit), lint, a production build, and a look at the rendered page at phone and desktop widths. Then add the component to the project's catalog/docs if one exists.
Traps
- Two Reacts: never add
reactas a dependency of a vendored package; "Invalid hook call" after an install is usually Vite's dep re-optimisation — restart the dev server before debugging. - Tailwind arbitrary values with parentheses (e.g.
[filter:drop-shadow(…)]) are often not emitted; use an inline style. - Framer-motion
whileInView, WAAPI and rAF do not advance in a background tab — verify via DOM/JS, not screenshots, when automating. - Components that open the camera/microphone: never per instance; one shared stream behind explicit consent.