fix: append main before insertBefore in dashboard buildDashboard (fixes #166)

buildDashboard() called root.insertBefore(shellHeader, main) before main was
a child of root, throwing NotFoundError and aborting the dashboard plugin
init, which blocked Ctrl+K and the browser chat input. Append main to root
first so it is a valid reference node for the guarded header insert.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
MervinPraisonandClaude committed 2026-06-26 06:19:37 +00:00
1 parent 0b62e7dcec
commit 11898f2c7d
2 files changed
+51 -1

No files matched your search

@@ -1302,11 +1302,11 @@ async function buildDashboard() {
root.appendChild(sidebar);
setupMobileNav(root, sidebar);
}
root.appendChild(main);
const shellHeader = document.createElement('div');
shellHeader.id = 'db-shell-header-slot';
renderSlot('shell:header', shellHeader);
if (shellHeader.children.length) root.insertBefore(shellHeader, main);
root.appendChild(main);
// Resolve initial page from URL path or default to first page
const pathId = location.pathname.replace(/^\//, '') || '';
+50
View File
@@ -0,0 +1,50 @@
"""Regression tests for #166 — buildDashboard() insertBefore NotFoundError.
buildDashboard() called `root.insertBefore(shellHeader, main)` before `main`
was a child of `root`, violating the DOM contract and throwing
NotFoundError. That aborted the dashboard plugin init, blocking Ctrl+K and
the browser chat input. These source-parsing tests assert `main` is appended
to `root` before any insertBefore references it, mirroring
`test_session_search_dashboard.py`.
"""
from __future__ import annotations
import re
from pathlib import Path
FRONTEND = (
Path(__file__).resolve().parents[2]
/ "src" / "praisonaiui" / "templates" / "frontend" / "plugins"
)
DASHBOARD_JS = FRONTEND / "dashboard.js"
class TestDashboardShellOrder:
def _build_body(self) -> str:
src = DASHBOARD_JS.read_text()
m = re.search(
r"function buildDashboard\([^)]*\)\s*\{(.*?)^}",
src, re.DOTALL | re.MULTILINE,
)
assert m, "buildDashboard not found"
return m.group(1)
def test_main_appended_before_insert_before(self):
body = self._build_body()
append_idx = body.find("root.appendChild(main)")
insert_idx = body.find("root.insertBefore(shellHeader, main)")
assert append_idx != -1, "root.appendChild(main) not found"
assert insert_idx != -1, "root.insertBefore(shellHeader, main) not found"
assert append_idx < insert_idx, (
"main must be appended to root before insertBefore(shellHeader, main)"
)
def test_shell_header_insert_guarded_by_children(self):
body = self._build_body()
m = re.search(
r"if \(shellHeader\.children\.length\)\s*"
r"root\.insertBefore\(shellHeader, main\)",
body,
)
assert m, "shellHeader insert must be guarded by children.length"