Agent Wranglers

APP-53Recommended

Recover when a new release replaces the old files

When a tab still runs the old release and a code chunk fails to load after a deploy, reload once to get the new release. Keep older files online as keep the previous build's assets sets.

How to do it

A tab opened before a deploy asks for chunk files that the new release may have removed. Catch failed dynamic imports, such as Vite's vite:preloadError event or webpack's ChunkLoadError, save any draft, and reload once. Store the reload time in sessionStorage, and skip a second reload within a minute, so a broken release can't loop. Also check the build version from a small endpoint and offer a reload when it changes.

Examples

TypeScript example

const RELOAD_FLAG = 'reloaded-for-release';

const RELOAD_GUARD_MS = 60_000;

addEventListener('vite:preloadError', event => {
  const lastReload = Number(sessionStorage.getItem(RELOAD_FLAG) ?? 0);
  if (Date.now() - lastReload < RELOAD_GUARD_MS) return;
  event.preventDefault();
  sessionStorage.setItem(RELOAD_FLAG, String(Date.now()));
  saveDrafts();
  location.reload();
});

Python example

import os

BUILD = os.environ["BUILD_ID"]

@app.get("/api/version")
def version():
    return {"build": BUILD}, 200, {"Cache-Control": "no-store"}

How to check

Deploy a release to staging, then click an in-app link in a tab opened before the deploy. The next screen loads, and the tab reloads at most once.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/resilience/new-release-reload">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.