Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use foreignObject inside SVG #1733

Closed
adrm opened this issue Jul 16, 2019 · 1 comment
Closed

Unable to use foreignObject inside SVG #1733

adrm opened this issue Jul 16, 2019 · 1 comment
Labels

Comments

@adrm
Copy link

adrm commented Jul 16, 2019

Stencil version:

 @stencil/core@1.1.4

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

When trying to model an svg element with JSX inside a Stencil component, the svg rendering breaks from the point that a foreignObject appears. If I add a div with innerHTML set to a string with the same svg used before, thus avoiding JSX, it works as expected.

I have this JSX in my component:

<Host>
          <p>If injected with innerHTML it works.</p>
          <div
            innerHTML={`
          <svg width="100%" height="500">
          <rect x="10" y="10" width="100" height="150" fill="blue" />
          <foreignObject x="10" y="10" width="100" height="150">
            <div>
              Here is a <strong>paragraph</strong> that requires
              <em>word wrap</em>
            </div>
          </foreignObject>

          <circle cx="200" cy="200" r="100" fill="red" />
          <foreignObject x="120" y="120" width="180" height="180">
            <div>
              <ul>
                <li>
                  <strong>First</strong> item
                </li>

                <li>
                  <em>Second</em> item
                </li>
                <li>Thrid item</li>
              </ul>
            </div>
          </foreignObject>
        </svg>
          `}
          />

          <p>If plain JSX is used, with the same code, it doesn't.</p>
          <svg width="100%" height="500">
            <rect x="10" y="10" width="100" height="150" fill="blue" />
            <foreignObject x="10" y="10" width="100" height="150">
              <div>
                Here is a <strong>paragraph</strong> that requires
                <em>word wrap</em>
              </div>
            </foreignObject>

            <circle cx="200" cy="200" r="100" fill="red" />
            <foreignObject x="120" y="120" width="180" height="180">
              <div>
                <ul>
                  <li>
                    <strong>First</strong> item
                  </li>

                  <li>
                    <em>Second</em> item
                  </li>
                  <li>Thrid item</li>
                </ul>
              </div>
            </foreignObject>
          </svg>
        </Host>

And this is what I get rendered:

imagen

The svg example is from https://jsfiddle.net/leaverou/qwg3r/, btw.

Expected behavior:

SVG should render fine, the same as using pure HTML.

Steps to reproduce:

Create a stencil component with the code provided before as the return value for the render function and run it in a browser.

Other information:

@briandiehr
Copy link

Hi! I see this was marked as fix within the changelog, but when I test with the latest version, 1.7.0, the inner text does not render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants