fix: await loadDoc, add empty render check, show stack trace

This commit is contained in:
Accusys
2026-05-18 11:46:55 +08:00
parent dc210b24c6
commit 4f35386bb1

View File

@@ -70,13 +70,15 @@ async function loadDoc(name) {
if (!resp.ok) throw new Error('HTTP ' + resp.status);
const md = await resp.text();
if (!wasm) throw new Error('WASM not initialized');
el.innerHTML = wasm.render(md);
document.querySelectorAll('.sidebar a.module-link').forEach(a => a.classList.remove('active'));
const link = document.querySelector('.sidebar a[data-module="' + name + '"]');
var html = wasm.render(md);
if (html.length === 0) throw new Error('WASM render returned empty HTML');
el.innerHTML = html;
document.querySelectorAll('.sidebar a.module-link').forEach(function(a) { a.classList.remove('active'); });
var link = document.querySelector('.sidebar a[data-module="' + name + '"]');
if (link) link.classList.add('active');
history.pushState(null, '', '#' + name);
} catch(e) {
el.innerHTML = '<p style="color:red">Error: ' + e.message + '</p>';
el.innerHTML = '<p style="color:red">Error: ' + e.message + '</p><pre style="font-size:12px;background:#f8f8f8;padding:8px">' + e.stack + '</pre>';
}
}
@@ -99,9 +101,9 @@ async function init() {
window.location.reload();
};
var hash = location.hash.slice(1);
loadDoc(hash || '01_auth');
await loadDoc(hash || '01_auth');
} catch(e) {
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p>';
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p><pre style="font-size:12px;background:#f8f8f8;padding:8px">' + e.stack + '</pre>';
}
}