Skip to content

API HotPatch

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

HotPatch

Runtime hot patch API for replacing or incrementally updating modules.

Script API Reference

Overview

HotPatch is a static object that applies new script source to a module while the domain is running. It is available only when the host enables hot reload.

The two methods differ in how they treat the target module:

  • replace clears the existing members of the target module, then applies the new source.
  • incremental keeps the existing members and adds or overwrites only what the patch declares.

Both methods accept the target module either implicitly (the current module) or explicitly by path.

Caution

Top-level code in the patch executes while the patch is applied. Use HotPatch only with trusted script sources and a validated module graph.

Methods

HotPatch.replace(...)

Signatures

HotPatch.replace(script: string, ignoreDepends?: boolean)
HotPatch.replace(modulePath: string, script: string, ignoreDepends?: boolean)

Parameters

Name Type Required Description
modulePath string No Target module path. Omitting it patches the current module. A relative value resolves from the current module FullPath directory.
script string Yes Complete replacement source for the target module.
ignoreDepends boolean No Whether dependency updates are ignored.

Returns

null.

Behavior

Existing members of the target module are cleared before the new source is applied, so anything the patch omits disappears.

Example

@module(MAIN);

export func replaceSelf() {
    HotPatch.replace("@module(MAIN); export func run() { return 42; }");
    return 0;
}
HotPatch.replace("./feature", "@module(FEATURE); export func run() { return 1; }");

HotPatch.incremental(...)

Signatures

HotPatch.incremental(script: string, ignoreDepends?: boolean)
HotPatch.incremental(modulePath: string, script: string, ignoreDepends?: boolean)

Parameters

Name Type Required Description
modulePath string No Target module path. Omitting it patches the current module. A relative value resolves from the current module FullPath directory.
script string Yes Incremental patch source.
ignoreDepends boolean No Whether dependency updates are ignored.

Returns

null.

Behavior

Existing members are retained. Declarations in the patch are added, and a declaration that already exists is overwritten.

Example

HotPatch.incremental("export func added() { return 7; }");
HotPatch.incremental("./feature", "export func refresh() { return true; }");

Clone this wiki locally