fix: ensure SVG namespaces are correct when copying a thunk

ISSUES CLOSED: #867
pull/996/head
macarc 3 years ago
parent ce95a24e73
commit 009ed2a2d2

@ -13,17 +13,19 @@ export type VNodeChildElement =
export type ArrayOrElement<T> = T | T[];
export type VNodeChildren = ArrayOrElement<VNodeChildElement>;
function addNS(
export function addNS(
data: any,
children: VNodes | undefined,
children: Array<VNode | string> | undefined,
sel: string | undefined
): void {
data.ns = "http://www.w3.org/2000/svg";
if (sel !== "foreignObject" && children !== undefined) {
for (let i = 0; i < children.length; ++i) {
const childData = children[i].data;
const child = children[i];
if (typeof child === "string") continue;
const childData = child.data;
if (childData !== undefined) {
addNS(childData, children[i].children as VNodes, children[i].sel);
addNS(childData, child.children as VNodes, child.sel);
}
}
}

@ -1,5 +1,5 @@
import { VNode, VNodeData } from "./vnode";
import { h } from "./h";
import { h, addNS } from "./h";
export interface ThunkData extends VNodeData {
fn: () => VNode;
@ -16,12 +16,14 @@ export interface ThunkFn {
}
function copyToThunk(vnode: VNode, thunk: VNode): void {
const ns = thunk.data ? thunk.data.ns : null;
(vnode.data as VNodeData).fn = (thunk.data as VNodeData).fn;
(vnode.data as VNodeData).args = (thunk.data as VNodeData).args;
thunk.data = vnode.data;
thunk.children = vnode.children;
thunk.text = vnode.text;
thunk.elm = vnode.elm;
if (ns) addNS(thunk.data, thunk.children, thunk.sel);
}
function init(thunk: VNode): void {

Loading…
Cancel
Save