[FIX] blockdom: do not propagate svg namespace to siblings

This commit is contained in:
Lucas Perais (lpe)
2021-12-03 12:46:31 +01:00
committed by Aaron Bohy
parent 463eb4bb86
commit 5dddf8f9a3
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -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[] = [];
+16
View File
@@ -243,6 +243,22 @@ describe("misc", () => {
expect(fixture.innerHTML).toBe(`<a hello="world"><b><c>12</c></b>3</a>`);
});
test("namespace is not propagated to siblings", () => {
const block = createBlock(`<div><svg block-ns="someNameSpace"><g/></svg><div></div></div>`);
const fixture = makeTestFixture();
mount(block(), fixture);
expect(fixture.innerHTML).toBe("<div><svg><g></g></svg><div></div></div>");
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('<div><block-text-0/></div>');
// const foo = block(["foo"]);