Lovable Works in Preview but Breaks on the Live URL
Preview looks fine but your live URL breaks — the cause is almost always one of a short list of deployment-layer problems: environment variables that exist in the editor but were never added to the production host, auth redirects still pointing to localhost, 404 errors on page refresh because the host is not configured for single-page app routing, or the pipeline is stuck serving an old commit instead of the latest code.
By Founder Name · Last verified: 2026-06-23
Why does my app work in Lovable preview but break on the live URL?
The Lovable editor preview runs in a sandboxed environment with your editor environment variables pre-loaded. Your live deployment runs on a hosting provider — Lovable Cloud, Vercel, Netlify, Cloudflare Pages — with only the environment variables you explicitly added there. If a variable exists in the editor but not in the production host, the deployed app will fail at any code path that depends on it, while the preview continues to work perfectly.
This is the **Vanishing Env-Var** — the most common cause of the preview-works-live-breaks failure pattern. The moment you publish to a custom domain or a separate hosting provider, the editor environment variables disappear. Every variable your app needs must be manually added in the hosting provider's settings panel.
The second most common cause is a stale deployment — the hosting provider is serving a build from an earlier commit while the editor preview reflects the current state. Check your deployment logs to confirm when the last production build ran and which commit it deployed.
| Symptom on Live URL | Root Cause | Self-fixable? |
|---|---|---|
| Blank screen on live URL, preview fine | Env vars missing in production host (VITE_SUPABASE_URL, etc.) | Yes — add vars in host settings, redeploy |
| Login redirects to localhost after deploy | Auth callback URL hardcoded to localhost in Supabase settings | Yes — update Site URL in Supabase auth config |
| 404 on every page refresh | SPA routing not configured — host serves files, not index.html fallback | Yes — add _redirects or vercel.json rewrite |
| Live URL serves old UI despite code changes | Stale deployment — pipeline not picking up latest commit | Yes — trigger manual redeploy, clear build cache |
| Oops! Something went wrong and we couldn't publish your site | Build error in production — check deployment log for exit code 1 | Sometimes — resolve TypeScript error, redeploy |
| App loads but Supabase calls all fail with 401 | VITE_SUPABASE_ANON_KEY missing or using wrong key in prod | Yes — verify key in host env vars matches Supabase project |
| Custom domain shows 'This site can't be reached' | DNS not propagated or A record pointing to wrong IP | Yes — verify DNS records match Lovable's required values |
How do vanishing environment variables break a live deployment?
Environment variables configured in the Lovable editor are not automatically propagated to your hosting provider. Every variable your app needs — Supabase URL and anon key, Stripe publishable and secret keys, any API endpoint URLs — must be added manually in the hosting provider's settings panel. The symptom is a runtime error on first load: the Supabase client fails to initialize, or the Stripe checkout throws an undefined key error.
- Open your hosting provider's dashboard and navigate to Environment Variables settings.
- Compare the list against the variables in your Lovable editor (Settings → Environment).
- Add any that are missing, being careful to use the production values — not development or test values.
- Trigger a new deployment after adding variables — most providers require a redeploy for changes to take effect.
- Check the deployment logs for any startup errors that reference undefined environment variables.
Why does login redirect to localhost in production?
Lovable-generated apps often configure the auth callback URL as `http://localhost:3000` during development. When you deploy to a real domain, the auth provider — Supabase, OAuth providers, or Stripe — redirects the user back to localhost after sign-in, which fails in production. This must be updated in both the auth provider settings and the app's environment variables.
- In your Supabase project, go to Authentication → URL Configuration.
- Update Site URL to your production domain (e.g. https://yourapp.com).
- Add your production domain to the Redirect URLs allow-list.
- Update the NEXT_PUBLIC_SITE_URL or equivalent environment variable in your hosting provider.
- For OAuth providers (Google, GitHub), update the authorized redirect URIs in their developer consoles.
- Redeploy and test the full sign-in flow on the live URL.
Why do I get 404 errors when I refresh a page on the live URL?
A 404 on page refresh is a classic single-page app deployment problem. The hosting provider tries to serve a file at the URL path — for example `/dashboard` — but that file does not exist on disk because the app uses client-side routing. The solution is to configure your hosting provider to serve the root index.html for all paths and let the JavaScript router handle the URL.
- For Netlify: add a _redirects file to your public folder with the line: /* /index.html 200
- For Vercel: add a vercel.json with rewrites that map all routes to /index.html.
- For Cloudflare Pages: enable the 'Single-page application' option in the Pages project settings.
- For Lovable Cloud: this should be handled automatically — if you see 404s, contact support.
- After adding the config file, redeploy and test navigation and refresh on a deep route.
What if the deployment is stuck serving an old commit?
Sometimes the deployment pipeline appears to succeed but the live site continues to serve an old version. This is the **Stale-Commit Deploy** — the build cache is stale, a deployment hook did not fire, or the CDN is serving a cached version of the old build. The fastest fix is to trigger a forced redeploy from scratch.
- In your hosting provider dashboard, find the Deployments list and check the most recent deployment's commit SHA.
- Compare it to the latest commit in your GitHub repository — they should match.
- If they do not match, check whether the GitHub integration is still connected and whether the deployment hook fired.
- Trigger a manual redeploy from the current HEAD commit, clearing the build cache if the option is available.
- After the new deployment completes, hard-refresh the live URL to bypass CDN caching.
How do I confirm the deployment fix is actually working?
After fixing a deployment issue, confirm the fix at the deployment and infrastructure level — not just the browser view. CDN edge caching and local browser caching can both show you a stale version of the site for minutes or hours after a successful redeploy, masking whether the underlying issue is resolved. These steps confirm the fix is genuine and the new build is actually live.
- Check the hosting provider's deployment log to confirm the new build used the latest commit SHA.
- Open the live URL in a private/incognito browser window to bypass local browser cache.
- Open DevTools (F12 → Console) on the live URL and confirm no red errors on load.
- Check the Supabase dashboard to confirm any data operations from the live URL are succeeding.
- Test the full auth flow on the live URL — sign up, sign in, and confirm no localhost redirects.
- Refresh a deep route directly (e.g. /dashboard) and confirm the app loads rather than returning 404.
Frequently asked questions
My Lovable preview looks perfect but the live URL shows a blank screen — where do I start?
How do I know if my latest code is actually deployed to the live URL?
Why does logging in on my live site send me back to localhost?
Should I migrate off Lovable Cloud to fix deployment problems?
How long does it take to fix a broken live deployment?
What environment variables do I need to add to my hosting provider for a Lovable app?
Why does my site show 'Oops! Something went wrong and we couldn't publish your site'?
Do I need to set up environment variables separately in Lovable and in my hosting provider?
My custom domain has been 'pending' for 48 hours — is that normal?
App down or leaking data? Get an expert on it within 24–48h.
Book a free 30-minute audit call. We'll diagnose what's wrong and tell you exactly what it costs to fix.