/lovable-issues

Customizing Component Names Generated by Lovable

Discover why component naming matters in Lovable prompts—learn to assign custom names and master best naming practices for clarity and efficiency.

Book a free  consultation
4.9
Clutch rating 🌟
600+
Happy partners
17+
Countries served
190+
Team members
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

Why Component Naming Must Be Defined in Lovable Prompts

A component name must be provided in the Lovable prompt because Lovable’s chat-first editor does not have a terminal or global refactor tools: explicit names give the chat engine a stable handle (file name, export identifier, header marker) so edits, previews, and future regenerations update the correct file instead of creating duplicates or breaking imports.

 

Why this is required

 

  • Stable file identity: Lovable edits files directly. If the prompt doesn't include a concrete component name, the generator may create a new file or a differently named export on each run, which breaks imports and routes.
  • Reliable edits across sessions: Chat-mode changes locate code by names/markers. Explicit names let Lovable find and patch the same component later (Preview and file diffs will target the right file).
  • Import & routing consistency: Build systems, routing files, and manual imports rely on file names and exported identifiers. Without an explicit name, generated code can mismatch those references and cause runtime errors after Publish or GitHub sync.
  • No CLI refactor available: You can’t run rename/refactor commands inside Lovable. That means automated renames that would be safe locally are risky in Lovable — you need the name upfront so edits remain additive and non-destructive.
  • Safer GitHub sync and deployments: Stable component names reduce merge conflicts and accidental duplicates when you export to GitHub and run CI outside Lovable.

 

Lovable prompts you can paste to implement enforcement (paste into Lovable chat)

 

// Prompt A: Add a Lovable component-name header to every component file so future chat edits can find and update the file.
// Task: For each React/Vue/Svelte component under src/components (example paths: src/components/*.tsx, src/components/**/*.tsx),
// add or correct the top-of-file marker comment: // LOVABLE_COMPONENT_NAME: ComponentName
// If the file already exports a default function/class/component, ensure the marker matches the exported identifier and update the file header only (do not rename files).
// Save edits as file diffs. List all files changed in the reply.

 

// Prompt B: Create a simple registry file to map LOVABLE_COMPONENT_NAME markers to paths.
// Task: Create or update src/components/registry.ts with an exported object listing each component marker and its relative file path.
// Do not change runtime logic beyond exporting the mapping. If any component files are missing the marker, add them as per Prompt A first.
// Show the exact content of src/components/registry.ts after changes and the list of modified files.

 

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

How to Assign Custom Names to Components in Lovable

Add a runtime display name and update the component’s exports/imports inside Lovable using chat edits: modify the component file to set Component.displayName, update your barrel export (e.g., src/components/index.ts), and ask Lovable to update import sites across the project. Then Preview to verify and Publish or sync to GitHub if you need local terminal work.

 

Step-by-step Lovable prompts to assign custom names

 

  • Add a displayName on the component file (single component) — Paste this prompt into Lovable to edit the component file directly.
// Please update src/components/Button.tsx
// Goal: give this component a custom public name "PrimaryButton" while keeping the filename.
// Replace the current component definition with the version below or insert the displayName assignment
// Do not change other unrelated code.

import React from 'react';

const Button: React.FC<{children?: React.ReactNode}> = ({ children }) => {
  return <button className="btn">{children}</button>;
};

// Set a runtime display name so dev tools and component registries see the custom name
Button.displayName = 'PrimaryButton';

export default Button;

 

  • Update the components barrel (single place import) — Ask Lovable to update src/components/index.ts so imports can use the custom name.
// Please update src/components/index.ts
// Ensure this file exports the component under the custom name "PrimaryButton"
// Create the file if it doesn't exist.

export { default as PrimaryButton } from './Button';

 

  • Refactor import sites across the project — Have Lovable perform a project-wide edit to replace old imports with the new named export. Use this prompt to change all import sites.
// Please search & replace across the repo (all src/** files):
// Replace imports that look like: import Button from '.../components/Button';
// With the new named export style: import { PrimaryButton } from '.../components';
// Also handle relative paths such as './components/Button' or '../components/Button'.
// Update usages from <Button ... /> to <PrimaryButton ... /> where applicable.

 

Quick verification and next steps

 

  • Preview — Use Lovable's Preview to run the app and verify the component renders and that React DevTools shows PrimaryButton.
  • Publish / GitHub sync — If the change touches many files or you want to run local tests, sync to GitHub from Lovable and complete the rest of the refactor locally (outside Lovable) — label that clearly as outside Lovable if you need a terminal.

 

