Explore why Lovable misinterprets component importance and how to safeguard key parts with best practices to preserve components.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Lovable can misjudge a component’s importance because its chat-driven edits rely on limited static heuristics and the project context it sees in the editor. When usage is dynamic, indirect, or outside the usual entry points, Lovable’s analyzer may conclude a component is unused or low‑impact and remove or change it.
// Please analyze the repository edits and explain why specific components were removed/changed.
// Show file diffs, list static references, and give the most likely reason Lovable treated them as unused.
// For each path below, provide:
// - the diff showing what changed (file path + snippet)
// - all static references Lovable can find
// - which entry points (e.g., src/main.tsx, src/pages, server functions) include or omit the component
// - a short explanation of the heuristic that led to removal/change and a confidence level (low/med/high)
// Files to inspect (replace with exact paths if different):
// src/components/MyWidget.tsx
// src/components/Header/index.tsx
// src/pages/dashboard.tsx
// supabase/functions/webhook/index.ts
// Actions:
// 1) Show the repository diff for the edit that removed/modified these files.
// 2) For each listed file, list all references Lovable finds and explain any dynamic or indirect usage it could NOT statically verify.
// 3) Point out if a file is only referenced from tests/stories or absent from known entry points.
// 4) Give a concise reason why Lovable considered the component low-importance and a confidence level for that reason.
Please produce the analysis in clear sections per file.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
Add explicit preservation markers, a PRESERVE.md listing critical files, in-file comments and small exported flags, a short test that imports those flags, and a lightweight GitHub Actions check — then always include a “respect PRESERVE.md and in-file LOVABLE-PRESERVE markers” instruction in future Lovable prompts. Use Lovable Chat Mode edits to create/update these files, Preview to verify, and Publish or GitHub sync when pushing changes.
// Create a new file PRESERVE.md at the repository root with this exact content.
// This file is the single source-of-truth for critical files Lovable must NOT remove.
// Do not delete or rename this file unless the team explicitly requests it.
# PRESERVE - Critical files and components
# Lovable: Please do NOT delete or rename files listed here unless a separate change request is made.
# When editing, add a comment explaining why you changed a preserved file and keep the // LOVABLE-PRESERVE line.
src/components/CriticalWidget.tsx
src/lib/important.ts
// Add other critical file paths here, one per line.
// Open PRESERVE.md, read each file path, and for each existing file:
// 1) Add a top-of-file comment: // LOVABLE-PRESERVE: <filename>
// 2) Export a small flag constant: export const __lovable_preserve_<Identifier> = true;
// 3) If the file is TypeScript/JSX, keep the code valid and place the export near the top.
// Example change for src/components/CriticalWidget.tsx:
//
// // LOVABLE-PRESERVE: src/components/CriticalWidget.tsx
// export const __lovable_preserve_CriticalWidget = true;
//
// // existing imports and component code continue below...
//
// Do this for every path listed in PRESERVE.md. If a listed path does not exist, add a note back to me and do not create an empty placeholder without confirmation.
// Create tests/preserve.test.ts (or .tsx) with a simple import-based assertion.
// Use the project's test framework (if none, add a lightweight Jest devDependency and script).
//
// // tests/preserve.test.ts
// // Import each preserved export and assert it's truthy.
// import { __lovable_preserve_CriticalWidget } from '../src/components/CriticalWidget';
// import { __lovable_preserve_important } from '../src/lib/important';
//
// test('preserved exports exist', () => {
// expect(__lovable_preserve_CriticalWidget).toBe(true);
// expect(__lovable_preserve_important).toBe(true);
// });
//
// If the project already uses a different test runner, adapt to that runner. If you add devDependencies, update package.json scripts["test"] accordingly.
// Create .github/workflows/preserve-check.yml with a simple Node + test run.
// This ensures GitHub CI will catch accidental removals when code is pushed via GitHub sync.
//
// name: Preserve check
// on: [push, pull_request]
// jobs:
// preserve:
// runs-on: ubuntu-latest
// steps:
// - uses: actions/checkout@v4
// - name: Use Node
// uses: actions/setup-node@v4
// with:
// node-version: 18
// - name: Install
// run: npm ci
// - name: Run tests
// run: npm test --silent
//
// If your project uses yarn or pnpm, adapt the install/run commands.
// Create .lovable-instructions.md at repo root with this content:
//
// Lovable edit rules:
// - Always consult PRESERVE.md before making deletions/renames.
// - Never remove a file line listed in PRESERVE.md without a separate, explicit change request.
// - Respect // LOVABLE-PRESERVE comments inside files. If you must change a preserved file, add a comment explaining why and leave the preserve export in place.
// - When proposing deletion, create a separate PR and mention PRESERVE.md so humans can approve.
//
// Use these rules for all future Chat Mode edits.
Create explicit, importable references for the components (barrel exports and a dev-only showcase/registry), prefer named exports, keep a small dev route or registry that imports every important component, and use Lovable’s Chat Mode edits + Preview/Publish (or GitHub sync for heavy changes). These make components obvious to the editor, easy to refactor, and safe to ship from Lovable without needing a terminal.
Paste each prompt below into Lovable’s chat (Chat Mode). They tell Lovable exactly which files to create or update, and what to render. Use Preview to inspect changes, then Publish or GitHub sync for deeper workflows.
Paste into Lovable chat:
```text
// Create or update src/components/index.ts
// If a component file uses default export, convert it to a named export or wrap it here.
Please create src/components/index.ts with content that explicitly re-exports every component file in src/components. If any component currently has a default export, update that file to use a named export and adjust the export here. Example content:
// src/components/index.ts
// LOVABLE: explicit barrel for component discovery
export { Header } from "./Header";
export { Footer } from "./Footer";
export { Button } from "./Button";
// // Add any other existing components here
// If a file uses default export, patch that file to:
// export const ComponentName = () => { ... }
// // rather than export default ...
</li>
<li><b>Prompt: Add a dev-only Component Showcase page that imports each component</b>
Paste into Lovable chat:
```text
// Create src/dev/ComponentShowcase.tsx
// Create or update your router (src/App.tsx or src/routes) to add a route /__dev/components only in development.
Please create src/dev/ComponentShowcase.tsx with a minimal page that imports from src/components and renders placeholders for each component. Example:
// src/dev/ComponentShowcase.tsx
import React from "react";
import { Header, Footer, Button } from "../components";
export default function ComponentShowcase() {
return (
<div>
{/* DEV ONLY SHOWCASE */}
<h2>Component Showcase</h2>
<section><Header /></section>
<section><Button>Demo</Button></section>
<section><Footer /></section>
</div>
);
}
Then update src/App.tsx (or equivalent routes file) to add a route:
// update src/App.tsx in the <Routes> block to include:
{process.env.NODE_ENV === "development" && (
<Route path="/__dev/components" element={<ComponentShowcase />} />
)}
// Use Chat Mode file patches to add these changes.
Paste into Lovable chat:
```text
// Create docs/COMPONENTS.md
// Add a short list of components and where they’re used so maintainers (and Lovable edits) see intent.
Please create docs/COMPONENTS.md listing important components, their file paths, and pages that use them. Example lines:
Also add a small header comment to each key component file:
// src/components/Button.tsx
// PRESERVE: component used in MainLayout and login flows
// export const Button = ...
</li>
<li><b>Prompt: Use Preview and Publish, and use GitHub sync for large refactors</b>
Paste into Lovable chat:
```text
// Instruction for the human / Lovable assistant
// Preview changes in Lovable UI after the above patches. If everything looks correct, Publish.
// For multi-file or repo-wide renames, use GitHub sync/export so you can run CI or local scripts outside Lovable.
Please remind the user to Preview the edits inside Lovable, then Publish. If they need to run local build scripts or rename many files, create a GitHub commit via Lovable export/sync and instruct the user to run the build/test locally or CI.
Explicit exports and a dev showcase make component usage visible to both humans and Lovable’s code suggestions; that reduces accidental unseen refactors. Named exports and a registry/readme make refactors safer and easier to track. Finally, use Lovable’s Preview/Publish and GitHub sync for verification and larger changes that require terminal/CI outside Lovable.
From startups to enterprises and everything in between, see for yourself our incredible impact.
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.Â