Skip to content

Commit 66d2245

Browse files
committed
Add a failing test for SVG across portals
It should reset the container stack when it pushes a portal, and restore it on pop. However this currently doesn't happen.
1 parent 4f3cc53 commit 66d2245

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,44 @@ describe('ReactDOMFiber', () => {
313313
expect(container.innerHTML).toBe('');
314314
});
315315

316+
xit('TODO: should not apply SVG mode across portals', () => {
317+
var portalContainer = document.createElement('div');
318+
var portalContainer2 = document.createElement('div');
319+
var portalContainer3 = document.createElement('div');
320+
321+
ReactDOM.render(
322+
<svg>
323+
<image xlinkHref="http://i.imgur.com/w7GCRPb.png" />
324+
{ReactDOM.unstable_createPortal(
325+
<div>portal1[1]</div>,
326+
portalContainer
327+
)}
328+
<image xlinkHref="http://i.imgur.com/w7GCRPb.png" />
329+
</svg>,
330+
container
331+
);
332+
333+
const div = portalContainer.childNodes[0];
334+
const image1 = container.firstChild.childNodes[0];
335+
const image2 = container.firstChild.childNodes[1];
336+
expect(div.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
337+
expect(div.tagName).toBe('DIV');
338+
expect(image1.namespaceURI).toBe('http://www.w3.org/2000/svg');
339+
expect(image1.tagName).toBe('image');
340+
expect(
341+
image1.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
342+
).toBe('http://i.imgur.com/w7GCRPb.png');
343+
expect(image2.namespaceURI).toBe('http://www.w3.org/2000/svg');
344+
expect(image2.tagName).toBe('image');
345+
expect(
346+
image2.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
347+
).toBe('http://i.imgur.com/w7GCRPb.png');
348+
349+
ReactDOM.unmountComponentAtNode(container);
350+
expect(portalContainer.innerHTML).toBe('');
351+
expect(container.innerHTML).toBe('');
352+
});
353+
316354
it('should pass portal context when rendering subtree elsewhere', () => {
317355
var portalContainer = document.createElement('div');
318356

src/renderers/dom/shared/__tests__/ReactDOMSVG-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ describe('ReactDOMSVG', () => {
5555
node
5656
);
5757
// SVG tagName is case sensitive.
58-
expect(g.tagName).toBe('g');
5958
expect(g.namespaceURI).toBe('http://www.w3.org/2000/svg');
59+
expect(g.tagName).toBe('g');
6060
expect(g.getAttribute('stroke-width')).toBe('5');
61-
expect(image.tagName).toBe('image');
6261
expect(image.namespaceURI).toBe('http://www.w3.org/2000/svg');
62+
expect(image.tagName).toBe('image');
6363
expect(
6464
image.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
6565
).toBe('http://i.imgur.com/w7GCRPb.png');
66-
expect(image2.tagName).toBe('image');
6766
expect(image2.namespaceURI).toBe('http://www.w3.org/2000/svg');
67+
expect(image2.tagName).toBe('image');
6868
expect(
6969
image2.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
7070
).toBe('http://i.imgur.com/w7GCRPb.png');
7171
// DOM tagName is capitalized by browsers.
72-
expect(p.tagName).toBe('P');
7372
expect(p.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
74-
expect(div.tagName).toBe('DIV');
73+
expect(p.tagName).toBe('P');
7574
expect(div.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
76-
expect(foreignDiv.tagName).toBe('DIV');
75+
expect(div.tagName).toBe('DIV');
7776
expect(foreignDiv.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
77+
expect(foreignDiv.tagName).toBe('DIV');
7878
});
7979

8080
});

0 commit comments

Comments
 (0)