- Don't merge dynamic attributes together unnecessarily - Walk the workspace until we find a target dir with the dioxusin handle
This commit is contained in:
11 files changed
+259
-31
No files matched your search
+6
-16
@@ -453,7 +453,8 @@ impl<'a> DynamicContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_static_node(&mut self, root: &'a BodyNode) -> TokenStream2 {
|
||||
/// Render a portion of an rsx callbody to a token stream
|
||||
pub fn render_static_node(&mut self, root: &'a BodyNode) -> TokenStream2 {
|
||||
match root {
|
||||
BodyNode::Element(el) => {
|
||||
let el_name = &el.name;
|
||||
@@ -499,20 +500,10 @@ impl<'a> DynamicContext<'a> {
|
||||
}
|
||||
|
||||
_ => {
|
||||
// If this attribute is dynamic, but it already exists in the template, we can reuse the index
|
||||
if let Some(attribute_index) = self
|
||||
.attr_paths
|
||||
.iter()
|
||||
.position(|path| path == &self.current_path)
|
||||
{
|
||||
self.dynamic_attributes[attribute_index].push(attr);
|
||||
quote! {}
|
||||
} else {
|
||||
let ct = self.dynamic_attributes.len();
|
||||
self.dynamic_attributes.push(vec![attr]);
|
||||
self.attr_paths.push(self.current_path.clone());
|
||||
quote! { dioxus_core::TemplateAttribute::Dynamic { id: #ct }, }
|
||||
}
|
||||
let ct = self.dynamic_attributes.len();
|
||||
self.dynamic_attributes.push(vec![attr]);
|
||||
self.attr_paths.push(self.current_path.clone());
|
||||
quote! { dioxus_core::TemplateAttribute::Dynamic { id: #ct }, }
|
||||
}
|
||||
});
|
||||
|
||||
@@ -525,7 +516,6 @@ impl<'a> DynamicContext<'a> {
|
||||
out
|
||||
});
|
||||
|
||||
let _opt = el.children.len() == 1;
|
||||
let children = quote! { #(#children),* };
|
||||
|
||||
let ns = ns(quote!(NAME_SPACE));
|
||||
|
||||
@@ -28,6 +28,16 @@ fn hotreloads() {
|
||||
diff_rsx(&new, &old),
|
||||
DiffResult::RsxChanged { .. }
|
||||
));
|
||||
|
||||
let (old, new) = load_files(
|
||||
include_str!("./valid/combo.old.rsx"),
|
||||
include_str!("./valid/combo.new.rsx"),
|
||||
);
|
||||
|
||||
assert!(matches!(
|
||||
diff_rsx(&new, &old),
|
||||
DiffResult::RsxChanged { .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
use dioxus_rsx::{CallBody, DynamicContext};
|
||||
use syn::Item;
|
||||
|
||||
#[test]
|
||||
fn rsx_writeout_snapshot() {
|
||||
let body = parse_from_str(include_str!("./parsing/multiexpr.rsx"));
|
||||
|
||||
assert_eq!(body.roots.len(), 1);
|
||||
|
||||
let root = &body.roots[0];
|
||||
|
||||
let el = match root {
|
||||
dioxus_rsx::BodyNode::Element(el) => el,
|
||||
_ => panic!("Expected an element"),
|
||||
};
|
||||
|
||||
assert_eq!(el.name, "circle");
|
||||
|
||||
assert_eq!(el.attributes.len(), 5);
|
||||
|
||||
let mut context = DynamicContext::default();
|
||||
let o = context.render_static_node(&body.roots[0]);
|
||||
|
||||
// hi!!!!!
|
||||
// you're probably here because you changed something in how rsx! generates templates and need to update the snapshot
|
||||
// This is a snapshot test. Make sure the contents are checked before committing a new snapshot.
|
||||
let stability_tested = o.to_string();
|
||||
assert_eq!(
|
||||
stability_tested.trim(),
|
||||
include_str!("./parsing/multiexpr.expanded.rsx").trim()
|
||||
);
|
||||
}
|
||||
|
||||
fn parse_from_str(contents: &str) -> CallBody {
|
||||
// Parse the file
|
||||
let file = syn::parse_file(contents).unwrap();
|
||||
|
||||
// The first token should be the macro call
|
||||
let Item::Macro(call) = file.items.first().unwrap() else {
|
||||
panic!("Expected a macro call");
|
||||
};
|
||||
|
||||
call.mac.parse_body().unwrap()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
dioxus_core :: TemplateNode :: Element { tag : dioxus_elements :: circle :: TAG_NAME , namespace : dioxus_elements :: circle :: NAME_SPACE , attrs : & [dioxus_core :: TemplateAttribute :: Dynamic { id : 0usize } , dioxus_core :: TemplateAttribute :: Dynamic { id : 1usize } , dioxus_core :: TemplateAttribute :: Dynamic { id : 2usize } , dioxus_core :: TemplateAttribute :: Static { name : dioxus_elements :: circle :: stroke . 0 , namespace : dioxus_elements :: circle :: stroke . 1 , value : "green" , } , dioxus_core :: TemplateAttribute :: Static { name : dioxus_elements :: circle :: fill . 0 , namespace : dioxus_elements :: circle :: fill . 1 , value : "yellow" , } ,] , children : & [] , }
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
rsx! {
|
||||
circle {
|
||||
cx: 50,
|
||||
cy: 50,
|
||||
r: 40,
|
||||
stroke: "green",
|
||||
fill: "yellow"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// This test is used by playwright configured in the root of the repo
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn app() -> Element {
|
||||
let mut num = use_signal(|| 0);
|
||||
let mut eval_result = use_signal(String::new);
|
||||
let a = 123;
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
"hello axum! {num}"
|
||||
button { class: "increment-button", onclick: move |_| num += 1, "Increment" }
|
||||
}
|
||||
svg { circle { cx: 50, cy: 50, r: 40, stroke: "green", fill: "yellow" } }
|
||||
div { class: "raw-attribute-div", "raw-attribute": "raw-attribute-value" }
|
||||
div { class: "hidden-attribute-div", hidden: true }
|
||||
div {
|
||||
class: "dangerous-inner-html-div",
|
||||
dangerous_inner_html: "<p>hello dangerous inner html</p>"
|
||||
}
|
||||
input { value: "hello input" }
|
||||
div { class: "style-div", color: "red", "colored text" }
|
||||
div { class: "style-div", color: "red", "colored text" }
|
||||
button {
|
||||
class: "eval-button",
|
||||
onclick: move |_| async move {
|
||||
let mut eval = eval(
|
||||
r#"
|
||||
window.document.title = 'Hello from Dioxus Eval!';
|
||||
dioxus.send("returned eval value");
|
||||
"#,
|
||||
);
|
||||
|
||||
let result = eval.recv().await;
|
||||
if let Ok(serde_json::Value::String(string)) = result {
|
||||
eval_result.set(string);
|
||||
}
|
||||
},
|
||||
"Eval!!!!"
|
||||
"Eval!!!!"
|
||||
"Eval!!!!!"
|
||||
"Eval!!!!"
|
||||
"Eval!!!!"
|
||||
"Eval!!!!"
|
||||
}
|
||||
div { class: "eval-result", "{eval_result}" }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// tracing_wasm::set_as_global_default_with_config(
|
||||
// tracing_wasm::WASMLayerConfigBuilder::default()
|
||||
// .set_max_level(tracing::Level::TRACE)
|
||||
// .build(),
|
||||
// );
|
||||
launch(app);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// This test is used by playwright configured in the root of the repo
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn app() -> Element {
|
||||
let mut num = use_signal(|| 0);
|
||||
let mut eval_result = use_signal(String::new);
|
||||
let a = 123;
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
"hello axum! {num}"
|
||||
button { class: "increment-button", onclick: move |_| num += 1, "Increment" }
|
||||
}
|
||||
svg { circle { cx: 50, cy: 50, r: 40, stroke: "green", fill: "yellow" } }
|
||||
div { class: "raw-attribute-div", "raw-attribute": "raw-attribute-value" }
|
||||
div { class: "hidden-attribute-div", hidden: true }
|
||||
div {
|
||||
class: "dangerous-inner-html-div",
|
||||
dangerous_inner_html: "<p>hello dangerous inner html</p>"
|
||||
}
|
||||
input { value: "hello input" }
|
||||
div { class: "style-div", color: "red", "colored text" }
|
||||
div { class: "style-div", color: "red", "colored text" }
|
||||
button {
|
||||
class: "eval-button",
|
||||
onclick: move |_| async move {
|
||||
let mut eval = eval(
|
||||
r#"
|
||||
window.document.title = 'Hello from Dioxus Eval!';
|
||||
dioxus.send("returned eval value");
|
||||
"#,
|
||||
);
|
||||
|
||||
let result = eval.recv().await;
|
||||
if let Ok(serde_json::Value::String(string)) = result {
|
||||
eval_result.set(string);
|
||||
}
|
||||
},
|
||||
"Eval!!!!"
|
||||
"Eval!!!!"
|
||||
"Eval!!!!!"
|
||||
"Eval!!!!"
|
||||
"Eval!!!!"
|
||||
}
|
||||
div { class: "eval-result", "{eval_result}" }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// tracing_wasm::set_as_global_default_with_config(
|
||||
// tracing_wasm::WASMLayerConfigBuilder::default()
|
||||
// .set_max_level(tracing::Level::TRACE)
|
||||
// .build(),
|
||||
// );
|
||||
launch(app);
|
||||
}
|
||||
Reference in new issue
Block a user