All posts

Buttons stop working after you deploy? Old files in open tabs

You ship an update. Then a customer writes: "I tapped the button and nothing happened", or "the page went blank". You open the app and everything works. That is the clue: it only happens to people who had the app open before the update, and a fresh tab can't show it. Vendor facts below come from their own docs, checked in November 2026.

Short answer: the open tab asks for page files from the old version, and your deploy removed them. Catch that one error and load the page again, once, with a guard so it can't loop. Don't let browsers cache index.html. Then test it with a tab that was open during a deploy.

Why it happens

Build tools like Vite split your app into files with hashed names, such as Pricing-3f9a1c.js. The name changes when the code changes, and a deploy replaces the old files with new ones. A tab that was open before the deploy still runs the old code. When someone taps a link, it asks for Pricing-3f9a1c.js, and that file is gone.

Then the host's single-page-app fallback steps in. Netlify's rewrite docs show the usual rule, /* /index.html 200, which will "effectively serve the index.html instead of giving a 404 no matter what URL the browser requests." The same page says: "By default, you can't shadow a URL that actually exists within the site." So real files load fine, and only missing files get the HTML page. The browser expected JavaScript, gets HTML, and the import fails. On a phone nobody sees the console, so the tap just does nothing. If the browser also kept an old copy of index.html, even the main file can be missing, and the page stays blank.

In the console, the error looks like this:

  • Chrome and Edge: Failed to fetch dynamically imported module
  • Safari: Importing a module script failed
  • Firefox: error loading dynamically imported module

I saw this on dizid.com on 10 November 2026, during a deploy. A tab opened before the deploy did nothing when Hire or a blog post was tapped. The old hashed page file was gone, Netlify's fallback answered with HTML instead of JavaScript, and the import failed. It's the other side of the rewrite rule from why an app works in the editor but breaks live.

The fix: load the page again, once

First, open package.json and look for vite. Lovable's FAQ says "Older apps use React + Vite and render in the browser"; apps created from May 13, 2026 (June 22 for Enterprise workspaces) use TanStack Start. For Bolt and Cursor projects, check the file too.

Vite has an event for this. Its build guide says: "Vite emits vite:preloadError event when it fails to load dynamic imports." It names this exact case: "When a new deployment occurs, the hosting service may delete the assets from previous deployments." Its example:

window.addEventListener('vite:preloadError', (event) => {
  window.location.reload() // for example, refresh the page
})

The guide adds: "make sure to set Cache-Control: no-cache on the HTML file, otherwise the old assets will be still referenced." Why a full reload and not a retry? Vite notes: "Older browsers require a page reload because they cache the failure in the module map." React's lazy() docs say "React will not call load more than once."

You can also catch it in the router, which knows where the user was going. Vue Router's onError handler runs for "errors occurred when trying to resolve an async component that is required to render a route". In React, when a lazy() page fails, "React will throw the rejection reason for the nearest Error Boundary to handle." React Router lets you give a route an ErrorBoundary (its guide), so you can check the message there.

Always add a loop guard. A file can also be missing for other reasons: a broken build, a blocked request, a bad connection. Then the fresh page fails too, reloads again, and the user is stuck in a loop. So remember when you last reloaded, and don't do it again within a few seconds. My approach on dizid.com (Vue Router), shortened:

// Reload once when a page file from an older deploy is gone.
const RELOAD_KEY = 'stale-chunk-reload-at'
const GUARD_MS = 10000 // no second reload within 10 seconds
const CHUNK_ERROR =
  /Failed to fetch dynamically imported module|Importing a module script failed|error loading dynamically imported module|Unable to preload CSS/i

function reloadOnce(url) {
  try {
    const last = Number(sessionStorage.getItem(RELOAD_KEY) || 0)
    if (Date.now() - last < GUARD_MS) return // just reloaded: stop
    sessionStorage.setItem(RELOAD_KEY, String(Date.now()))
  } catch {
    // sessionStorage blocked: reload anyway
  }
  window.location.assign(url)
}

// A page file failed to load: load the target page fully
router.onError((error, to) => {
  if (CHUNK_ERROR.test(error?.message || '')) reloadOnce(to.fullPath)
})

In a React or other Vite app, call reloadOnce(window.location.href) from the vite:preloadError listener instead. Use one of the two, not both.

I checked it with a simulated deploy. Before the fix, the tap stayed on the home page. After it, the tap landed on /hire with one reload. Then I added the same guard to seven of my sites; two already had it.

What your host does

Netlify. Once all files are uploaded, the deploy docs say "the new version of the site immediately goes live on the CDN." An open tab is suddenly one version behind. Netlify also has skew protection, "available on all plans", but today the docs list only Astro and Next.js as supported frameworks. Its default for static files is Cache-Control: public, max-age=0, must-revalidate, so browsers check index.html with the server each time. Keep that for the HTML.

Vercel. Its Skew Protection docs say it "is available on Enterprise and Pro plans" and works "by using version locking, which ensures client and server use the exact same version." The zero-configuration list is Next.js, SvelteKit, Qwik, Astro, Nuxt and React Router; a plain Vite single-page app is not on it. And "The default maximum age is 12 hours on Pro and one day on Enterprise, measured from when the deployment was created", so tabs on older deploys still need the reload.

Cloudflare Pages. Its serving docs say: "If your project does not include a top-level 404.html file, Pages assumes that you are deploying a single-page application." It then serves your root page "for any incoming path that does not correspond to a static asset", so a missing old file gets HTML there too.

Lovable and Bolt hosting: test it after your next update, as described below.

Cache rules: no long cache on index.html; a long cache only on hashed files. MDN's Cache-Control page shows max-age=31536000, immutable for hashed files in /assets/, and says: "Use a no-cache to make sure that the HTML response itself is not cached."

A second cause: an old service worker

If your app is installable (a PWA), its service worker can keep serving the old version from its cache. MDN's service worker guide says a new version "is installed in the background, but not yet activated. It is only activated when there are no longer any pages loaded that are still using the old service worker."

In vite-plugin-pwa, the registerType option decides what happens next. The default is 'prompt': you show a Refresh button in onNeedRefresh and call updateSW() when it's tapped; "the page will reload and the up-to-date content will be served." The other option, 'autoUpdate', updates without asking, but its docs warn "the user can lose data in any browser windows/tabs in which the application is open and is filling in a form." If your app has forms, keep the prompt. More in installable web app or App Store.

Test it before your users do

  1. Open the live site in a normal tab. Don't refresh it from now on.
  2. Change one word on 3 or 4 pages and deploy. Wait until it's live.
  3. Back in the old tab, tap through those pages. With the fix, you see one quick reload and land on the page you tapped. Without it, a tap does nothing.
  4. Check the developer tools console for the three errors above.

To test the guard without a deploy, use Chrome's request blocking. Open a page once, find its JS file in the Network tab, "right-click a request and select Block request". Go to the home page, reload, and tap the link to the blocked page. You should see one reload at most, never a loop. Turn blocking off afterwards.

Real users don't send you their console. Error tracking does: see uptime monitoring and error alerts. A rollback swaps the files too, so the same reload helps when you roll back a broken deploy.

Prompts for Lovable, Bolt or Cursor

  • "After a deploy, users with the app open tap links and nothing happens. On Vite's vite:preloadError event (or the router's error hook), if the message contains 'Failed to fetch dynamically imported module', 'Importing a module script failed' or 'error loading dynamically imported module', load the page again. Save the reload time in sessionStorage and never reload twice within 10 seconds. Change nothing else; tell me how to test it."
  • "Check what the live site returns for a JavaScript file that doesn't exist, like /assets/does-not-exist.js: status code, content type, and whether the single-page-app rewrite answers it with index.html. Also show me the cache headers for index.html and /assets/. Don't change anything yet."
  • "This app is a PWA. Show me which registerType vite-plugin-pwa uses. Keep the default 'prompt' and add a small banner: when onNeedRefresh fires, show 'A new version is available' with Refresh and Later buttons. Refresh calls updateSW(). Don't switch to autoUpdate, because users could lose what they typed in a form."

Checklist

  • A failed page-file import loads the page again, once.
  • A guard in sessionStorage stops a reload loop.
  • index.html has no long cache; only hashed files may have one.
  • You know what your host returns for a missing .js file, and whether your plan has skew protection.
  • A PWA shows an update prompt instead of silently serving the old version.
  • Tested with a tab that was open during a deploy, on 3 or 4 pages.
  • Tested with one page file blocked: one reload at most, no loop.
  • Error alerts are on, so you see these errors before customers write.

Want this fixed for you?

I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including taps that do nothing after an update. Send me the details and I'll reply within 24 hours.