Skip to content
Back to skills

Use Hot Reload

ASecurity

Edit, save, keep playing. The `blit386/vite` plugin (engine 1.4.0+) injects hot reload into the starter so method edits and `public/` asset edits update the running game instead of wiping state with a full page reload.

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
development

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add blit386/blit386 --skill use-hot-reload --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Use Hot Reload?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Use Hot Reload
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blit386-use-hot-reload/badge)](https://www.skillsdirectory.com/skills/blit386-use-hot-reload)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: use-hot-reload
description:
  Keep the game running while editing code or assets with the blit386/vite plugin, optional onHotReload state restore,
  and in-place sprite/audio/font hot-replace. Use when the user asks about hot reload, HMR, why the page reloads on
  save, how to keep score across edits, or how to live-update a PNG or sound without restarting.
---

# Use hot reload

Edit, save, keep playing. The `blit386/vite` plugin (engine 1.4.0+) injects hot reload into the starter so method edits
and `public/` asset edits update the running game instead of wiping state with a full page reload.

## How to do it

### 1. Confirm the Vite plugin

New scaffolds already have this. Older projects get it automatically from `npx blit migrate --write` or
`npx blit upgrade` (blit386 1.4.0+). Or add it by hand, then restart the dev server:

```js
import { defineConfig } from 'vite';
import { blit386 } from 'blit386/vite';

export default defineConfig({
  plugins: [blit386()],
});
```

Needs blit386 `^1.4.0`, and Vite 6.4.6 or newer for asset edits (on Vite 5 they are silently ignored). Production builds
skip the plugin (`apply: 'serve'`), so shipped games are unchanged.

### 2. Know which save you made

| Edit | What happens |
| --- | --- |
| `update()` / `render()` / module constants they use | Method swap - instance fields kept; `init()` does not re-run |
| `init()`, constructor, or class field initializers | Fresh instance + `init()`; optional `onHotReload` can restore fields |
| `configure()` hardware settings | Full page reload when a returned setting changes (display size, FPS, scroll capture, overlay flags). On engine 1.9.0+ that is every setting except `isSplashEnabled`, `splashColorDark` and `splashColorLight` |

### 3. Optional: restore state after a re-init

```js
onHotReload(context) {
    if (context.reason !== 'reinit' || !context.snapshot) {
        return;
    }
    if (typeof context.snapshot.score === 'number') {
        this.score = context.snapshot.score;
    }
}
```

Without this hook, a re-init still works - fields just reset to whatever the new `init()` sets. A failed `init()` leaves
the previous instance running.

A throw from `update()` or `render()` pauses the loop and logs the error once. The next save whose swap succeeds starts
the loop again (engine 1.9.0+), so tell the user to fix and save, not to reload the page. A fix inside `update()` or
`render()` is a method-only swap and keeps every field. A fix that also touches `init()`, the constructor, or a field
initializer is a re-init: fields reset unless `onHotReload` copies them across. One exception: a `BT.renderAt` call made
after the crash parks the loop, and a fixed save then installs the new code without restarting it. Call `BT.resume()` to
end the seek and run the game again.

### 4. Asset hot-replace

Files under `public/` (images, audio, `.btfont`) update in place. The sheets, sounds, and fonts your game already holds
stay valid. If a replaced image changes size, recompute any `srcRect` you cached - the sheet's size updates, but your
old rectangle does not.

## Notes

- You never call `registerHotReload` yourself - the plugin injects it.
- A browser event listener you add yourself with `this.onTap.bind(this)` keeps the old `onTap` after a save. Write
  `(event) => this.onTap(event)` instead, so it finds the new one. A re-init also leaves the old game's listeners
  attached, so remove them in the game or add them only once.
- Hot reload is local-dev only. It does nothing after `{{pmRunBuild}}`.
- See `docs/hot-reload.md` for the beginner walkthrough.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.