fix: #2836 fix formula first render (#2860)

* fix: #2836 fix formula first render

* Revert "refresh svg by innerHTML"

* add NS to vNode before path

* improve readability
This commit is contained in:
toSayNothing 2022-01-14 00:14:46 +08:00 committed by GitHub
parent d24a578a1a
commit ccf105e146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import loadRenderer from '../../renderers'
import { CLASS_OR_ID } from '../../config'
import { conflict, mixins, camelToSnake } from '../../utils'
import { patch, toVNode, toHTML, h } from './snabbdom'
import { patch, toVNode, toHTML, h, addNStoVNodeSvgChildren } from './snabbdom'
import { beginRules } from '../rules'
import renderInlines from './renderInlines'
import renderBlock from './renderBlock'
@ -175,7 +175,7 @@ class StateRender {
const children = blocks.map(block => {
return this.renderBlock(null, block, activeBlocks, matches, true)
})
addNStoVNodeSvgChildren(children)
const newVdom = h(selector, children)
const rootDom = document.querySelector(selector) || this.container
const oldVdom = toVNode(rootDom)

View File

@ -17,3 +17,21 @@ export const htmlToVNode = html => { // helper function for convert html to vnod
wrapper.innerHTML = html
return toVNode(wrapper).children
}
const addNS = ({ data, children, sel }) => {
data.ns = 'http://www.w3.org/2000/svg'
if (sel !== 'foreignObject' && children !== undefined) {
for (const vNode of children) {
if (vNode.data === undefined) continue
addNS(vNode)
}
}
}
export const addNStoVNodeSvgChildren = (children = []) => {
for (const vNode of children) {
if (vNode.data === undefined) continue
if (vNode.sel.startsWith('svg')) addNS(vNode)
addNStoVNodeSvgChildren(vNode.children)
}
}