diff --git a/src/blockdom/block_compiler.ts b/src/blockdom/block_compiler.ts
index 76f7df31..35cfe2b6 100644
--- a/src/blockdom/block_compiler.ts
+++ b/src/blockdom/block_compiler.ts
@@ -127,7 +127,7 @@ function buildTree(
switch (node.nodeType) {
case Node.ELEMENT_NODE: {
// HTMLElement
- let currentNS = parent && parent.currentNS;
+ let currentNS = domParentTree && domParentTree.currentNS;
const tagName = (node as Element).tagName;
let el: Node | undefined = undefined;
const info: DynamicInfo[] = [];
diff --git a/tests/blockdom/block.test.ts b/tests/blockdom/block.test.ts
index 98c80df7..cd385ae8 100644
--- a/tests/blockdom/block.test.ts
+++ b/tests/blockdom/block.test.ts
@@ -243,6 +243,22 @@ describe("misc", () => {
expect(fixture.innerHTML).toBe(`