Skip to content
This repository was archived by the owner on Mar 2, 2021. It is now read-only.

Bump-Scoped rendering and SVG class attribute fix #136

Merged
merged 10 commits into from
Feb 24, 2020
37 changes: 36 additions & 1 deletion tests/web/render.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{assert_rendered, before_after, create_element, RenderFn};
use dodrio::{builder::*, Vdom};
use dodrio::{builder::*, bumpalo::collections::String, Node, Render, RenderContext, Vdom};
use std::rc::Rc;
use wasm_bindgen::{ JsCast};
use wasm_bindgen_test::*;
Expand Down Expand Up @@ -35,6 +35,41 @@ fn container_is_emptied_upon_drop() {
assert!(container.first_child().is_none());
}

/// Renders a child with a lifetime scoped to the RenderContext bump arena.
#[wasm_bindgen_test]
fn render_bump_scoped_node() {
struct Child<'a> {
name: &'a str,
}

impl<'a> Render<'a> for Child<'a> {
fn render(&self, _cx: &mut RenderContext<'a>) -> Node<'a> {
text(self.name)
}
}

struct Parent;

impl<'a> Render<'a> for Parent {
fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
let child_name = String::from_str_in("child", cx.bump).into_bump_str();

div(&cx)
.children([Child { name: child_name }.render(cx)])
.finish()
}
}

let parent = Rc::new(RenderFn(|cx| {
Parent.render(cx)
}));

let container = create_element("div");
let _vdom = Vdom::new(&container, parent.clone());

assert_rendered(&container, &parent);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the smoke test. It's pretty similar to the other one, but I used the assert_rendered afterward

/// Originally, dodrio would use the className property for SVGs.
///
/// This is problematic because when SVG elements are created, the className is flagged as a read
Expand Down