Skip to content

Commit 46772a2

Browse files
authored
Support inheriting namespace through portals (#4993) (#4995)
1 parent c1bcde3 commit 46772a2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

compat/src/portals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function Portal(props) {
4747
childNodes: [],
4848
_children: { _mask: root._mask },
4949
ownerDocument: container.ownerDocument,
50+
namespaceURI: container.namespaceURI,
5051
insertBefore(child, before) {
5152
this.childNodes.push(child);
5253
_this._container.insertBefore(child, before);

compat/test/browser/portals.test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,35 @@ describe('Portal', () => {
875875
'Portal'
876876
]);
877877
});
878+
879+
// #4992
880+
it('should maintain SVG namespace when rendering through a portal', () => {
881+
const svgRoot = document.createElementNS(
882+
'http://www.w3.org/2000/svg',
883+
'svg'
884+
);
885+
document.body.appendChild(svgRoot);
886+
887+
function App() {
888+
return (
889+
<svg>
890+
<g>
891+
<rect width="100" height="100" fill="red" />
892+
{createPortal(
893+
<g id="test-portal">
894+
<rect width="50" height="50" fill="blue" />
895+
</g>,
896+
svgRoot
897+
)}
898+
</g>
899+
</svg>
900+
);
901+
}
902+
903+
render(<App />, scratch);
904+
905+
const portalG = svgRoot.querySelector('g#test-portal');
906+
expect(portalG.namespaceURI).to.equal('http://www.w3.org/2000/svg');
907+
expect(portalG.constructor.name).to.equal('SVGGElement');
908+
});
878909
});

0 commit comments

Comments
 (0)