Skip to content

Commit 244b76e

Browse files
fix(component): propagate SVG namespace through components (#10916)
1 parent 45af5e0 commit 244b76e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix SVG namespace propagation through components
2+
3+
Components rendered inside `<svg>` elements now correctly create SVG elements instead of HTML elements.

packages/component/src/lib/vdom.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,36 @@ describe('vnode rendering', () => {
192192
// Attribute should remain correct post-hydration
193193
expect(postPath.getAttribute('stroke-linecap')).toBe('round')
194194
})
195+
196+
it('propagates SVG namespace through components', () => {
197+
let container = document.createElement('div')
198+
let root = createRoot(container)
199+
200+
function SvgGroup({ href, children }: { href: string; children?: RemixNode }) {
201+
return () => <g href={href}>{children}</g>
202+
}
203+
204+
root.render(
205+
<svg width="100" height="100">
206+
<SvgGroup href="/test">
207+
<path id="p" />
208+
</SvgGroup>
209+
</svg>,
210+
)
211+
212+
let svg = container.querySelector('svg')
213+
let group = container.querySelector('g')
214+
let path = container.querySelector('path')
215+
216+
invariant(svg instanceof SVGSVGElement)
217+
invariant(group instanceof SVGGElement)
218+
invariant(path instanceof SVGPathElement)
219+
220+
// All elements should have SVG namespace
221+
expect(svg.namespaceURI).toBe('http://www.w3.org/2000/svg')
222+
expect(group.namespaceURI).toBe('http://www.w3.org/2000/svg')
223+
expect(path.namespaceURI).toBe('http://www.w3.org/2000/svg')
224+
})
195225
})
196226

197227
describe('inserts', () => {

packages/component/src/lib/vdom.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,8 @@ function insert(
773773
cursor?: Node | null,
774774
): Node | null | undefined {
775775
node._parent = vParent // set parent for initial render context lookups
776-
if (isHostNode(node)) {
777-
node._svg = getSvgContext(vParent, node.type)
778-
}
776+
node._svg = getSvgContext(vParent, node.type)
777+
779778
cursor = skipComments(cursor ?? null)
780779

781780
let doInsert = anchor

0 commit comments

Comments
 (0)