mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: properly supports svg
Snabbdom supports svg, but it adds the namespace at the creation of the virtual node. However, owl works slightly differently: it adds children after creating the parent virtual node. So, we need to actually call the addNS method after the children nodes have been created. As a bonus, this is slightly faster than snabbdom: we only check at template compilation time once if a node is a svg.
This commit is contained in:
+9
-1
@@ -2,6 +2,7 @@ import { EventBus } from "../core/event_bus";
|
||||
import { h, patch, VNode } from "../vdom/index";
|
||||
import { Context } from "./context";
|
||||
import { shallowEqual } from "../utils";
|
||||
import { addNS } from "../vdom/vdom";
|
||||
|
||||
/**
|
||||
* Owl QWeb Engine
|
||||
@@ -93,7 +94,10 @@ const UTILS: Utils = {
|
||||
}
|
||||
return expr;
|
||||
},
|
||||
shallowEqual
|
||||
shallowEqual,
|
||||
addNameSpace(vnode) {
|
||||
addNS(vnode.data, vnode.children, vnode.sel);
|
||||
},
|
||||
};
|
||||
|
||||
function parseXML(xml: string): Document {
|
||||
@@ -537,6 +541,10 @@ export class QWeb extends EventBus {
|
||||
}
|
||||
|
||||
this._compileChildren(node, ctx);
|
||||
if (node.nodeName === 'svg') {
|
||||
ctx.rootContext.shouldDefineUtils = true;
|
||||
ctx.addLine(`utils.addNameSpace(vn${ctx.parentNode});`);
|
||||
}
|
||||
|
||||
for (let { directive, value, fullName } of validDirectives) {
|
||||
if (directive.finalize) {
|
||||
|
||||
Reference in New Issue
Block a user