← Back to Usage Guide Index
Mounting is not the same as loading. Loading/unloading retrieves packages, resolves dependencies, and manages module/asset registries. Mounting/unmounting injects or removes concrete DOM elements described by package mount assets.
The Mount Manager consumes assets of type
mount(JSON configs), injects their DOM nodes, and tracks them so corresponding unmount calls can cleanly remove them. It works via the#runner.mount/#runner.unmounthandlers you attach toload()/unload().
- During load: call
#runner.mountin youronLoadhandlers to auto‑inject HTML/DOM assets. - During unload: call
#runner.unmountinonDoneto remove previously injected nodes. - Package‑scoped mounting (planned/now supported): target specific package IDs when mounting/unmounting.
- Discover mount assets. The manager queries the bootstrapper for all assets with
type: "mount", producing an id→entry map. - Inject DOM nodes. For each asset’s
items[], it calls the DOM injector with selector, method, container, and attributes to create and place nodes. - Track for teardown. Injected nodes are registered in a DOM registry, grouped by package ID, so later unmount can remove them by group.
Current code path (simplified):
injectAssets()→inject()(resolve per‑package asset + call DOM injector) →track()(group by pkgId).
A mount asset is a JSON config with an items array. Each item describes how to inject one node.
// Minimal conceptual schema for a mount item
{
id: string, // required: local asset ID (must exist in the package)
selector?: string, // CSS selector to target; default: 'body'
container?: string, // wrapper tag name: 'div' | 'section' | 'style' | 'template' | ...
method?: string, // 'replace' | 'before' | 'after' | 'prepend' | 'append' (default: 'append')
dissolve?: boolean, // if true and wrapper has one child, replace wrapper with its child
attrs?: object // HTML attributes to apply to the wrapper
}The runtime resolves the package‑local **asset **`` and hands its content to the DOM injector with the above placement options.
Mount all eligible type:"mount" assets.
- Default behavior: inject all
mountassets for the relevant packages. - Tracking: nodes are recorded in the DOM registry under their package group for later removal.
Remove previously injected nodes.
- Default behavior (legacy builds): clear the DOM registry (global).
- Planned/updated behavior: unmount by package ID (or set of IDs), leaving other packages’ nodes intact.
We support (or are introducing) package‑scoped mounting/unmounting. Use one of the following patterns:
Pass target packages in the options object (accessible to handlers via ctx.options).
await bootstrap.load(resources,
[
{ fn: "#runner.mount" } // handler sees ctx.options.mount.packages
],
null,
{
mount: { packages: ["scene:chess", "allpurposemounter"] }
}
);
await bootstrap.unload(
["scene:chess"],
[ { fn: "#runner.unmount" } ],
null,
{ mount: { packages: ["scene:chess"] } }
);If/when #mount.* accepts inline args on the handler:
const onLoad = [
{ fn: "#runner.mount", args: { packages: ["scene:chess"] } }
];
const onDone = [
{ fn: "#runner.unmount", args: { packages: ["scene:chess"] } }
];Both approaches result in per‑package injection/teardown rather than global effects.
const onLoad = ["#runner.mount"]; // auto‑inject mount assets from loaded packages
await bootstrap.load(resources, onLoad, ["jobFail"], {
hooks: true,
mount: { packages: ["scene:chess"] } // optional narrowing
});await bootstrap.unload(
["scene:chess"],
["#runner.unmount"], // remove nodes injected for this package
["jobFail"],
{ mount: { packages: ["scene:chess"] } }
);- Selector defaults: if
selectoris omitted, elements are appended todocument.body. - Per‑package lookups: injected items resolve using the package‑scoped asset registry; a missing local id logs a warning.
- Registry semantics: nodes are tracked with
group = pkgIdso unmount can target a specific package. - Legacy behavior: older builds call
registry.clear(null, true)on unload (clears broadly); newer behavior targets groups.
-
Nothing appears in the DOM
- Confirm you shipped an asset of
type: "mount"and itscontent.body.itemsarray is present. - Verify the local
idmatches an asset in the package.
- Confirm you shipped an asset of
-
Unmount removed too much
- Ensure you’re passing
packages: [...]viaoptions.mount(or handler args) so only that package’s nodes are cleared.
- Ensure you’re passing
-
Selector conflicts
- Use a more precise
selectorandcontainer, or setattrswith uniqueid/classvalues.
- Use a more precise
Related Topics
- Loading Packages — attach
#runner.mountinonLoad - Mounting & Unmounting Packages — attach
#runner.unmountinonDone - Hooks & Handlers — handler forms &
functionResourceObject - Package & Repo Specifications — asset definitions & function resource objects