diff --git a/docs/src/concepts/old b/docs/src/concepts/old
new file mode 100644
index 000000000..c43f7b4c3
--- /dev/null
+++ b/docs/src/concepts/old
@@ -0,0 +1,32 @@
+
+## All the VNode types
+
+VNodes can be any of:
+- **Element**: a container with a tag name, namespace, attributes, children, and event listeners
+- **Text**: bump allocated text derived from string formatting
+- **Fragments**: a container of elements with no parent
+- **Suspended**: a container for nodes that aren't yet ready to be rendered
+- **Anchor**: a special type of node that is only available when fragments have no children
+
+In practice, only elements and text can be initialized directly while other node types can only be created through hooks or NodeFactory methods.
+
+## Bump Arena Allocation
+
+To speed up the process of building our elements and text, Dioxus uses a special type of memory allocator tuned for large batches of small allocations called a Bump Arena. We use the `bumpalo` allocator which was initially developed for Dioxus' spiritual predecessor: `Dodrio.`
+
+- Bumpalo: [https://github.com/fitzgen/bumpalo](https://github.com/fitzgen/bumpalo)
+- Dodrio: [https://github.com/fitzgen/dodrio](https://github.com/fitzgen/dodrio)
+
+In other frontend frameworks for Rust, nearly every string is allocated using the global allocator. This means that strings in Rust do not benefit from the immutable string interning optimizations that JavaScript engines employ. By using a smaller, faster, more limited allocator, we can increase framework performance, bypassing even the naive WasmBindgen benchmarks for very quick renders.
+
+It's important to note that VNodes are not `'static` - the VNode definition has a lifetime attached to it:
+
+```rust, ignore
+enum VNode<'bump> {
+ VElement { tag: &'static str, children: &'bump [VNode<'bump>] },
+ VText { content: &'bump str },
+ // other VNodes ....
+}
+```
+
+Because VNodes use a bump allocator as their memory backing, they can only be created through the `NodeFactory` API - which we'll cover in the next chapter. This particular detail is important to understand because "rendering" VNodes produces a lifetime attached to the bump arena - which must be explicitly declared when dealing with components that borrow data from their parents.
diff --git a/docs/src/concepts/vnodes.md b/docs/src/concepts/vnodes.md
index df8e8d391..c80c93853 100644
--- a/docs/src/concepts/vnodes.md
+++ b/docs/src/concepts/vnodes.md
@@ -1,64 +1,99 @@
-# VNodes and Elements
+# Declaring your first UI with Elements
-At the heart of Dioxus is the concept of an "element" - a container that can have children, properties, event handlers, and other important attributes. Dioxus only knows how to render the `VNode` datastructure - an Enum variant of an Element, Text, Components, Fragments, and Anchors.
+Every user interface you've ever used is just a symphony of tiny widgets working together to abstract over larger complex functions. In Dioxus, we call these tiny widgets "Elements." Using Components, you can easily compose Elements into larger groups to form even larger structures: Apps.
-Because Dioxus is meant for the Web and uses WebView as a desktop and mobile renderer, almost all elements in Dioxus share properties with their HTML counterpart. When we declare our elements, we'll do so using HTML semantics:
+Because Dioxus is mostly used with HTML/CSS renderers, the default Element "collection" is HTML. Provided the `html` feature is not disabled, we can declare Elements using the `rsx!` macro:
+
+```rust
+#use dioxus::prelude::*;
+rsx!(
+ div {}
+)
+```
+As you might expect, we can render this call using Dioxus-SSR to produce valid HTML:
+
+```rust
+#use dioxus::prelude::*;
+dioxus::ssr::render_lazy(rsx!(
+ div {}
+))
+```
+Produces:
+```html
+
+```
+
+## Composing Elements
+
+Every element has a set of properties that can be rendered in different ways. In particular, each Element may contain other Elements. To achieve this, we can simply declare new Elements within the parent:
+
+```rust
+#use dioxus::prelude::*;
+rsx!(
+ div {
+ h1 {}
+ h2 {}
+ p {}
+ }
+)
+```
+With the default configuration, any Element defined within the `dioxus-html` crate can be declared in this way. To create your own new elements, see the `Custom Elements` Advanced Guide.
+
+## Text Elements
+
+Dioxus also supports a special type of Element: Text. Text Elements do not accept children, but rather just text denoted with double quotes.
+
+```rust
+rsx! (
+ "hello world"
+)
+```
+Text Elements can be composed within other Elements:
+```rust
+rsx! (
+ div {
+ h1 { "hello world" }
+ p { "Some body content" }
+ }
+)
+```
+Text can also be formatted with any value that implements `Display`. We use f-string formatting - a "coming soon" feature for stable Rust that is familiar for Python and JavaScript users:
+
+```rust
+let name = "Bob";
+rsx! ( "hello {name}" )
+```
+
+## Attributes
+
+Every Element in your User Interface will have some sort of properties that the renderer will use when drawing to the screen. These might inform the renderer if the component should be hidden, what its background color should be, or to give it a specific name or ID.
+
+To do this, we simply use the familiar struct-style syntax that Rust provides us. Commas are optional:
```rust
rsx!(
div {
- "hello world"
+ hidden: true,
+ background_color: "blue",
+ class: "card color-{mycolor}"
}
)
```
-As you would expect, this snippet would generate a simple hello-world div. In fact, we can render these nodes directly with the SSR crate:
+Each field is defined as a method on the element in the `dioxus-html` crate. This prevents you from misspelling a field name and lets us provide inline documentation. When you need to use a field not defined as a method, you have two options:
+1) file an issue if the attribute _should_ be enabled
+2) add a custom attribute on-the-fly
+
+To use custom attributes, simply put the attribute name in quotes followed by a colon:
```rust
-dioxus::ssr::render_lazy(rsx!(
+rsx!(
div {
- "hello world"
+ "custom_attr": "important data here"
}
-))
+)
```
-And produce the corresponding html structure:
-```html
-
hello world
-```
+## Listeners
-Our structure declared above is made of two variants of the `VNode` datastructure:
-- A VElement with a tagname of `div`
-- A VText with contents of `"hello world"`
-
-## All the VNode types
-
-VNodes can be any of:
-- **Element**: a container with a tag name, namespace, attributes, children, and event listeners
-- **Text**: bump allocated text derived from string formatting
-- **Fragments**: a container of elements with no parent
-- **Suspended**: a container for nodes that aren't yet ready to be rendered
-- **Anchor**: a special type of node that is only available when fragments have no children
-
-In practice, only elements and text can be initialized directly while other node types can only be created through hooks or NodeFactory methods.
-
-## Bump Arena Allocation
-
-To speed up the process of building our elements and text, Dioxus uses a special type of memory allocator tuned for large batches of small allocations called a Bump Arena. We use the `bumpalo` allocator which was initially developed for Dioxus' spiritual predecessor: `Dodrio.`
-
-- Bumpalo: [https://github.com/fitzgen/bumpalo](https://github.com/fitzgen/bumpalo)
-- Dodrio: [https://github.com/fitzgen/dodrio](https://github.com/fitzgen/dodrio)
-
-In other frontend frameworks for Rust, nearly every string is allocated using the global allocator. This means that strings in Rust do not benefit from the immutable string interning optimizations that JavaScript engines employ. By using a smaller, faster, more limited allocator, we can increase framework performance, bypassing even the naive WasmBindgen benchmarks for very quick renders.
-
-It's important to note that VNodes are not `'static` - the VNode definition has a lifetime attached to it:
-
-```rust, ignore
-enum VNode<'bump> {
- VElement { tag: &'static str, children: &'bump [VNode<'bump>] },
- VText { content: &'bump str },
- // other VNodes ....
-}
-```
-
-Because VNodes use a bump allocator as their memory backing, they can only be created through the `NodeFactory` API - which we'll cover in the next chapter. This particular detail is important to understand because "rendering" VNodes produces a lifetime attached to the bump arena - which must be explicitly declared when dealing with components that borrow data from their parents.
+## Arbitrary Tokens
diff --git a/packages/core-macro/src/lib.rs b/packages/core-macro/src/lib.rs
index d01a27f35..dab35d6fb 100644
--- a/packages/core-macro/src/lib.rs
+++ b/packages/core-macro/src/lib.rs
@@ -182,158 +182,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
/// ```
#[proc_macro]
pub fn rsx(s: TokenStream) -> TokenStream {
- match syn::parse::>(s) {
- Err(e) => e.to_compile_error().into(),
- Ok(s) => s.to_token_stream().into(),
- }
-}
-
-/// The html! macro makes it easy for developers to write jsx-style markup in their components.
-///
-/// ## Complete Reference Guide:
-/// ```
-/// const Example: FC<()> = |(cx, props)|{
-/// let formatting = "formatting!";
-/// let formatting_tuple = ("a", "b");
-/// let lazy_fmt = format_args!("lazily formatted text");
-/// cx.render(html! {
-///
-///
-///
-///
"Some text"
-///
"Some text with {formatting}"
-///
"Formatting basic expressions {formatting_tuple.0} and {formatting_tuple.1}"
-///
-/// "Multiple"
-/// "Text"
-/// "Blocks"
-/// "Use comments as separators in html"
-///
))}
-/// {{
-/// let data = std::collections::HashMap::<&'static str, &'static str>::new();
-/// // Iterators *should* have keys when you can provide them.
-/// // Keys make your app run faster. Make sure your keys are stable, unique, and predictable.
-/// // Using an "ID" associated with your data is a good idea.
-/// data.into_iter().map(|(k, v)| rsx!(
"{v}"
))
-/// }}
-
-/// // Matching
-/// // Matching will throw a Rust error about "no two closures are the same type"
-/// // To fix this, call "render" method or use the "in" syntax to produce VNodes.
-/// // There's nothing we can do about it, sorry :/ (unless you want *really* unhygenic macros)
-/// {match true {
-/// true => rsx!(cx,
"Top text"
),
-/// false => rsx!(cx,
"Bottom text"
),
-/// }}
-///
-/// // Conditional rendering
-/// // Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals.
-/// // You can convert a bool condition to rsx! with .then and .or
-/// {true.then(|| html!())}
-///
-/// // True conditions need to be rendered (same reasons as matching)
-/// {if true {
-/// html!(cx,
"Top text"
)
-/// } else {
-/// html!(cx,
"Bottom text"
)
-/// }}
-///
-/// // returning "None" is a bit noisy... but rare in practice
-/// {None as Option<()>}
-///
-/// // Use the Dioxus type-alias for less noise
-/// {NONE_ELEMENT}
-///
-/// // can also just use empty fragments
-///
-///
-/// // Fragments let you insert groups of nodes without a parent.
-/// // This lets you make components that insert elements as siblings without a container.
-///
"A"
-///
-///
"B"
-///
"C"
-///
-/// "D"
-///
-/// "heavily nested fragments is an antipattern"
-/// "they cause Dioxus to do unnecessary work"
-/// "don't use them carelessly if you can help it"
-///
-///
-///
-/// // Components
-/// // Can accept any paths
-/// // Notice how you still get syntax highlighting and IDE support :)
-///
-///
-///
-///
-/// // Can take properties
-///
-///
-/// // Can take optional properties
-///
-///
-/// // Can pass in props directly as an expression
-/// {{
-/// let props = TallerProps {a: "hello"};
-/// html!()
-/// }}
-///
-/// // Spreading can also be overridden manually
-///
-///
-/// // Can take children too!
-///
-///
"hello world!"
-///
-/// }
-/// })
-/// };
-///
-/// mod baller {
-/// use super::*;
-/// pub struct BallerProps {}
-///
-/// /// This component totally balls
-/// pub fn Baller(cx: Context<()>) -> DomTree {
-/// todo!()
-/// }
-/// }
-///
-/// #[derive(Debug, PartialEq, Props)]
-/// pub struct TallerProps {
-/// a: &'static str,
-/// }
-///
-/// /// This component is taller than most :)
-/// pub fn Taller(cx: Context) -> DomTree {
-/// let b = true;
-/// todo!()
-/// }
-/// ```
-#[proc_macro]
-pub fn html(s: TokenStream) -> TokenStream {
- match syn::parse::>(s) {
+ match syn::parse::(s) {
Err(e) => e.to_compile_error().into(),
Ok(s) => s.to_token_stream().into(),
}
diff --git a/packages/core-macro/src/rsx/ambiguous.rs b/packages/core-macro/src/rsx/ambiguous.rs
index f1ed461e8..71b3a2c4c 100644
--- a/packages/core-macro/src/rsx/ambiguous.rs
+++ b/packages/core-macro/src/rsx/ambiguous.rs
@@ -16,26 +16,22 @@ use syn::{
};
#[allow(clippy::large_enum_variant)]
-pub enum AmbiguousElement {
- Element(Element),
- Component(Component),
+pub enum AmbiguousElement {
+ Element(Element),
+ Component(Component),
}
-impl Parse for AmbiguousElement {
+impl Parse for AmbiguousElement {
fn parse(input: ParseStream) -> Result {
// Try to parse as an absolute path and immediately defer to the componetn
if input.peek(Token![::]) {
- return input
- .parse::>()
- .map(AmbiguousElement::Component);
+ return input.parse::().map(AmbiguousElement::Component);
}
// If not an absolute path, then parse the ident and check if it's a valid tag
if let Ok(pat) = input.fork().parse::() {
if pat.segments.len() > 1 {
- return input
- .parse::>()
- .map(AmbiguousElement::Component);
+ return input.parse::().map(AmbiguousElement::Component);
}
}
@@ -45,45 +41,16 @@ impl Parse for AmbiguousElement {
let first_char = name_str.chars().next().unwrap();
if first_char.is_ascii_uppercase() {
- input
- .parse::>()
- .map(AmbiguousElement::Component)
+ input.parse::().map(AmbiguousElement::Component)
} else {
- input
- .parse::>()
- .map(AmbiguousElement::Element)
+ input.parse::().map(AmbiguousElement::Element)
}
} else {
Err(Error::new(input.span(), "Not a valid Html tag"))
}
}
}
-
-impl Parse for AmbiguousElement {
- fn parse(input: ParseStream) -> Result {
- if input.peek(Token![<]) {
- let forked = input.fork();
- forked.parse::().unwrap();
- let tag = forked.parse::()?;
- let name_str = tag.to_string();
-
- let first_char = name_str.chars().next().unwrap();
- if first_char.is_ascii_uppercase() {
- input
- .parse::>()
- .map(AmbiguousElement::Component)
- } else {
- input
- .parse::>()
- .map(AmbiguousElement::Element)
- }
- } else {
- Err(Error::new(input.span(), "Not a valid Html tag"))
- }
- }
-}
-
-impl ToTokens for AmbiguousElement {
+impl ToTokens for AmbiguousElement {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match self {
AmbiguousElement::Element(el) => el.to_tokens(tokens),
diff --git a/packages/core-macro/src/rsx/body.rs b/packages/core-macro/src/rsx/body.rs
index 375e0344a..b5b487459 100644
--- a/packages/core-macro/src/rsx/body.rs
+++ b/packages/core-macro/src/rsx/body.rs
@@ -7,30 +7,16 @@ use syn::{
use super::*;
-pub struct CallBody {
+pub struct CallBody {
custom_context: Option,
- roots: Vec>,
+ roots: Vec,
}
/// The custom rusty variant of parsing rsx!
-impl Parse for CallBody {
+impl Parse for CallBody {
fn parse(input: ParseStream) -> Result {
let custom_context = try_parse_custom_context(input)?;
- let (_, roots, _) = BodyConfig::::new_call_body().parse_component_body(input)?;
- Ok(Self {
- custom_context,
- roots,
- })
- }
-}
-
-/// The HTML variant of parsing rsx!
-impl Parse for CallBody {
- fn parse(input: ParseStream) -> Result {
- let custom_context = try_parse_custom_context(input)?;
-
- // parsing the contents is almost like parsing the inner of any element, but with no props
- let (_, roots, _) = BodyConfig::::new_call_body().parse_component_body(input)?;
+ let (_, roots, _) = BodyConfig::new_call_body().parse_component_body(input)?;
Ok(Self {
custom_context,
roots,
@@ -50,7 +36,7 @@ fn try_parse_custom_context(input: ParseStream) -> Result