Skip to content

Commit 4317858

Browse files
authored
Support inheriting namespace through portals (#4993)
1 parent 25bb34b commit 4317858

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

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
contains: () => true,
50+
namespaceURI: container.namespaceURI,
5051
insertBefore(child, before) {
5152
this.childNodes.push(child);
5253
_this._container.insertBefore(child, before);

compat/test/browser/portals.test.js

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

0 commit comments

Comments
 (0)