Learn why v0 overwrites your manual code changes and discover effective tips and best practices to protect your custom logic.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Understanding Automatic Updates in v0
The Role of Auto-Generated Code
Why Manual Changes Might Be Lost
Example of Auto-Generated Code Section
/\* This section of code is auto-generated.
Manual modifications made here may be overwritten
during system updates to maintain consistency. \*/
function initialize() {
console.log("System initialized with default settings.");
}
Implications for Manual Customizations
Separate Generated Code from Your Manual Code
manual-changes.js
in your project’s main directory. This file will hold all the custom code you write manually.
// manual-changes.js
// Write your custom code here
function customFeature() {
console.log("This is a manual code change.");
}
// Export the custom function if you need to use it elsewhere
module.exports = { customFeature };
Link Your Manual Code to the Main Application File
app.js
or similar.
// app.js
// Import manual changes
try {
const manual = require('./manual-changes.js');
// Use your custom function as needed
manual.customFeature();
} catch (error) {
console.log("manual-changes.js not found or has errors.");
}
manual-changes.js
remain intact.
Protect Your Custom Code Using Guard Comments
app.js
file, mark an area for manual edits:
// BEGIN MANUAL EDITS - Do not remove or modify the markers below
/_ MANUAL CODE START _/
// Any manual overrides or additional configurations can be added here.
/_ MANUAL CODE END _/
// END MANUAL EDITS
Configure v0 to Skip Overwriting Manual Changes
v0-config.json
– and add the setting to prevent overwrites. For example:
{
"overwriteCustom": false,
"customCodeMarkers": {
"start": "/_ MANUAL CODE START _/",
"end": "/_ MANUAL CODE END _/"
}
}
v0-config.json
file in the root of your project so that the generator can detect your preferences before applying any updates.
Simulate Dependency Installation in Lovable
app.js
file like so:
// app.js
// Simulated dependency installation
try {
require.resolve("some-library");
} catch (e) {
console.log("Please ensure 'some-library' is available in your project.");
// You can add the library code manually or host it locally
}
Organize Your Code into Separate Areas
v0_generated
and manual
. This separation means that when v0 updates its files, only the files in the v0_generated
folder are replaced.project.config.js
in your project root with the following code:
module.exports = {
autoGenerated: './v0\_generated',
manual: './manual'
};
Insert Markers to Protect Manual Code Sections
// BEGIN MANUAL SECTION
// Add your custom code here. For example:
function customFunction() {
// Your custom logic
}
// END MANUAL SECTION
Use a Separate File for Manual Customizations
index.html
, you can create a custom.js
file inside the manual
folder that includes your manual logic. Link this file in index.html
so that your changes are applied without interfering with the auto‑generated code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Application</title>
</head>
<body>
<script src="./v0\_generated/app.js"></script>
<script src="./manual/custom.js"></script>
</body>
</html>
Configure v0 to Exclude Manual Files
v0.config.json
, modify it as follows:
{
"inputDir": "source",
"outputDir": "v0\_generated",
"ignore": [
"manual/\*\*",
"custom.js"
]
}
manual
folder and any file pattern specified, protecting your manual modifications.
Document Your Custom Code and Process
README_manual.txt
or README_MANUAL.md
if markdown is acceptable) in your project root. In this file, describe the locations of your manual code, the purpose of each file, and where the markers are placed. Documentation will help any developer understand that these sections should not be altered by automated processes.
Manual Code Locations:
- Manual custom code is in the "manual" folder.
- Inside auto-generated files, custom updates must be inserted between "BEGIN MANUAL SECTION" and "END MANUAL SECTION" markers.
- The configuration file "v0.config.json" has been updated to ignore manual folders.
Keep Your Custom Code and Generated Code in Sync
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.