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.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Use Hot Reload?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blit386-use-hot-reload)
---
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.