fix(js): expose runtime API before startup

Assign window.hemx before startup side effects so constrained browser contexts can still inspect the runtime and root state even if bootstrap work reports errors.

req: runtime/002
This commit is contained in:
slhx agent
2026-06-05 20:25:58 +02:00
parent ce4c2e086d
commit 4b83169207
2 changed files with 31 additions and 6 deletions
+15 -6
View File
@@ -791,11 +791,20 @@
function start() {
roots().forEach((root) => {
bootstrapState(root);
bindRoot(root);
bindSse(root);
try {
bootstrapState(root);
bindRoot(root);
bindSse(root);
} catch (error) {
emit(root, "hemx:error", String(error));
}
});
history.replaceState(history.state || { hemx: true }, "", location.href);
try {
history.replaceState(history.state || { hemx: true }, "", location.href);
} catch (error) {
const root = roots()[0];
if (root) emit(root, "hemx:history-error", String(error));
}
}
addEventListener("popstate", () => {
@@ -803,8 +812,8 @@
if (root) navigateUrl(location.href, root, "none").catch((error) => emit(root, "hemx:error", String(error)));
});
window.hemx = Object.freeze({ runtimeAbiVersion, roots, rootOf, applyHtml, applyBatch, decodeBatch, atomValue, decodeAtomState });
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start);
else start();
window.hemx = Object.freeze({ runtimeAbiVersion, roots, rootOf, applyHtml, applyBatch, decodeBatch, atomValue, decodeAtomState });
})();