Skip to content
Permalink
Browse files

Fix foreignObject not being treated as svg

  • Loading branch information
marvinhagemeister committed Mar 11, 2019
1 parent 5046b75 commit 7467ac3f3822e8deaa810c1024dcd03f070edddd
Showing with 16 additions and 2 deletions.
  1. +2 −2 src/diff/index.js
  2. +14 −0 test/browser/svg.test.js
@@ -217,7 +217,7 @@ function diffElementNodes(dom, newVNode, oldVNode, context, isSvg, excessDomChil
let d = dom;

// Tracks entering and exiting SVG namespace when descending through the tree.
isSvg = isSvg ? newVNode.type !== 'foreignObject' : newVNode.type === 'svg';
if (newVNode.type==='svg') isSvg = true;

if (dom==null && excessDomChildren!=null) {
for (let i=0; i<excessDomChildren.length; i++) {
@@ -261,7 +261,7 @@ function diffElementNodes(dom, newVNode, oldVNode, context, isSvg, excessDomChil
diffProps(dom, newVNode.props, oldProps, isSvg);
}

diffChildren(dom, newVNode, oldVNode, context, isSvg, excessDomChildren, mounts, ancestorComponent);
diffChildren(dom, newVNode, oldVNode, context, newVNode.type==='foreignObject' ? false : isSvg, excessDomChildren, mounts, ancestorComponent);
}

return dom;
@@ -118,6 +118,20 @@ describe('svg', () => {
.that.is.a('HTMLAnchorElement');
});

it('should render foreignObject as an svg element', () => {
render((
<svg>
<g>
<foreignObject>
<a href="#foo">test</a>
</foreignObject>
</g>
</svg>
), scratch);

expect(scratch.querySelector('foreignObject').localName).to.equal('foreignObject');
});

it('should transition from DOM to SVG and back', () => {
render((
<div>

0 comments on commit 7467ac3

Please sign in to comment.
You can’t perform that action at this time.