bug: unable to render foreignObject with attributes inside SVG
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
Research direction
Start with the linked reproduction project and Stencil render functions, focusing on how SVG foreignObject attributes width, height, x, and y are handled. Reproduce the issue using the example component, then verify that foreignObject renders with those attributes without requiring the setAttribute workaround.
Written by the indexing model from the issue text.
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
v2.x
Current Behavior
foreignObject with attributes in SVG cannot be rendered.
Stencil expect the foreignObject to be provided as foreign-object in order to be able to render attributes but, the browser expect the foreignObject to be provided as <foreignObject/> and not <foreign-object/>.
It seems Stencil has an issue only with a subset of SVGAttributes respectively width, height, x and y.
Expected Behavior
Being able to use <foreignObject/> with attributes withing svg in Stencil render functions.
Steps to Reproduce
import { Component, h } from '@stencil/core';
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
render() {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300" x="0" y="0" height="300" width="300">
<circle r="142" cx="150" cy="150" fill="none" stroke="#000000" stroke-width="2" />
<foreignObject x={0} y={0} width="200" height="200">
<p>Hello World</p>
</foreignObject>
</svg>
);
}
}
Code Reproduction URL
https://github.com/peterpeterparker/stencil-svg-foreignobject
Additional Information
Notes
a fixed issue regarding foreign object has been opened in the past, see #1733
Screenshots
Workaround
import {Component, h, ComponentInterface} from '@stencil/core';
@Component({
tag: 'deckgo-social-img',
styleUrl: 'social-img.scss',
shadow: true
})
export class SocialImg implements ComponentInterface {
private foreignObjectRef!: SVGForeignObjectElement;
componentDidLoad() {
this.setForeignObjectAttributes();
}
private setForeignObjectAttributes() {
this.foreignObjectRef?.setAttribute('x', '0');
this.foreignObjectRef?.setAttribute('y', '0');
this.foreignObjectRef?.setAttribute('width', '200');
this.foreignObjectRef?.setAttribute('height', '100');
}
render() {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300" x="0" y="0" height="300" width="300">
<circle r="142" cx="150" cy="150" fill="none" stroke="#000000" stroke-width="2" />
<foreignObject ref={(el) => (this.foreignObjectRef = el as SVGForeignObjectElement)}>
<p>Hello World</p>
</foreignObject>
</svg>
);
}
}
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 855
- Avg merge
- 4h 7m
- Merged PRs (30d)
- 44
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/core
-
Stencil v5
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Bug: Validated Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Feature: Want this? Upvote it!
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature: Want this? Upvote it!
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·