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

SVG Issues #142

Closed
PaulBGD opened this issue Dec 7, 2016 · 5 comments
Closed

SVG Issues #142

PaulBGD opened this issue Dec 7, 2016 · 5 comments

Comments

@PaulBGD
Copy link
Member

PaulBGD commented Dec 7, 2016

I'm having trouble displaying my SVG. There's a few issues that I'm seeing occurring:

  1. The namespace ends up being [object Object]? Examples:
var svg = document.createElementNS( '[object Object]', 'svg' );
var defs = document.createElementNS( '[object Object]', 'defs' );
var path = document.createElementNS( '[object Object]', 'path' );
  1. My defs object doesn't get populated with styles:
    Input:
        <defs>
            <style>.dev-1{fill:#38aecc}.dev-2{fill:#022f40}.dev-3{fill:#fff}.dev-4{fill:#5f5}</style>
        </defs>

Output:

	var defs = document.createElementNS( '[object Object]', 'defs' );
	
	svg.appendChild( defs );
  1. For some reason there's this random text node thing occurring after every single element:
	svg.appendChild( document.createTextNode( "\n        " ) );
@Rich-Harris
Copy link
Member

  1. That's very odd. Can you reproduce the issue in the REPL? The SVG example there is working correctly
  2. Looks like Svelte doesn't like it if you have more than one <style> tag – in this example, if you delete the second one, the styles inside the <defs> are used, otherwise they're ignored. Hmm. We should figure out exactly how to handle multiple <style> tags (is there a good reason to have more than one within a component? Is there a good reason to disallow more than one?)
  3. Yeah, whitespace matters in HTML (a bit) but not in SVG. We should discard whitespace inside SVG elements

@Rich-Harris
Copy link
Member

Oh, I've reproduced part 1 now – it's because the xmlns attribute is being incorrectly handled. On it.

@PaulBGD
Copy link
Member Author

PaulBGD commented Dec 7, 2016

  1. That's a good point, there isn't a reason that you really would need two style tags. The reason I had two was because I was copying the SVG from the exported file that AI makes. I don't think there's a good reason to disallow it however.

@Rich-Harris
Copy link
Member

I don't think there's a good reason to disallow it however.

Thinking on it further, it does make life slightly harder – it'll probably make it slightly trickier to create CSS sourcemaps when we eventually get round to that, and you have to ensure that rules appear in the correct order, etc. All doable, but a bit more work. It turns out the parser was already supposed to be disallowing duplicate <style> and <script> tags but there was a typo, so for now I've just fixed that in #143, meaning the compiler will now yell at you for having two <style> tags. We can definitely revisit that restriction in future

Rich-Harris added a commit that referenced this issue Dec 7, 2016
don't render whitespace text nodes inside SVG elements
@Rich-Harris
Copy link
Member

Released 1.1.3 with these fixes

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

No branches or pull requests

2 participants