Notes & practical tips

 

  • displayName is safe and low-risk — It doesn't require moving files; it's visible in DevTools and component registries. Use it when you want a UI-friendly name without changing public import paths.
  • Barrel exports control import names — Exporting as a named alias (export { default as PrimaryButton } from './Button') is the Lovable-friendly way to offer a new import name without renaming files.
  • Ask Lovable to apply project-wide edits — Use a search-and-replace prompt so Lovable performs safe, atomic file edits across the repo; then Preview to catch any missed references.

 

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Best Practices for Naming Components in Lovable

Use a consistent, descriptive naming convention (prefer PascalCase for React components), keep filenames matching the exported component name, prefer named exports with an index.ts re-export per folder, add displayName for wrapped/anonymous components, and use clear suffixes (e.g., Button.Primary or PrimaryButton) to express intent. These rules make imports predictable, improve editor/DevTools visibility in Lovable Preview, and reduce breakage when Lovable syncs to GitHub or you export to run codemods locally.

 

Practical guidance (what to change and why)

 

  • PascalCase component names and matching filenames — filename should be ExampleComponent.tsx and export a component named ExampleComponent.
  • One component per file — makes preview and patches easier in Lovable.
  • Use named exports and an index.ts re-export — simplifies refactors and keeps imports stable: import { ExampleComponent } from 'components/Example'.
  • Add displayName for HOCs or anonymous components — e.g., Wrapped.displayName = 'WithAuth(Wrapped)'; improves Preview and debugging.
  • Descriptive suffixes — use PrimaryButton vs ButtonPrimary if your team prefers, but be consistent across the repo.
  • Update routes and tests — ensure imports in src/pages, src/routes, and test files are updated.

 

Pasteable Lovable prompts (use Chat Mode edits / file diffs)

 

Prompt A — Apply PascalCase + filename = component name and add index re-exports across src/components

// Please scan src/components recursively and perform these changes.
// 1) For every component file that exports a React component, rename the file so the filename matches the component's PascalCase name.
// 2) Update the exported component declaration inside the file to use a named export matching the filename.
// 3) Create or update an index.ts in each component folder to re-export the named component.
// Apply safe text edits and update all imports across src/** to match the new names.
// Examples below show before/after and should guide the edits.

// Example BEFORE:
// src/components/button.tsx
// export default function button(props) { return <button {...props}/> }

// Example AFTER:
// src/components/Button/Button.tsx
// // export a named component whose name matches the file
// export function Button(props: any) { return <button {...props}/> }

// src/components/Button/index.ts
// export { Button } from './Button'

// Update imports:
// // BEFORE: import Button from 'src/components/button'
// // AFTER: import { Button } from 'src/components/Button'

Prompt B — Add displayName for wrapped or anonymous components

// Search for higher-order components or default-export anonymous functions in src/**.
// For each wrapped/default anonymous export, edit the file to add a named function or attach displayName.
// Example change to apply:

// BEFORE:
// export default withAuth((props) => { return <div/> })

// AFTER:
// function WrappedComponent(props: any) { return <div/> }
// WrappedComponent.displayName = 'WrappedComponent'
// export default withAuth(WrappedComponent)

// Make these edits in place for each matching file.

Prompt C — Update route and test imports

// After renames above, update any imports in these paths:
// - src/pages/**
// - src/routes/**
// - src/**/*.test.{ts,tsx}
// Replace old import paths like 'src/components/button' with '{ ComponentName } from "src/components/ComponentName"'
// Apply changes as project-wide text edits and show a preview of changed files before saving.

 

If this repo is very large and you expect many cross-file renames, note: large codemods may be easier outside Lovable. Use GitHub sync/export and run a codemod locally (outside Lovable, terminal required) — only do that if the in-Lovable preview shows too many conflicts.


Recognized by the best

Trusted by 600+ businesses globally

From startups to enterprises and everything in between, see for yourself our incredible impact.

RapidDev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with.

They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

Arkady
CPO, Praction
Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost.

He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Donald Muir
Co-Founder, Arc
RapidDev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space.

They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Mat Westergreen-Thorne
Co-CEO, Grantify
RapidDev is an excellent developer for custom-code solutions.

We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Emmanuel Brown
Co-Founder, Church Real Estate Marketplace
Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 

This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Samantha Fekete
Production Manager, Media Production Company
The pSEO strategy executed by RapidDev is clearly driving meaningful results.

Working with RapidDev has delivered measurable, year-over-year growth. Comparing the same period, clicks increased by 129%, impressions grew by 196%, and average position improved by 14.6%. Most importantly, qualified contact form submissions rose 350%, excluding spam.

Appreciation as well to Matt Graham for championing the collaboration!

Michael W. Hammond
Principal Owner, OCD Tech

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.