Skip to content

Hot Reload

Blushister edited this page May 12, 2026 · 4 revisions

Hot Reload

TesseraUI supports hot-reloading HTML and CSS templates from disk during development, eliminating the need to restart Minecraft after every UI change.


In-game reload command

The fastest way to reload templates is the /tessera reload command, available in-game:

/tessera reload

This clears the template cache. The next time any TesseraUI screen is opened, its template is re-read from disk.

Workflow:

  1. Open the screen with /tessera test-v23 (or your own screen)
  2. Edit the HTML or CSS file
  3. Run /tessera reload in chat
  4. Close and re-open the screen — changes appear instantly

Enabling automatic disk-watch (development)

For hands-free reloading, call TesseraHotReload.tryEnable(boolean devEnvironment) early in your mod's client initialization:

@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientSetup {

    @SubscribeEvent
    public static void onClientSetup(FMLClientSetupEvent event) {
        if (FMLEnvironment.dist == Dist.CLIENT) {
            TesseraHotReload.tryEnable(FMLEnvironment.production == false);
        }
    }
}

With hot-reload enabled, TesseraUI watches template files for changes and invalidates the cache automatically. This includes companion CSS files and CSS files referenced through <link rel="stylesheet" href="...">. Reopen the screen to see the updates.

Warning: Do not call TesseraHotReload.tryEnable(true) in production builds. It adds a file-watcher thread and uses disk I/O on every screen open.


Manual cache invalidation

You can also invalidate the entire cache programmatically:

TesseraHotReload.invalidateAll();

Then call rebuild() in your screen's init() method to re-render.


Security

Resource IDs passed to TesseraHotReload.resolveHtml(), resolveCss(), and linked stylesheet resolution are validated against the assets/ directory. Any path that would escape assets/ (e.g. a resourceId containing ../) throws a SecurityException. This prevents accidental or malicious access to files outside the watched asset tree.


Recommended development setup

@Override
protected void init() {
    // Always rebuild on init so pressing F3+T re-loads the screen too
    rebuild();
}

private void rebuild() {
    TesseraHotReload.invalidateAll();   // call only in dev builds
    root = TesseraTemplateRenderer.build(
        TesseraTemplate.load("yourmod:ui/my_screen"),
        model, handlers,
        px, py, pw, ph
    );
}

Clone this wiki locally