Fixing Lovable's live preview
I can’t pinpoint when it started, but around the app’s publication, the live preview function in Lovable’s editor began to fail. It kept loading for several minutes, then reported an error. I didn’t succeed in getting the agent to find a solution. It eventually concluded it was an environment issue and advised me to contact support. The issue didn’t affect local builds, pop-out previews or the live site. What proved most annoying was that while the live preview was loading, communication with the agent was also blocked, and I couldn’t deploy updates.
In the reply from support I was told that the repository is quite large which causes the preview to time out. I had a feeling this was going to be about the images I inherited over from WordPress. As a quick fix I copied the wp-content folder to the new repository so that the linked images in old posts would not break. During development, I had these images cleaned up for duplicates — WordPress created several sizes of the same image — and had them uploaded to the bucket in their rightful place. I later deleted the folder — not realizing the images would remain in the .git folder as assets, totaling about 2 gigabytes.
My first approach was to remove the commit that contained the upload of these images, hoping that this would reduce the size of the repository. I researched interactive rebase and tried to drop the relevant commits. The hardest part was that the command used vi, so I had the age-old experience of learning to navigate it. 😅
Unfortunately this did not end up helping, the repository remained the same size and the preview was still loading endlessly. Next, I tried Git Filter-Repo on the recommendation of GPT-5. It definitely seemed intimidating, and the fact that it refused to run on the original repo wasn’t encouraging:
❯ git filter-repo --path wp-content --path public/wp-content --invert-paths
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
(expected freshly packed repo)
Please operate on a fresh clone instead. If you want to proceed
anyway, use --force.
I cloned the repository and started a dry run, which succeeded. After taking a deep breath, I ran it on the original repository — and it seemed to work. One small scare followed when the command removed the 'origin' remote. I had skipped the notice about this and thought I broke something. After re-adding origin and pushing to remote, Lovable rewrote history on its side, fixing the live preview. Now, I have a conveniently small repository, as it’s supposed to be:
❯ git count-objects -vH
count: 9
size: 36.00 KiB
in-pack: 1208
packs: 1
size-pack: 891.54 KiB
prune-packable: 0
garbage: 0
size-garbage: 0 bytes
Lesson: Don’t upload gigabytes of assets to repositories.