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

Better strategy for dealing with svg #147

Closed
Swatinem opened this issue Dec 7, 2016 · 3 comments
Closed

Better strategy for dealing with svg #147

Swatinem opened this issue Dec 7, 2016 · 3 comments

Comments

@Swatinem
Copy link
Member

Swatinem commented Dec 7, 2016

I had a hunch and the failing test I just commited (83e9ed9) proves it:
When using components to render children into a svg node, the children get the wrong namespace.

Looking at other frameworks, react and incremental-dom both rely on the parent element to determine which namespace to use for elements:
https://github.com/facebook/react/blob/master/src/renderers/dom/stack/client/ReactDOMComponent.js#L511-L533
https://github.com/google/incremental-dom/blob/master/src/nodes.js#L30-L40

Problem is that since we separated create from mount, we can’t really look at any parent at creation time. I think I also saw that some frameworks keep whitelists of svg tags, so that might be an option.

@Rich-Harris
Copy link
Member

Ah, yeah. One option:

<circle cx='{{x}}' cy='{{cy}}' r='{{r}}'/>

<script>
  export default {
    namespace: 'http://www.w3.org/2000/svg' // maybe accept 'svg' as shorthand
  };
</script>

That way the compiler knows which namespace to use. We could use the element whitelist to print a warning if the namespace isn't present but should be.

@Ryuno-Ki
Copy link

Ryuno-Ki commented Dec 7, 2016

@Rich-Harris What would you do, if one would want to generate Atom feeds with Svelte?
Atom has a namespace (https://www.w3.org/2005/Atom). I've saw static site generators like Hugo providing templates for feeds: https://gohugo.io/templates/rss/#the-embedded-rss-xml

So it is not that crazy to at least consider that.

@Rich-Harris
Copy link
Member

@Ryuno-Ki that should work just fine, since it's an SSR concern – you'd never need to render an Atom feed in a browser (I'm not sure what that would even mean!) so there are no namespace quirks to deal with. This is purely about what the first argument to document.createElementNS(...) should be.

Now that you mention it, it does occur to me that we could fix sveltejs/v2.svelte.dev#4 by rendering RSS/Atom with svelte/ssr, which is quite cool. Would just need to add <?xml ...> declaration support.

Rich-Harris added a commit that referenced this issue Dec 10, 2016
add support for declared namespaces
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

3 participants