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(`123`); }); + test("namespace is not propagated to siblings", () => { + const block = createBlock(`
`); + + const fixture = makeTestFixture(); + mount(block(), fixture); + + expect(fixture.innerHTML).toBe("
"); + expect(fixture.querySelector("svg")!.namespaceURI).toBe("someNameSpace"); + expect(fixture.querySelector("g")!.namespaceURI).toBe("someNameSpace"); + const allDivs = fixture.querySelectorAll("div"); + expect(Array.from(allDivs).map((el) => el.namespaceURI)).toEqual([ + "http://www.w3.org/1999/xhtml", + "http://www.w3.org/1999/xhtml", + ]); + }); + // test.skip("reusing a block skips patching process", async () => { // const block = createBlock('
'); // const foo = block(["foo"]);