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

Add support for inline SVG element #104

Merged
merged 3 commits into from
Mar 21, 2019
Merged

Conversation

ivanceras
Copy link
Contributor

@ivanceras ivanceras commented Mar 16, 2019

This change is Reviewable

// https://developer.mozilla.org/en-US/docs/Web/SVG/Element
// a hashmap of `(tag, is_self_closing)`
static ref SVG_NAMESPACED_TAGS: HashMap<&'static str, bool> = [
("a", true),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might affect the tag in HTML.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah as this stands now this seems like we'd use create_element_ns for anchor tags even when they aren't inside of an SVG

("set", true),
("solidcolor", true),
("stop", true),
("style", false),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also affect the <style> tag in HTML, there is a need for the parser to determine if this is inside of an element.

("polyline", true),
("radialGradient", false),
("rect", true),
("script", false),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also affect the <script> tag in html.

Copy link
Owner

@chinedufn chinedufn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff! Thanks so much for diving into this - very excited to see SVG support!

Left some small notes - mainly around adding a couple of tests and tweaks to ensure that this works both now and going forwards.

Note that the test files contain instructions for how to run them but you'll probably need to do

cargo install wasm-pack -f --git https://github.com/rustwasm/wasm-pack first since wasm-pack hasn't published the changes that allow you to run individual tests yet.

@@ -217,7 +217,11 @@ impl VElement {
pub fn create_element_node(&self) -> CreatedNode<Element> {
let document = web_sys::window().unwrap().document().unwrap();

let element = document.create_element(&self.tag).unwrap();
let element = if let Some(ns) = html_validation::get_namespace(&self.tag){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want a new test in the create_element tests that shows that this works for an SVG tag.

And also one that shows that anchor tags still work

https://github.com/chinedufn/percy/blob/bf2eb091dccacbd3995777cf94f16de86bf247aa/crates/virtual-dom-rs/tests/create_element.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, using the create_element for svg elements still attached the svg and its children to the DOM, but it somehow not shown( or misbehaving) in the browser.

/// Return the namespace of this tag
/// returns the svg namespace as of now,
/// any other tags will have a `None` value
pub fn get_namespace(tag: &str) -> Option<String> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option<String> feels a little off to me here since every tag has a namespace.

For now can we instead have a is_svg_namespace (tag: &str) -> bool and make use of that in our create_element_node function? This way we don't need to say that None really means HTML

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that make sense.

("animateTransform", true),
("circle", true),
("clipPath",false),
//("color-profile",),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For everything that is commented out in here mind leaving a comment explaining why the item is commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should file an issue how are tags that has a - (dash) in between are done? How is it also done in attributes?

// https://developer.mozilla.org/en-US/docs/Web/SVG/Element
// a hashmap of `(tag, is_self_closing)`
static ref SVG_NAMESPACED_TAGS: HashMap<&'static str, bool> = [
("a", true),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah as this stands now this seems like we'd use create_element_ns for anchor tags even when they aren't inside of an SVG

@chinedufn
Copy link
Owner

You'll want to rebase on top of the latest master branch since I pushed up some conflicts in eb0c6de

Copy link
Owner

@chinedufn chinedufn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment to update then looks great to me!!! Thanks for making these changes!

}
/// Return the namespace of this tag
/// returns the svg namespace as of now,
/// any other tags will have a `None` value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this comment needs a quick update since we no longer use None

@chinedufn
Copy link
Owner

Hmm looks like tests are failing

Is ./test.sh passing for you locally ?

@ivanceras
Copy link
Contributor Author

My local test was failing. I just fixed the test to match the expected output.

@chinedufn chinedufn merged commit 00f3e4a into chinedufn:master Mar 21, 2019
@chinedufn
Copy link
Owner

Thanks! Merging

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

Successfully merging this pull request may close these issues.

2 participants