Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa23fdc

Browse filesBrowse files
committed
fix fragment caching for SVG elements in IE (fix vuejs#2406)
1 parent 3b82e2b commit aa23fdc
Copy full SHA for aa23fdc

File tree

Expand file treeCollapse file tree

3 files changed

+28
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+28
-2
lines changed

‎src/fragment/factory.js

Copy file name to clipboardExpand all lines: src/fragment/factory.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { compile } from '../compiler/index'
2-
import { isTemplate } from '../util/index'
2+
import { isTemplate, getOuterHTML } from '../util/index'
33
import { parseTemplate, cloneNode } from '../parsers/template'
44
import Fragment from './fragment'
55
import Cache from '../cache'
@@ -29,7 +29,7 @@ export default function FragmentFactory (vm, el) {
2929
var linker
3030
var cid = vm.constructor.cid
3131
if (cid > 0) {
32-
var cacheId = cid + (isString ? el : el.outerHTML)
32+
var cacheId = cid + (isString ? el : getOuterHTML(el))
3333
linker = linkerCache.get(cacheId)
3434
if (!linker) {
3535
linker = compile(template, vm.$options, true)

‎src/util/dom.js

Copy file name to clipboardExpand all lines: src/util/dom.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,21 @@ export function removeNodeRange (start, end, vm, frag, cb) {
414414
export function isFragment (node) {
415415
return node && node.nodeType === 11
416416
}
417+
418+
/**
419+
* Get outerHTML of elements, taking care
420+
* of SVG elements in IE as well.
421+
*
422+
* @param {Element} el
423+
* @return {String}
424+
*/
425+
426+
export function getOuterHTML (el) {
427+
if (el.outerHTML) {
428+
return el.outerHTML
429+
} else {
430+
var container = document.createElement('div')
431+
container.appendChild(el.cloneNode(true))
432+
return container.innerHTML
433+
}
434+
}

‎test/unit/specs/util/dom_spec.js

Copy file name to clipboardExpand all lines: test/unit/specs/util/dom_spec.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,12 @@ describe('Util - DOM', function () {
115115
_.addClass(el, 'bb')
116116
expect(el.getAttribute('class')).toBe('cc bb')
117117
})
118+
119+
it('getOuterHTML for SVG', function () {
120+
var el = document.createElementNS('http://www.w3.org/2000/svg', 'circle')
121+
el.setAttribute('class', 'aa bb cc')
122+
var html = _.getOuterHTML(el)
123+
var re = /<circle (xmlns="http:\/\/www\.w3\.org\/2000\/svg"\s)?class="aa bb cc"(\s?\/>|><\/circle>)/
124+
expect(re.test(html)).toBe(true)
125+
})
118126
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.