From 5dddf8f9a3b99491f6bb1719d2ee520b2a11bf75 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 3 Dec 2021 12:46:31 +0100 Subject: [PATCH] [FIX] blockdom: do not propagate svg namespace to siblings --- src/blockdom/block_compiler.ts | 2 +- tests/blockdom/block.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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"]);