浏览代码

Merge branch 'upstream' into desktop-hot-reload

Evan Almloff 2 年之前
父节点
当前提交
dc8fcf254b
共有 55 个文件被更改,包括 1012 次插入600 次删除
  1. 123 0
      .github/workflows/miri.yml
  2. 1 0
      examples/fermi.rs
  3. 2 2
      packages/autofmt/README.md
  4. 14 175
      packages/autofmt/src/buffer.rs
  5. 28 27
      packages/autofmt/src/component.rs
  6. 101 45
      packages/autofmt/src/element.rs
  7. 8 65
      packages/autofmt/src/expr.rs
  8. 10 9
      packages/autofmt/src/lib.rs
  9. 188 0
      packages/autofmt/src/writer.rs
  10. 3 0
      packages/autofmt/tests/samples.rs
  11. 42 0
      packages/autofmt/tests/samples/commentshard.rsx
  12. 1 1
      packages/core-macro/Cargo.toml
  13. 3 3
      packages/core-macro/README.md
  14. 1 1
      packages/core/Cargo.toml
  15. 9 9
      packages/core/README.md
  16. 2 0
      packages/core/src/bump_frame.rs
  17. 1 0
      packages/core/src/lazynodes.rs
  18. 1 1
      packages/core/src/scopes.rs
  19. 76 0
      packages/core/tests/miri_stress.rs
  20. 1 1
      packages/desktop/Cargo.toml
  21. 4 4
      packages/desktop/README.md
  22. 3 2
      packages/desktop/src/readme.md
  23. 4 4
      packages/dioxus/README.md
  24. 1 1
      packages/fermi/Cargo.toml
  25. 4 4
      packages/fermi/README.md
  26. 1 1
      packages/hooks/Cargo.toml
  27. 2 2
      packages/hooks/README.md
  28. 2 2
      packages/html/Cargo.toml
  29. 5 11
      packages/html/README.md
  30. 10 0
      packages/html/src/web_sys_bind/events.rs
  31. 2 2
      packages/interpreter/README.md
  32. 1 1
      packages/liveview/Cargo.toml
  33. 5 5
      packages/liveview/README.md
  34. 11 2
      packages/liveview/src/main.js
  35. 6 2
      packages/liveview/src/pool.rs
  36. 1 1
      packages/mobile/Cargo.toml
  37. 3 3
      packages/mobile/README.md
  38. 1 1
      packages/native-core-macro/Cargo.toml
  39. 3 3
      packages/native-core-macro/README.md
  40. 3 1
      packages/native-core/Cargo.toml
  41. 4 4
      packages/native-core/README.md
  42. 109 148
      packages/native-core/src/passes.rs
  43. 3 3
      packages/native-core/src/real_dom.rs
  44. 146 0
      packages/native-core/tests/miri_native.rs
  45. 3 3
      packages/router/README.md
  46. 2 0
      packages/rsx-rosetta/src/lib.rs
  47. 2 2
      packages/rsx/Cargo.toml
  48. 2 2
      packages/rsx/README.md
  49. 7 10
      packages/rsx/src/component.rs
  50. 3 1
      packages/rsx/src/element.rs
  51. 1 1
      packages/ssr/Cargo.toml
  52. 23 18
      packages/ssr/README.md
  53. 9 8
      packages/tui/README.md
  54. 6 6
      packages/web/README.md
  55. 5 3
      packages/web/src/dom.rs

+ 123 - 0
.github/workflows/miri.yml

@@ -0,0 +1,123 @@
+name: Miri Tests
+
+on:
+  push:
+    # Run in PRs and for bors, but not on master.
+    branches:
+      - 'auto'
+      - 'try'
+  pull_request:
+    branches:
+      - 'master'
+  schedule:
+    - cron: '6 6 * * *' # At 6:06 UTC every day.
+
+env:
+  CARGO_UNSTABLE_SPARSE_REGISTRY: 'true'
+  RUSTFLAGS: -Dwarnings
+  RUST_BACKTRACE: 1
+  # Change to specific Rust release to pin
+  rust_stable: stable
+  rust_nightly: nightly-2022-11-03
+  rust_clippy: 1.65.0
+  # When updating this, also update:
+  # - README.md
+  # - tokio/README.md
+  # - CONTRIBUTING.md
+  # - tokio/Cargo.toml
+  # - tokio-util/Cargo.toml
+  # - tokio-test/Cargo.toml
+  # - tokio-stream/Cargo.toml
+  # rust_min: 1.49.0
+
+
+
+jobs:
+  test:
+    runs-on: ${{ matrix.os }}
+    env:
+      RUST_BACKTRACE: 1
+      HOST_TARGET: ${{ matrix.host_target }}
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - os: ubuntu-latest
+            host_target: x86_64-unknown-linux-gnu
+          # - os: macos-latest
+          #   host_target: x86_64-apple-darwin
+          # - os: windows-latest
+          #   host_target: i686-pc-windows-msvc
+          # - os: windows-latest
+          #   host_target: i686-pc-windows-msvc
+          # - os: windows-latest
+          #   host_target: i686-pc-windows-msvc
+          # - os: windows-latest
+          #   host_target: i686-pc-windows-msvc
+    steps:
+      - name: Set the tag GC interval to 1 on linux
+        if: runner.os == 'Linux'
+        run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV
+
+      - uses: actions/checkout@v3
+      - name: Install Rust ${{ env.rust_nightly }}
+        uses: dtolnay/rust-toolchain@master
+        with:
+          toolchain: ${{ env.rust_nightly }}
+          components: miri
+      - uses: Swatinem/rust-cache@v2
+      - name: miri
+        # Many of tests in tokio/tests and doctests use #[tokio::test] or
+        # #[tokio::main] that calls epoll_create1 that Miri does not support.
+        # run: cargo miri test --features full --lib --no-fail-fast
+        run: |
+          cargo miri test --package dioxus-core --test miri_stress  -- --exact --nocapture
+          cargo miri test --package dioxus-native-core --test miri_native  -- --exact --nocapture
+
+        # working-directory: tokio
+        env:
+          #  todo: disable memory leaks ignore
+          MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields -Zmiri-ignore-leaks
+          PROPTEST_CASES: 10
+
+      # Cache the global cargo directory, but NOT the local `target` directory which
+      # we cannot reuse anyway when the nightly changes (and it grows quite large
+      # over time).
+      # - name: Add cache for cargo
+      #   id: cache
+      #   uses: actions/cache@v3
+      #   with:
+      #     path: |
+      #       # Taken from <https://doc.rust-lang.org/nightly/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci>.
+      #       ~/.cargo/bin
+      #       ~/.cargo/registry/index
+      #       ~/.cargo/registry/cache
+      #       ~/.cargo/git/db
+      #       # contains package information of crates installed via `cargo install`.
+      #       ~/.cargo/.crates.toml
+      #       ~/.cargo/.crates2.json
+      #     key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
+      #     restore-keys: ${{ runner.os }}-cargo
+
+      # - name: Install rustup-toolchain-install-master
+      #   if: ${{ steps.cache.outputs.cache-hit != 'true' }}
+      #   shell: bash
+      #   run: |
+      #     cargo install -f rustup-toolchain-install-master
+      # - name: Install "master" toolchain
+      #   shell: bash
+      #   run: |
+      #     if [[ ${{ github.event_name }} == 'schedule' ]]; then
+      #       echo "Building against latest rustc git version"
+      #       git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
+      #     fi
+      #      toolchain --host ${{ matrix.host_target }}
+      # - name: Show Rust version
+      #   run: |
+      #     rustup show
+      #     rustc -Vv
+      #     cargo -V
+      # - name: Test
+      #   run: |
+      #     MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress  -- --exact --nocapture
+      #     MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native  -- --exact --nocapture

+ 1 - 0
examples/fermi.rs

@@ -10,6 +10,7 @@ fn main() {
 static NAME: Atom<String> = |_| "world".to_string();
 static NAME: Atom<String> = |_| "world".to_string();
 
 
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
+    use_init_atom_root(&cx);
     let name = use_read(cx, NAME);
     let name = use_read(cx, NAME);
 
 
     cx.render(rsx! {
     cx.render(rsx! {

+ 2 - 2
packages/autofmt/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-autofmt/latest/dioxus-autofmt) |
+[API Docs](https://docs.rs/dioxus-autofmt/latest/dioxus_autofmt) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -45,5 +45,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 14 - 175
packages/autofmt/src/buffer.rs

@@ -1,33 +1,18 @@
-use std::{
-    collections::{HashMap, VecDeque},
-    fmt::{Result, Write},
-};
+//! The output buffer that supports some helpful methods
+//! These are separate from the input so we can lend references between the two
+//!
+//!
+//!
 
 
-use dioxus_rsx::{BodyNode, ElementAttr, ElementAttrNamed, IfmtInput};
-use proc_macro2::{LineColumn, Span};
-use syn::{spanned::Spanned, Expr};
+use std::fmt::{Result, Write};
 
 
-#[derive(Default, Debug)]
+use dioxus_rsx::IfmtInput;
+
+/// The output buffer that tracks indent and string
+#[derive(Debug, Default)]
 pub struct Buffer {
 pub struct Buffer {
-    pub src: Vec<String>,
-    pub cached_formats: HashMap<Location, String>,
     pub buf: String,
     pub buf: String,
     pub indent: usize,
     pub indent: usize,
-    pub comments: VecDeque<usize>,
-}
-
-#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
-pub struct Location {
-    pub line: usize,
-    pub col: usize,
-}
-impl Location {
-    pub fn new(start: LineColumn) -> Self {
-        Self {
-            line: start.line,
-            col: start.column,
-        }
-    }
 }
 }
 
 
 impl Buffer {
 impl Buffer {
@@ -62,160 +47,14 @@ impl Buffer {
         writeln!(self.buf)
         writeln!(self.buf)
     }
     }
 
 
-    // Expects to be written directly into place
-    pub fn write_ident(&mut self, node: &BodyNode) -> Result {
-        match node {
-            BodyNode::Element(el) => self.write_element(el),
-            BodyNode::Component(component) => self.write_component(component),
-            BodyNode::Text(text) => self.write_text(text),
-            BodyNode::RawExpr(exp) => self.write_raw_expr(exp),
-            _ => Ok(()),
-        }
-    }
-
     pub fn write_text(&mut self, text: &IfmtInput) -> Result {
     pub fn write_text(&mut self, text: &IfmtInput) -> Result {
         write!(self.buf, "\"{}\"", text.source.as_ref().unwrap().value())
         write!(self.buf, "\"{}\"", text.source.as_ref().unwrap().value())
     }
     }
-
-    pub fn consume(self) -> Option<String> {
-        Some(self.buf)
-    }
-
-    pub fn write_comments(&mut self, child: Span) -> Result {
-        // collect all comments upwards
-        let start = child.start();
-        let line_start = start.line - 1;
-
-        for (id, line) in self.src[..line_start].iter().enumerate().rev() {
-            if line.trim().starts_with("//") || line.is_empty() {
-                if id != 0 {
-                    self.comments.push_front(id);
-                }
-            } else {
-                break;
-            }
-        }
-
-        let mut last_was_empty = false;
-        while let Some(comment_line) = self.comments.pop_front() {
-            let line = &self.src[comment_line];
-            if line.is_empty() {
-                if !last_was_empty {
-                    self.new_line()?;
-                }
-                last_was_empty = true;
-            } else {
-                last_was_empty = false;
-                self.tabbed_line()?;
-                write!(self.buf, "{}", self.src[comment_line].trim())?;
-            }
-        }
-
-        Ok(())
-    }
-
-    // Push out the indent level and write each component, line by line
-    pub fn write_body_indented(&mut self, children: &[BodyNode]) -> Result {
-        self.indent += 1;
-
-        self.write_body_no_indent(children)?;
-
-        self.indent -= 1;
-        Ok(())
-    }
-
-    pub fn write_body_no_indent(&mut self, children: &[BodyNode]) -> Result {
-        let last_child = children.len();
-
-        for (idx, child) in children.iter().enumerate() {
-            match child {
-                // check if the expr is a short
-                BodyNode::RawExpr { .. } => {
-                    self.tabbed_line()?;
-                    self.write_ident(child)?;
-                    if idx != last_child - 1 {
-                        write!(self.buf, ",")?;
-                    }
-                }
-                _ => {
-                    if self.current_span_is_primary(child.span()) {
-                        self.write_comments(child.span())?;
-                    }
-                    self.tabbed_line()?;
-                    self.write_ident(child)?;
-                }
-            }
-        }
-
-        Ok(())
-    }
-
-    pub(crate) fn is_short_attrs(&mut self, attributes: &[ElementAttrNamed]) -> usize {
-        let mut total = 0;
-
-        for attr in attributes {
-            if self.current_span_is_primary(attr.attr.start()) {
-                'line: for line in self.src[..attr.attr.start().start().line - 1].iter().rev() {
-                    match (line.trim().starts_with("//"), line.is_empty()) {
-                        (true, _) => return 100000,
-                        (_, true) => continue 'line,
-                        _ => break 'line,
-                    }
-                }
-            }
-
-            total += match &attr.attr {
-                ElementAttr::AttrText { value, name } => {
-                    value.source.as_ref().unwrap().value().len() + name.span().line_length() + 3
-                }
-                ElementAttr::AttrExpression { name, value } => {
-                    value.span().line_length() + name.span().line_length() + 3
-                }
-                ElementAttr::CustomAttrText { value, name } => {
-                    value.source.as_ref().unwrap().value().len() + name.value().len() + 3
-                }
-                ElementAttr::CustomAttrExpression { name, value } => {
-                    name.value().len() + value.span().line_length() + 3
-                }
-                ElementAttr::EventTokens { tokens, name } => {
-                    let location = Location::new(tokens.span().start());
-
-                    let len = if let std::collections::hash_map::Entry::Vacant(e) =
-                        self.cached_formats.entry(location)
-                    {
-                        let formatted = prettyplease::unparse_expr(tokens);
-                        let len = if formatted.contains('\n') {
-                            10000
-                        } else {
-                            formatted.len()
-                        };
-                        e.insert(formatted);
-                        len
-                    } else {
-                        self.cached_formats[&location].len()
-                    };
-
-                    len + name.span().line_length() + 3
-                }
-            };
-        }
-
-        total
-    }
-
-    pub fn retrieve_formatted_expr(&mut self, expr: &Expr) -> &str {
-        self.cached_formats
-            .entry(Location::new(expr.span().start()))
-            .or_insert_with(|| prettyplease::unparse_expr(expr))
-            .as_str()
-    }
 }
 }
 
 
-trait SpanLength {
-    fn line_length(&self) -> usize;
-}
-impl SpanLength for Span {
-    fn line_length(&self) -> usize {
-        self.end().line - self.start().line
+impl std::fmt::Write for Buffer {
+    fn write_str(&mut self, s: &str) -> std::fmt::Result {
+        self.buf.push_str(s);
+        Ok(())
     }
     }
 }
 }

+ 28 - 27
packages/autofmt/src/component.rs

@@ -1,4 +1,4 @@
-use crate::{buffer::Location, Buffer};
+use crate::{writer::Location, Writer};
 use dioxus_rsx::*;
 use dioxus_rsx::*;
 use quote::ToTokens;
 use quote::ToTokens;
 use std::fmt::{Result, Write};
 use std::fmt::{Result, Write};
@@ -19,7 +19,7 @@ enum ShortOptimization {
     NoOpt,
     NoOpt,
 }
 }
 
 
-impl Buffer {
+impl Writer {
     pub fn write_component(
     pub fn write_component(
         &mut self,
         &mut self,
         Component {
         Component {
@@ -28,6 +28,7 @@ impl Buffer {
             children,
             children,
             manual_props,
             manual_props,
             prop_gen_args,
             prop_gen_args,
+            ..
         }: &Component,
         }: &Component,
     ) -> Result {
     ) -> Result {
         self.write_component_name(name, prop_gen_args)?;
         self.write_component_name(name, prop_gen_args)?;
@@ -82,46 +83,46 @@ impl Buffer {
         match opt_level {
         match opt_level {
             ShortOptimization::Empty => {}
             ShortOptimization::Empty => {}
             ShortOptimization::Oneliner => {
             ShortOptimization::Oneliner => {
-                write!(self.buf, " ")?;
+                write!(self.out, " ")?;
 
 
                 self.write_component_fields(fields, manual_props, true)?;
                 self.write_component_fields(fields, manual_props, true)?;
 
 
                 if !children.is_empty() && !fields.is_empty() {
                 if !children.is_empty() && !fields.is_empty() {
-                    write!(self.buf, ", ")?;
+                    write!(self.out, ", ")?;
                 }
                 }
 
 
                 for child in children {
                 for child in children {
                     self.write_ident(child)?;
                     self.write_ident(child)?;
                 }
                 }
 
 
-                write!(self.buf, " ")?;
+                write!(self.out, " ")?;
             }
             }
 
 
             ShortOptimization::PropsOnTop => {
             ShortOptimization::PropsOnTop => {
-                write!(self.buf, " ")?;
+                write!(self.out, " ")?;
                 self.write_component_fields(fields, manual_props, true)?;
                 self.write_component_fields(fields, manual_props, true)?;
 
 
                 if !children.is_empty() && !fields.is_empty() {
                 if !children.is_empty() && !fields.is_empty() {
-                    write!(self.buf, ",")?;
+                    write!(self.out, ",")?;
                 }
                 }
 
 
                 self.write_body_indented(children)?;
                 self.write_body_indented(children)?;
-                self.tabbed_line()?;
+                self.out.tabbed_line()?;
             }
             }
 
 
             ShortOptimization::NoOpt => {
             ShortOptimization::NoOpt => {
                 self.write_component_fields(fields, manual_props, false)?;
                 self.write_component_fields(fields, manual_props, false)?;
 
 
                 if !children.is_empty() && !fields.is_empty() {
                 if !children.is_empty() && !fields.is_empty() {
-                    write!(self.buf, ",")?;
+                    write!(self.out, ",")?;
                 }
                 }
 
 
                 self.write_body_indented(children)?;
                 self.write_body_indented(children)?;
-                self.tabbed_line()?;
+                self.out.tabbed_line()?;
             }
             }
         }
         }
 
 
-        write!(self.buf, "}}")?;
+        write!(self.out, "}}")?;
         Ok(())
         Ok(())
     }
     }
 
 
@@ -133,16 +134,16 @@ impl Buffer {
         let mut name = name.to_token_stream().to_string();
         let mut name = name.to_token_stream().to_string();
         name.retain(|c| !c.is_whitespace());
         name.retain(|c| !c.is_whitespace());
 
 
-        write!(self.buf, "{name}")?;
+        write!(self.out, "{name}")?;
 
 
         if let Some(generics) = generics {
         if let Some(generics) = generics {
             let mut written = generics.to_token_stream().to_string();
             let mut written = generics.to_token_stream().to_string();
             written.retain(|c| !c.is_whitespace());
             written.retain(|c| !c.is_whitespace());
 
 
-            write!(self.buf, "{}", written)?;
+            write!(self.out, "{}", written)?;
         }
         }
 
 
-        write!(self.buf, " {{")?;
+        write!(self.out, " {{")?;
 
 
         Ok(())
         Ok(())
     }
     }
@@ -157,18 +158,18 @@ impl Buffer {
 
 
         while let Some(field) = field_iter.next() {
         while let Some(field) = field_iter.next() {
             if !sameline {
             if !sameline {
-                self.indented_tabbed_line()?;
+                self.out.indented_tabbed_line()?;
             }
             }
 
 
             let name = &field.name;
             let name = &field.name;
             match &field.content {
             match &field.content {
                 ContentField::ManExpr(exp) => {
                 ContentField::ManExpr(exp) => {
                     let out = prettyplease::unparse_expr(exp);
                     let out = prettyplease::unparse_expr(exp);
-                    write!(self.buf, "{}: {}", name, out)?;
+                    write!(self.out, "{}: {}", name, out)?;
                 }
                 }
                 ContentField::Formatted(s) => {
                 ContentField::Formatted(s) => {
                     write!(
                     write!(
-                        self.buf,
+                        self.out,
                         "{}: \"{}\"",
                         "{}: \"{}\"",
                         name,
                         name,
                         s.source.as_ref().unwrap().value()
                         s.source.as_ref().unwrap().value()
@@ -178,27 +179,27 @@ impl Buffer {
                     let out = prettyplease::unparse_expr(exp);
                     let out = prettyplease::unparse_expr(exp);
                     let mut lines = out.split('\n').peekable();
                     let mut lines = out.split('\n').peekable();
                     let first = lines.next().unwrap();
                     let first = lines.next().unwrap();
-                    write!(self.buf, "{}: {}", name, first)?;
+                    write!(self.out, "{}: {}", name, first)?;
                     for line in lines {
                     for line in lines {
-                        self.new_line()?;
-                        self.indented_tab()?;
-                        write!(self.buf, "{}", line)?;
+                        self.out.new_line()?;
+                        self.out.indented_tab()?;
+                        write!(self.out, "{}", line)?;
                     }
                     }
                 }
                 }
             }
             }
 
 
             if field_iter.peek().is_some() || manual_props.is_some() {
             if field_iter.peek().is_some() || manual_props.is_some() {
-                write!(self.buf, ",")?;
+                write!(self.out, ",")?;
 
 
                 if sameline {
                 if sameline {
-                    write!(self.buf, " ")?;
+                    write!(self.out, " ")?;
                 }
                 }
             }
             }
         }
         }
 
 
         if let Some(exp) = manual_props {
         if let Some(exp) = manual_props {
             if !sameline {
             if !sameline {
-                self.indented_tabbed_line()?;
+                self.out.indented_tabbed_line()?;
             }
             }
             self.write_manual_props(exp)?;
             self.write_manual_props(exp)?;
         }
         }
@@ -258,10 +259,10 @@ impl Buffer {
 
 
         let first_line = lines.next().unwrap();
         let first_line = lines.next().unwrap();
 
 
-        write!(self.buf, "..{first_line}")?;
+        write!(self.out, "..{first_line}")?;
         for line in lines {
         for line in lines {
-            self.indented_tabbed_line()?;
-            write!(self.buf, "{line}")?;
+            self.out.indented_tabbed_line()?;
+            write!(self.out, "{line}")?;
         }
         }
 
 
         Ok(())
         Ok(())

+ 101 - 45
packages/autofmt/src/element.rs

@@ -1,35 +1,56 @@
-use crate::Buffer;
+use crate::Writer;
 use dioxus_rsx::*;
 use dioxus_rsx::*;
 use proc_macro2::Span;
 use proc_macro2::Span;
-use std::{fmt::Result, fmt::Write};
-use syn::{spanned::Spanned, Expr};
+use std::{
+    fmt::Result,
+    fmt::{self, Write},
+};
+use syn::{spanned::Spanned, token::Brace, Expr};
 
 
 #[derive(Debug)]
 #[derive(Debug)]
 enum ShortOptimization {
 enum ShortOptimization {
-    // Special because we want to print the closing bracket immediately
+    /// Special because we want to print the closing bracket immediately
+    ///
+    /// IE
+    /// `div {}` instead of `div { }`
     Empty,
     Empty,
 
 
-    // Special optimization to put everything on the same line
+    /// Special optimization to put everything on the same line and add some buffer spaces
+    ///
+    /// IE
+    ///
+    /// `div { "asdasd" }` instead of a multiline variant
     Oneliner,
     Oneliner,
 
 
-    // Optimization where children flow but props remain fixed on top
+    /// Optimization where children flow but props remain fixed on top
     PropsOnTop,
     PropsOnTop,
 
 
-    // The noisiest optimization where everything flows
+    /// The noisiest optimization where everything flows
     NoOpt,
     NoOpt,
 }
 }
 
 
-impl Buffer {
-    pub fn write_element(
-        &mut self,
-        Element {
+/*
+// whitespace
+div {
+    // some whitespace
+    class: "asdasd"
+
+    // whjiot
+    asdasd // whitespace
+}
+*/
+
+impl Writer {
+    pub fn write_element(&mut self, el: &Element) -> Result {
+        let Element {
             name,
             name,
             key,
             key,
             attributes,
             attributes,
             children,
             children,
             _is_static,
             _is_static,
-        }: &Element,
-    ) -> Result {
+            brace,
+        } = el;
+
         /*
         /*
             1. Write the tag
             1. Write the tag
             2. Write the key
             2. Write the key
@@ -37,7 +58,7 @@ impl Buffer {
             4. Write the children
             4. Write the children
         */
         */
 
 
-        write!(self.buf, "{name} {{")?;
+        write!(self.out, "{name} {{")?;
 
 
         // decide if we have any special optimizations
         // decide if we have any special optimizations
         // Default with none, opt the cases in one-by-one
         // Default with none, opt the cases in one-by-one
@@ -70,6 +91,9 @@ impl Buffer {
         // If there's nothing at all, empty optimization
         // If there's nothing at all, empty optimization
         if attributes.is_empty() && children.is_empty() && key.is_none() {
         if attributes.is_empty() && children.is_empty() && key.is_none() {
             opt_level = ShortOptimization::Empty;
             opt_level = ShortOptimization::Empty;
+
+            // Write comments if they exist
+            self.write_todo_body(brace)?;
         }
         }
 
 
         // multiline handlers bump everything down
         // multiline handlers bump everything down
@@ -80,55 +104,56 @@ impl Buffer {
         match opt_level {
         match opt_level {
             ShortOptimization::Empty => {}
             ShortOptimization::Empty => {}
             ShortOptimization::Oneliner => {
             ShortOptimization::Oneliner => {
-                write!(self.buf, " ")?;
+                write!(self.out, " ")?;
 
 
                 self.write_attributes(attributes, key, true)?;
                 self.write_attributes(attributes, key, true)?;
 
 
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
-                    write!(self.buf, ", ")?;
+                    write!(self.out, ", ")?;
                 }
                 }
 
 
                 for (id, child) in children.iter().enumerate() {
                 for (id, child) in children.iter().enumerate() {
                     self.write_ident(child)?;
                     self.write_ident(child)?;
                     if id != children.len() - 1 && children.len() > 1 {
                     if id != children.len() - 1 && children.len() > 1 {
-                        write!(self.buf, ", ")?;
+                        write!(self.out, ", ")?;
                     }
                     }
                 }
                 }
 
 
-                write!(self.buf, " ")?;
+                write!(self.out, " ")?;
             }
             }
 
 
             ShortOptimization::PropsOnTop => {
             ShortOptimization::PropsOnTop => {
                 if !attributes.is_empty() || key.is_some() {
                 if !attributes.is_empty() || key.is_some() {
-                    write!(self.buf, " ")?;
+                    write!(self.out, " ")?;
                 }
                 }
                 self.write_attributes(attributes, key, true)?;
                 self.write_attributes(attributes, key, true)?;
 
 
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
-                    write!(self.buf, ",")?;
+                    write!(self.out, ",")?;
                 }
                 }
 
 
                 if !children.is_empty() {
                 if !children.is_empty() {
                     self.write_body_indented(children)?;
                     self.write_body_indented(children)?;
                 }
                 }
-                self.tabbed_line()?;
+                self.out.tabbed_line()?;
             }
             }
 
 
             ShortOptimization::NoOpt => {
             ShortOptimization::NoOpt => {
                 self.write_attributes(attributes, key, false)?;
                 self.write_attributes(attributes, key, false)?;
 
 
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
                 if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
-                    write!(self.buf, ",")?;
+                    write!(self.out, ",")?;
                 }
                 }
 
 
                 if !children.is_empty() {
                 if !children.is_empty() {
                     self.write_body_indented(children)?;
                     self.write_body_indented(children)?;
                 }
                 }
-                self.tabbed_line()?;
+
+                self.out.tabbed_line()?;
             }
             }
         }
         }
 
 
-        write!(self.buf, "}}")?;
+        write!(self.out, "}}")?;
 
 
         Ok(())
         Ok(())
     }
     }
@@ -143,39 +168,39 @@ impl Buffer {
 
 
         if let Some(key) = key {
         if let Some(key) = key {
             if !sameline {
             if !sameline {
-                self.indented_tabbed_line()?;
+                self.out.indented_tabbed_line()?;
             }
             }
             write!(
             write!(
-                self.buf,
+                self.out,
                 "key: \"{}\"",
                 "key: \"{}\"",
                 key.source.as_ref().unwrap().value()
                 key.source.as_ref().unwrap().value()
             )?;
             )?;
             if !attributes.is_empty() {
             if !attributes.is_empty() {
-                write!(self.buf, ",")?;
+                write!(self.out, ",")?;
                 if sameline {
                 if sameline {
-                    write!(self.buf, " ")?;
+                    write!(self.out, " ")?;
                 }
                 }
             }
             }
         }
         }
 
 
         while let Some(attr) = attr_iter.next() {
         while let Some(attr) = attr_iter.next() {
-            self.indent += 1;
+            self.out.indent += 1;
             if !sameline {
             if !sameline {
                 self.write_comments(attr.attr.start())?;
                 self.write_comments(attr.attr.start())?;
             }
             }
-            self.indent -= 1;
+            self.out.indent -= 1;
 
 
             if !sameline {
             if !sameline {
-                self.indented_tabbed_line()?;
+                self.out.indented_tabbed_line()?;
             }
             }
 
 
             self.write_attribute(attr)?;
             self.write_attribute(attr)?;
 
 
             if attr_iter.peek().is_some() {
             if attr_iter.peek().is_some() {
-                write!(self.buf, ",")?;
+                write!(self.out, ",")?;
 
 
                 if sameline {
                 if sameline {
-                    write!(self.buf, " ")?;
+                    write!(self.out, " ")?;
                 }
                 }
             }
             }
         }
         }
@@ -187,19 +212,19 @@ impl Buffer {
         match &attr.attr {
         match &attr.attr {
             ElementAttr::AttrText { name, value } => {
             ElementAttr::AttrText { name, value } => {
                 write!(
                 write!(
-                    self.buf,
+                    self.out,
                     "{name}: \"{value}\"",
                     "{name}: \"{value}\"",
                     value = value.source.as_ref().unwrap().value()
                     value = value.source.as_ref().unwrap().value()
                 )?;
                 )?;
             }
             }
             ElementAttr::AttrExpression { name, value } => {
             ElementAttr::AttrExpression { name, value } => {
                 let out = prettyplease::unparse_expr(value);
                 let out = prettyplease::unparse_expr(value);
-                write!(self.buf, "{}: {}", name, out)?;
+                write!(self.out, "{}: {}", name, out)?;
             }
             }
 
 
             ElementAttr::CustomAttrText { name, value } => {
             ElementAttr::CustomAttrText { name, value } => {
                 write!(
                 write!(
-                    self.buf,
+                    self.out,
                     "\"{name}\": \"{value}\"",
                     "\"{name}\": \"{value}\"",
                     name = name.value(),
                     name = name.value(),
                     value = value.source.as_ref().unwrap().value()
                     value = value.source.as_ref().unwrap().value()
@@ -208,7 +233,7 @@ impl Buffer {
 
 
             ElementAttr::CustomAttrExpression { name, value } => {
             ElementAttr::CustomAttrExpression { name, value } => {
                 let out = prettyplease::unparse_expr(value);
                 let out = prettyplease::unparse_expr(value);
-                write!(self.buf, "\"{}\": {}", name.value(), out)?;
+                write!(self.out, "\"{}\": {}", name.value(), out)?;
             }
             }
 
 
             ElementAttr::EventTokens { name, tokens } => {
             ElementAttr::EventTokens { name, tokens } => {
@@ -220,17 +245,17 @@ impl Buffer {
                 // a one-liner for whatever reason
                 // a one-liner for whatever reason
                 // Does not need a new line
                 // Does not need a new line
                 if lines.peek().is_none() {
                 if lines.peek().is_none() {
-                    write!(self.buf, "{}: {}", name, first)?;
+                    write!(self.out, "{}: {}", name, first)?;
                 } else {
                 } else {
-                    writeln!(self.buf, "{}: {}", name, first)?;
+                    writeln!(self.out, "{}: {}", name, first)?;
 
 
                     while let Some(line) = lines.next() {
                     while let Some(line) = lines.next() {
-                        self.indented_tab()?;
-                        write!(self.buf, "{}", line)?;
+                        self.out.indented_tab()?;
+                        write!(self.out, "{}", line)?;
                         if lines.peek().is_none() {
                         if lines.peek().is_none() {
-                            write!(self.buf, "")?;
+                            write!(self.out, "")?;
                         } else {
                         } else {
-                            writeln!(self.buf)?;
+                            writeln!(self.out)?;
                         }
                         }
                     }
                     }
                 }
                 }
@@ -254,8 +279,6 @@ impl Buffer {
             ""
             ""
         };
         };
 
 
-        // dbg!(beginning);
-
         beginning.is_empty()
         beginning.is_empty()
     }
     }
 
 
@@ -268,6 +291,10 @@ impl Buffer {
         if children.is_empty() {
         if children.is_empty() {
             // todo: allow elements with comments but no children
             // todo: allow elements with comments but no children
             // like div { /* comment */ }
             // like div { /* comment */ }
+            // or
+            // div {
+            //  // some helpful
+            // }
             return Some(0);
             return Some(0);
         }
         }
 
 
@@ -342,6 +369,35 @@ impl Buffer {
             }
             }
         }
         }
     }
     }
+
+    /// empty everything except for some comments
+    fn write_todo_body(&mut self, brace: &Brace) -> fmt::Result {
+        let span = brace.span.span();
+        let start = span.start();
+        let end = span.end();
+
+        if start.line == end.line {
+            return Ok(());
+        }
+
+        writeln!(self.out)?;
+
+        for idx in start.line..end.line {
+            let line = &self.src[idx];
+            if line.trim().starts_with("//") {
+                for _ in 0..self.out.indent + 1 {
+                    write!(self.out, "    ")?
+                }
+                writeln!(self.out, "{}", line.trim()).unwrap();
+            }
+        }
+
+        for _ in 0..self.out.indent {
+            write!(self.out, "    ")?
+        }
+
+        Ok(())
+    }
 }
 }
 
 
 fn get_expr_length(expr: &Expr) -> Option<usize> {
 fn get_expr_length(expr: &Expr) -> Option<usize> {

+ 8 - 65
packages/autofmt/src/expr.rs

@@ -1,45 +1,23 @@
 //! pretty printer for rsx!
 //! pretty printer for rsx!
 use std::fmt::{Result, Write};
 use std::fmt::{Result, Write};
 
 
-use crate::Buffer;
+use crate::Writer;
 
 
-impl Buffer {
+impl Writer {
     pub fn write_raw_expr(&mut self, exp: &syn::Expr) -> Result {
     pub fn write_raw_expr(&mut self, exp: &syn::Expr) -> Result {
         /*
         /*
         We want to normalize the expr to the appropriate indent level.
         We want to normalize the expr to the appropriate indent level.
         */
         */
 
 
-        // in a perfect world, just fire up the rust pretty printer
-        // pretty_print_rust_code_as_if_it_were_rustfmt()
-
         use syn::spanned::Spanned;
         use syn::spanned::Spanned;
         let placement = exp.span();
         let placement = exp.span();
         let start = placement.start();
         let start = placement.start();
         let end = placement.end();
         let end = placement.end();
-        // let num_spaces_desired = (self.indent * 4) as isize;
-
-        // print comments
-        // let mut queued_comments = vec![];
-        // let mut offset = 2;
-        // loop {
-        //     let line = &self.src[start.line - offset];
-        //     if line.trim_start().starts_with("//") {
-        //         queued_comments.push(line);
-        //     } else {
-        //         break;
-        //     }
-
-        //     offset += 1;
-        // }
-        // let had_comments = !queued_comments.is_empty();
-        // for comment in queued_comments.into_iter().rev() {
-        //     writeln!(self.buf, "{}", comment)?;
-        // }
 
 
         // if the expr is on one line, just write it directly
         // if the expr is on one line, just write it directly
         if start.line == end.line {
         if start.line == end.line {
             write!(
             write!(
-                self.buf,
+                self.out,
                 "{}",
                 "{}",
                 &self.src[start.line - 1][start.column - 1..end.column].trim()
                 &self.src[start.line - 1][start.column - 1..end.column].trim()
             )?;
             )?;
@@ -50,7 +28,7 @@ impl Buffer {
         // This involves unshifting the first line if it's aligned
         // This involves unshifting the first line if it's aligned
         let first_line = &self.src[start.line - 1];
         let first_line = &self.src[start.line - 1];
         write!(
         write!(
-            self.buf,
+            self.out,
             "{}",
             "{}",
             &first_line[start.column - 1..first_line.len()].trim()
             &first_line[start.column - 1..first_line.len()].trim()
         )?;
         )?;
@@ -66,7 +44,7 @@ impl Buffer {
         };
         };
 
 
         for (id, line) in self.src[start.line..end.line].iter().enumerate() {
         for (id, line) in self.src[start.line..end.line].iter().enumerate() {
-            writeln!(self.buf)?;
+            writeln!(self.out)?;
             // trim the leading whitespace
             // trim the leading whitespace
             let line = match id {
             let line = match id {
                 x if x == (end.line - start.line) - 1 => &line[..end.column],
                 x if x == (end.line - start.line) - 1 => &line[..end.column],
@@ -75,52 +53,17 @@ impl Buffer {
 
 
             if offset < 0 {
             if offset < 0 {
                 for _ in 0..-offset {
                 for _ in 0..-offset {
-                    write!(self.buf, " ")?;
+                    write!(self.out, " ")?;
                 }
                 }
 
 
-                write!(self.buf, "{}", line)?;
+                write!(self.out, "{}", line)?;
             } else {
             } else {
                 let offset = offset as usize;
                 let offset = offset as usize;
                 let right = &line[offset..];
                 let right = &line[offset..];
-                write!(self.buf, "{}", right)?;
+                write!(self.out, "{}", right)?;
             }
             }
         }
         }
 
 
-        // let first = &self.src[start.line - 1];
-        // let num_spaces_real = first.chars().take_while(|c| c.is_whitespace()).count() as isize;
-        // let offset = num_spaces_real - num_spaces_desired;
-
-        // for (row, line) in self.src[start.line - 1..end.line].iter().enumerate() {
-        //     let line = match row {
-        //         0 => &line[start.column - 1..],
-        //         a if a == (end.line - start.line) => &line[..end.column - 1],
-        //         _ => line,
-        //     };
-
-        //     writeln!(self.buf)?;
-        //     // trim the leading whitespace
-        //     if offset < 0 {
-        //         for _ in 0..-offset {
-        //             write!(self.buf, " ")?;
-        //         }
-
-        //         write!(self.buf, "{}", line)?;
-        //     } else {
-        //         let offset = offset as usize;
-        //         let right = &line[offset..];
-        //         write!(self.buf, "{}", right)?;
-        //     }
-        // }
-
         Ok(())
         Ok(())
     }
     }
 }
 }
-
-// :(
-// fn pretty_print_rust_code_as_if_it_were_rustfmt(code: &str) -> String {
-//     let formatted = prettyplease::unparse_expr(exp);
-//     for line in formatted.lines() {
-//         write!(self.buf, "{}", line)?;
-//         self.new_line()?;
-//     }
-// }

+ 10 - 9
packages/autofmt/src/lib.rs

@@ -1,13 +1,14 @@
 use dioxus_rsx::CallBody;
 use dioxus_rsx::CallBody;
 
 
-use crate::buffer::*;
 use crate::util::*;
 use crate::util::*;
+use crate::writer::*;
 
 
 mod buffer;
 mod buffer;
 mod component;
 mod component;
 mod element;
 mod element;
 mod expr;
 mod expr;
 mod util;
 mod util;
+mod writer;
 
 
 /// A modification to the original file to be applied by an IDE
 /// A modification to the original file to be applied by an IDE
 ///
 ///
@@ -101,10 +102,9 @@ pub fn fmt_file(contents: &str) -> Vec<FormattedBlock> {
 }
 }
 
 
 pub fn write_block_out(body: CallBody) -> Option<String> {
 pub fn write_block_out(body: CallBody) -> Option<String> {
-    let mut buf = Buffer {
+    let mut buf = Writer {
         src: vec!["".to_string()],
         src: vec!["".to_string()],
-        indent: 0,
-        ..Buffer::default()
+        ..Writer::default()
     };
     };
 
 
     // Oneliner optimization
     // Oneliner optimization
@@ -120,12 +120,13 @@ pub fn write_block_out(body: CallBody) -> Option<String> {
 pub fn fmt_block(block: &str, indent_level: usize) -> Option<String> {
 pub fn fmt_block(block: &str, indent_level: usize) -> Option<String> {
     let body = syn::parse_str::<dioxus_rsx::CallBody>(block).ok()?;
     let body = syn::parse_str::<dioxus_rsx::CallBody>(block).ok()?;
 
 
-    let mut buf = Buffer {
+    let mut buf = Writer {
         src: block.lines().map(|f| f.to_string()).collect(),
         src: block.lines().map(|f| f.to_string()).collect(),
-        indent: indent_level,
-        ..Buffer::default()
+        ..Writer::default()
     };
     };
 
 
+    buf.out.indent = indent_level;
+
     // Oneliner optimization
     // Oneliner optimization
     if buf.is_short_children(&body.roots).is_some() {
     if buf.is_short_children(&body.roots).is_some() {
         buf.write_ident(&body.roots[0]).unwrap();
         buf.write_ident(&body.roots[0]).unwrap();
@@ -134,8 +135,8 @@ pub fn fmt_block(block: &str, indent_level: usize) -> Option<String> {
     }
     }
 
 
     // writing idents leaves the final line ended at the end of the last ident
     // writing idents leaves the final line ended at the end of the last ident
-    if buf.buf.contains('\n') {
-        buf.new_line().unwrap();
+    if buf.out.buf.contains('\n') {
+        buf.out.new_line().unwrap();
     }
     }
 
 
     buf.consume()
     buf.consume()

+ 188 - 0
packages/autofmt/src/writer.rs

@@ -0,0 +1,188 @@
+use dioxus_rsx::{BodyNode, ElementAttr, ElementAttrNamed};
+use proc_macro2::{LineColumn, Span};
+use std::{
+    collections::{HashMap, VecDeque},
+    fmt::{Result, Write},
+};
+use syn::{spanned::Spanned, Expr};
+
+use crate::buffer::Buffer;
+
+#[derive(Debug, Default)]
+pub struct Writer {
+    pub src: Vec<String>,
+    pub cached_formats: HashMap<Location, String>,
+    pub comments: VecDeque<usize>,
+    pub out: Buffer,
+}
+
+#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
+pub struct Location {
+    pub line: usize,
+    pub col: usize,
+}
+impl Location {
+    pub fn new(start: LineColumn) -> Self {
+        Self {
+            line: start.line,
+            col: start.column,
+        }
+    }
+}
+
+impl Writer {
+    // Expects to be written directly into place
+    pub fn write_ident(&mut self, node: &BodyNode) -> Result {
+        match node {
+            BodyNode::Element(el) => self.write_element(el),
+            BodyNode::Component(component) => self.write_component(component),
+            BodyNode::Text(text) => self.out.write_text(text),
+            BodyNode::RawExpr(exp) => self.write_raw_expr(exp),
+            _ => Ok(()),
+        }
+    }
+
+    pub fn consume(self) -> Option<String> {
+        Some(self.out.buf)
+    }
+
+    pub fn write_comments(&mut self, child: Span) -> Result {
+        // collect all comments upwards
+        let start = child.start();
+        let line_start = start.line - 1;
+
+        for (id, line) in self.src[..line_start].iter().enumerate().rev() {
+            if line.trim().starts_with("//") || line.is_empty() {
+                if id != 0 {
+                    self.comments.push_front(id);
+                }
+            } else {
+                break;
+            }
+        }
+
+        let mut last_was_empty = false;
+        while let Some(comment_line) = self.comments.pop_front() {
+            let line = &self.src[comment_line];
+            if line.is_empty() {
+                if !last_was_empty {
+                    self.out.new_line()?;
+                }
+                last_was_empty = true;
+            } else {
+                last_was_empty = false;
+                self.out.tabbed_line()?;
+                write!(self.out, "{}", self.src[comment_line].trim())?;
+            }
+        }
+
+        Ok(())
+    }
+
+    // Push out the indent level and write each component, line by line
+    pub fn write_body_indented(&mut self, children: &[BodyNode]) -> Result {
+        self.out.indent += 1;
+
+        self.write_body_no_indent(children)?;
+
+        self.out.indent -= 1;
+        Ok(())
+    }
+
+    pub fn write_body_no_indent(&mut self, children: &[BodyNode]) -> Result {
+        let last_child = children.len();
+        let iter = children.iter().peekable().enumerate();
+
+        for (idx, child) in iter {
+            if self.current_span_is_primary(child.span()) {
+                self.write_comments(child.span())?;
+            }
+
+            match child {
+                // check if the expr is a short
+                BodyNode::RawExpr { .. } => {
+                    self.out.tabbed_line()?;
+                    self.write_ident(child)?;
+                    if idx != last_child - 1 {
+                        write!(self.out, ",")?;
+                    }
+                }
+                _ => {
+                    self.out.tabbed_line()?;
+                    self.write_ident(child)?;
+                }
+            }
+        }
+
+        Ok(())
+    }
+
+    pub(crate) fn is_short_attrs(&mut self, attributes: &[ElementAttrNamed]) -> usize {
+        let mut total = 0;
+
+        for attr in attributes {
+            if self.current_span_is_primary(attr.attr.start()) {
+                'line: for line in self.src[..attr.attr.start().start().line - 1].iter().rev() {
+                    match (line.trim().starts_with("//"), line.is_empty()) {
+                        (true, _) => return 100000,
+                        (_, true) => continue 'line,
+                        _ => break 'line,
+                    }
+                }
+            }
+
+            total += match &attr.attr {
+                ElementAttr::AttrText { value, name } => {
+                    value.source.as_ref().unwrap().value().len() + name.span().line_length() + 3
+                }
+                ElementAttr::AttrExpression { name, value } => {
+                    value.span().line_length() + name.span().line_length() + 3
+                }
+                ElementAttr::CustomAttrText { value, name } => {
+                    value.source.as_ref().unwrap().value().len() + name.value().len() + 3
+                }
+                ElementAttr::CustomAttrExpression { name, value } => {
+                    name.value().len() + value.span().line_length() + 3
+                }
+                ElementAttr::EventTokens { tokens, name } => {
+                    let location = Location::new(tokens.span().start());
+
+                    let len = if let std::collections::hash_map::Entry::Vacant(e) =
+                        self.cached_formats.entry(location)
+                    {
+                        let formatted = prettyplease::unparse_expr(tokens);
+                        let len = if formatted.contains('\n') {
+                            10000
+                        } else {
+                            formatted.len()
+                        };
+                        e.insert(formatted);
+                        len
+                    } else {
+                        self.cached_formats[&location].len()
+                    };
+
+                    len + name.span().line_length() + 3
+                }
+            };
+        }
+
+        total
+    }
+
+    pub fn retrieve_formatted_expr(&mut self, expr: &Expr) -> &str {
+        self.cached_formats
+            .entry(Location::new(expr.span().start()))
+            .or_insert_with(|| prettyplease::unparse_expr(expr))
+            .as_str()
+    }
+}
+
+trait SpanLength {
+    fn line_length(&self) -> usize;
+}
+impl SpanLength for Span {
+    fn line_length(&self) -> usize {
+        self.end().line - self.start().line
+    }
+}

+ 3 - 0
packages/autofmt/tests/samples.rs

@@ -30,3 +30,6 @@ twoway! ("key" => key);
 
 
 // Disabled because we can't handle comments on exprs yet
 // Disabled because we can't handle comments on exprs yet
 twoway! ("multirsx" => multirsx);
 twoway! ("multirsx" => multirsx);
+
+// Disabled because we can't handle comments on exprs yet
+twoway! ("commentshard" => commentshard);

+ 42 - 0
packages/autofmt/tests/samples/commentshard.rsx

@@ -0,0 +1,42 @@
+rsx! {
+    // Comments
+    div {
+        // Comments
+        class: "asdasd",
+
+        // Comments
+        "hello world"
+
+        // Comments
+        expr1,
+
+        // Comments
+        expr2,
+
+        // Comments
+        // Comments
+        // Comments
+        // Comments
+        // Comments
+        expr3,
+
+        div {
+            // todo some work in here
+        }
+
+        div {
+            // todo some work in here
+            // todo some work in here
+            //
+            // todo some work in here
+        }
+
+        div {
+            // todo some work in here
+            class: "hello world",
+
+            // todo some work in here
+            class: "hello world"
+        }
+    }
+}

+ 1 - 1
packages/core-macro/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 
 [lib]
 [lib]

+ 3 - 3
packages/core-macro/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-core-macro/latest/dioxus-core-macro) |
+[API Docs](https://docs.rs/dioxus-core-macro/latest/dioxus_core_macro) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -29,7 +29,7 @@
 `dioxus-core-macro` provides a handful of helpful macros used by the `dioxus` crate. These include:
 `dioxus-core-macro` provides a handful of helpful macros used by the `dioxus` crate. These include:
 
 
 - The `rsx!` macro that underpins templates and node creation
 - The `rsx!` macro that underpins templates and node creation
-- The `inline_props` that transforms function arguments into an auto-derived struct
+- The `inline_props` macro transforms function arguments into an auto-derived struct
 - The `format_args_f` macro which allows f-string formatting with support for expressions
 - The `format_args_f` macro which allows f-string formatting with support for expressions
 
 
 
 
@@ -44,5 +44,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 1 - 1
packages/core/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 
 
 
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

+ 9 - 9
packages/core/README.md

@@ -13,7 +13,7 @@ dioxus-core is a fast and featureful VirtualDom implementation written in and fo
 - Error boundaries through the `anyhow` crate
 - Error boundaries through the `anyhow` crate
 - Customizable memoization
 - Customizable memoization
 
 
-If just starting out, check out the Guides first.
+If you are just starting, check out the Guides first.
 
 
 # General Theory
 # General Theory
 
 
@@ -21,7 +21,7 @@ The dioxus-core `VirtualDom` object is built around the concept of a `Template`.
 
 
 Each component in the VirtualDom works as a dedicated render loop where re-renders are triggered by events external to the VirtualDom, or from the components themselves.
 Each component in the VirtualDom works as a dedicated render loop where re-renders are triggered by events external to the VirtualDom, or from the components themselves.
 
 
-When each component re-renders, it must return an `Element`. In Dioxus, the `Element` type is an alias for `Result<VNode>`. Between two renders, Dioxus compares the inner `VNode` object, and calculates the differences of the dynamic portions of each internal `Template`. If any attributes or elements are different between the old layout and new layout, Dioxus will write modifications to the `Mutations` object.
+When each component re-renders, it must return an `Element`. In Dioxus, the `Element` type is an alias for `Result<VNode>`. Between two renders, Dioxus compares the inner `VNode` object and calculates the differences between the dynamic portions of each internal `Template`. If any attributes or elements are different between the old layout and the new layout, Dioxus will write modifications to the `Mutations` object.
 
 
 Dioxus expects the target renderer to save its nodes in a list. Each element is given a numerical ID which can be used to directly index into that list for O(1) lookups.
 Dioxus expects the target renderer to save its nodes in a list. Each element is given a numerical ID which can be used to directly index into that list for O(1) lookups.
 
 
@@ -63,7 +63,7 @@ dom.wait_for_work().await;
 dom.render_with_deadline(tokio::time::sleep(Duration::from_millis(16)));
 dom.render_with_deadline(tokio::time::sleep(Duration::from_millis(16)));
 ```
 ```
 
 
-If an event occurs from outside the virtualdom while waiting for work, then we can cancel the wait using a `select!` block and inject the event.
+If an event occurs from outside the VirtualDom while waiting for work, then we can cancel the wait using a `select!` block and inject the event.
 
 
 ```rust, ignore
 ```rust, ignore
 loop {
 loop {
@@ -88,18 +88,18 @@ Dioxus-core builds off the many frameworks that came before it. Notably, Dioxus
 - React: hooks, concurrency, suspense
 - React: hooks, concurrency, suspense
 - Dodrio: bump allocation, double buffering, and some diffing architecture
 - Dodrio: bump allocation, double buffering, and some diffing architecture
 
 
-Dioxus-core leverages some really cool techniques and hits a very high level of parity with mature frameworks. However, Dioxus also brings some new unique features:
+Dioxus-core hits a very high level of parity with mature frameworks. However, Dioxus also brings some new unique features:
 
 
 - managed lifetimes for borrowed data
 - managed lifetimes for borrowed data
 - placeholder approach for suspended vnodes
 - placeholder approach for suspended vnodes
 - fiber/interruptible diffing algorithm
 - fiber/interruptible diffing algorithm
-- custom memory allocator for vnodes and all text content
+- custom memory allocator for VNodes and all text content
 - support for fragments w/ lazy normalization
 - support for fragments w/ lazy normalization
 - slab allocator for scopes
 - slab allocator for scopes
-- mirrored-slab approach for remote vdoms
+- mirrored-slab approach for remote VirtualDoms
 - dedicated subtrees for rendering into separate contexts from the same app
 - dedicated subtrees for rendering into separate contexts from the same app
 
 
-There's certainly more to the story, but these optimizations make Dioxus memory use and allocation count extremely minimal. For an average application, it is possible that zero allocations will need to be performed once the app has been loaded. Only when new components are added to the dom will allocations occur. For a given component, the space of old VNodes is dynamically recycled as new nodes are added. Additionally, Dioxus tracks the average memory footprint of previous components to estimate how much memory allocate for future components.
+There's certainly more to the story, but these optimizations make Dioxus memory use and allocation count extremely minimal. For an average application, no allocations may be needed once the app has been loaded. Only when new components are added to the dom will allocations occur. For a given component, the space of old VNodes is dynamically recycled as new nodes are added. Additionally, Dioxus tracks the average memory footprint of previous components to estimate how much memory allocate for future components.
 
 
 All in all, Dioxus treats memory as a valuable resource. Combined with the memory-efficient footprint of Wasm compilation, Dioxus apps can scale to thousands of components and still stay snappy.
 All in all, Dioxus treats memory as a valuable resource. Combined with the memory-efficient footprint of Wasm compilation, Dioxus apps can scale to thousands of components and still stay snappy.
 
 
@@ -112,5 +112,5 @@ The final implementation of Dioxus must:
 - Be concurrent. Components should be able to pause rendering to let the screen paint the next frame.
 - Be concurrent. Components should be able to pause rendering to let the screen paint the next frame.
 - Be disconnected from a specific renderer (no WebSys dependency in the core crate).
 - Be disconnected from a specific renderer (no WebSys dependency in the core crate).
 - Support server-side-rendering (SSR). VNodes should render to a string that can be served via a web server.
 - Support server-side-rendering (SSR). VNodes should render to a string that can be served via a web server.
-- Be "live". Components should be able to be both server rendered and client rendered without needing frontend APIs.
-- Be modular. Components and hooks should be work anywhere without worrying about target platform.
+- Be "live". Components should be able to be both server-rendered and client rendered without needing frontend APIs.
+- Be modular. Components and hooks should work anywhere without worrying about the target platform.

+ 2 - 0
packages/core/src/bump_frame.rs

@@ -30,6 +30,8 @@ impl BumpFrame {
     pub(crate) fn bump(&self) -> &Bump {
     pub(crate) fn bump(&self) -> &Bump {
         unsafe { &*self.bump.get() }
         unsafe { &*self.bump.get() }
     }
     }
+
+    #[allow(clippy::mut_from_ref)]
     pub(crate) unsafe fn bump_mut(&self) -> &mut Bump {
     pub(crate) unsafe fn bump_mut(&self) -> &mut Bump {
         unsafe { &mut *self.bump.get() }
         unsafe { &mut *self.bump.get() }
     }
     }

+ 1 - 0
packages/core/src/lazynodes.rs

@@ -11,6 +11,7 @@
 //! The logic for this was borrowed from <https://docs.rs/stack_dst/0.6.1/stack_dst/>. Unfortunately, this crate does not
 //! The logic for this was borrowed from <https://docs.rs/stack_dst/0.6.1/stack_dst/>. Unfortunately, this crate does not
 //! support non-static closures, so we've implemented the core logic of `ValueA` in this module.
 //! support non-static closures, so we've implemented the core logic of `ValueA` in this module.
 
 
+#[allow(unused_imports)]
 use smallbox::{smallbox, space::S16, SmallBox};
 use smallbox::{smallbox, space::S16, SmallBox};
 
 
 use crate::{innerlude::VNode, ScopeState};
 use crate::{innerlude::VNode, ScopeState};

+ 1 - 1
packages/core/src/scopes.rs

@@ -131,7 +131,7 @@ impl<'src> ScopeState {
     /// If you need to allocate items that need to be dropped, use bumpalo's box.
     /// If you need to allocate items that need to be dropped, use bumpalo's box.
     pub fn bump(&self) -> &Bump {
     pub fn bump(&self) -> &Bump {
         // note that this is actually the previous frame since we use that as scratch space while the component is rendering
         // note that this is actually the previous frame since we use that as scratch space while the component is rendering
-        &self.previous_frame().bump()
+        self.previous_frame().bump()
     }
     }
 
 
     /// Get a handle to the currently active head node arena for this Scope
     /// Get a handle to the currently active head node arena for this Scope

+ 76 - 0
packages/core/tests/miri_stress.rs

@@ -137,6 +137,82 @@ fn free_works_on_root_hooks() {
     assert_eq!(Rc::strong_count(&ptr), 1);
     assert_eq!(Rc::strong_count(&ptr), 1);
 }
 }
 
 
+#[test]
+fn supports_async() {
+    use std::time::Duration;
+    use tokio::time::sleep;
+
+    fn app(cx: Scope) -> Element {
+        let colors = use_state(&cx, || vec!["green", "blue", "red"]);
+        let padding = use_state(&cx, || 10);
+
+        use_effect(&cx, colors, |colors| async move {
+            sleep(Duration::from_millis(1000)).await;
+            colors.with_mut(|colors| colors.reverse());
+        });
+
+        use_effect(&cx, padding, |padding| async move {
+            sleep(Duration::from_millis(10)).await;
+            padding.with_mut(|padding| {
+                if *padding < 65 {
+                    *padding += 1;
+                } else {
+                    *padding = 5;
+                }
+            });
+        });
+
+        let big = colors[0];
+        let mid = colors[1];
+        let small = colors[2];
+
+        cx.render(rsx! {
+            div {
+                background: "{big}",
+                height: "stretch",
+                width: "stretch",
+                padding: "50",
+                label {
+                    "hello",
+                }
+                div {
+                    background: "{mid}",
+                    height: "auto",
+                    width: "stretch",
+                    padding: "{padding}",
+                    label {
+                        "World",
+                    }
+                    div {
+                        background: "{small}",
+                        height: "auto",
+                        width: "stretch",
+                        padding: "20",
+                        label {
+                            "ddddddd",
+                        }
+                    }
+                },
+            }
+        })
+    }
+
+    let rt = tokio::runtime::Builder::new_current_thread()
+        .enable_time()
+        .build()
+        .unwrap();
+
+    rt.block_on(async {
+        let mut dom = VirtualDom::new(app);
+        let _ = dom.rebuild();
+
+        for x in 0..10 {
+            let _ = dom.wait_for_work().await;
+            let edits = dom.render_immediate();
+        }
+    });
+}
+
 // #[test]
 // #[test]
 // fn old_props_arent_stale() {
 // fn old_props_arent_stale() {
 //     fn app(cx: Scope) -> Element {
 //     fn app(cx: Scope) -> Element {

+ 1 - 1
packages/desktop/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 
 [dependencies]
 [dependencies]

+ 4 - 4
packages/desktop/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-desktop/latest/dioxus-desktop) |
+[API Docs](https://docs.rs/dioxus-desktop/latest/dioxus_desktop) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -37,10 +37,10 @@ This requires that webview is installed on the target system. WebView is install
 ## Features
 ## Features
 
 
 - Simple, one-line launch for desktop apps
 - Simple, one-line launch for desktop apps
-- Dioxus virtualdom running on a native thread
+- Dioxus VirtualDom running on a native thread
 - Full HTML/CSS support via `wry` and `tao`
 - Full HTML/CSS support via `wry` and `tao`
 - Exposed `window` and `Proxy` types from tao for direct window manipulation
 - Exposed `window` and `Proxy` types from tao for direct window manipulation
-- Helpful hooks for
+- Helpful hooks for accessing the window, WebView, and running javascript.
 
 
 ## Contributing
 ## Contributing
 
 
@@ -53,5 +53,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 3 - 2
packages/desktop/src/readme.md

@@ -18,10 +18,11 @@ $ cargo new --bin demo
 $ cd app
 $ cd app
 ```
 ```
 
 
-Add Dioxus with the `desktop` feature:
+Add Dioxus and the `desktop` renderer feature:
 
 
 ```shell
 ```shell
-$ cargo add dioxus --features desktop
+$ cargo add dioxus
+$ cargo add dioxus-desktop
 ```
 ```
 
 
 Edit your `main.rs`:
 Edit your `main.rs`:

+ 4 - 4
packages/dioxus/README.md

@@ -229,7 +229,7 @@ of logic. Hooks provide us a way of retrieving state from the `Scope` and using
 it to render UI elements.
 it to render UI elements.
 
 
 By convention, all hooks are functions that should start with `use_`. We can
 By convention, all hooks are functions that should start with `use_`. We can
-use hooks to define state and modify it from within listeners.
+use hooks to define the state and modify it from within listeners.
 
 
 ```rust, ignore
 ```rust, ignore
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
@@ -249,7 +249,7 @@ In a sense, hooks let us add a field of state to our component without declaring
 an explicit state struct. However, this means we need to "load" the struct in the right
 an explicit state struct. However, this means we need to "load" the struct in the right
 order. If that order is wrong, then the hook will pick the wrong state and panic.
 order. If that order is wrong, then the hook will pick the wrong state and panic.
 
 
-Most hooks you'll write are simply composition of other hooks:
+Most hooks you'll write are simply compositions of other hooks:
 
 
 ```rust, ignore
 ```rust, ignore
 fn use_username(cx: &ScopeState, id: Uuid) -> bool {
 fn use_username(cx: &ScopeState, id: Uuid) -> bool {
@@ -309,7 +309,7 @@ Beyond this overview, Dioxus supports:
 
 
 Good luck!
 Good luck!
 
 
-## Inspiration, Resources, Alternatives and Credits
+## Inspiration, Resources, Alternatives, and Credits
 
 
 Dioxus is inspired by:
 Dioxus is inspired by:
 - React: for its hooks, concurrency, suspense
 - React: for its hooks, concurrency, suspense
@@ -318,7 +318,7 @@ Dioxus is inspired by:
 Alternatives to Dioxus include:
 Alternatives to Dioxus include:
 - Yew: supports function components and web, but no SSR, borrowed data, or bump allocation. Rather slow at times.
 - Yew: supports function components and web, but no SSR, borrowed data, or bump allocation. Rather slow at times.
 - Percy: supports function components, web, ssr, but lacks state management
 - Percy: supports function components, web, ssr, but lacks state management
-- Sycamore: supports function components, web, ssr, but closer to SolidJS than React
+- Sycamore: supports function components, web, ssr, but is closer to SolidJS than React
 - MoonZoom/Seed: opinionated frameworks based on the Elm model (message, update) - no hooks
 - MoonZoom/Seed: opinionated frameworks based on the Elm model (message, update) - no hooks
 
 
 We've put a lot of work into making Dioxus ergonomic and *familiar*.
 We've put a lot of work into making Dioxus ergonomic and *familiar*.

+ 1 - 1
packages/fermi/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react", "state-management"]
 
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 

+ 4 - 4
packages/fermi/README.md

@@ -40,9 +40,9 @@ Inspired by atom-based state management solutions, all state in Fermi starts as
 static NAME: Atom<&str> = |_| "Dioxus";
 static NAME: Atom<&str> = |_| "Dioxus";
 ```
 ```
 
 
-From anywhere in our app, we can read our the value of our atom:
+From anywhere in our app, we can read the value of our atom:
 
 
-```rust, ignore
+```rust, ignores
 fn NameCard(cx: Scope) -> Element {
 fn NameCard(cx: Scope) -> Element {
     let name = use_read(cx, NAME);
     let name = use_read(cx, NAME);
     cx.render(rsx!{ h1 { "Hello, {name}"} })
     cx.render(rsx!{ h1 { "Hello, {name}"} })
@@ -83,9 +83,9 @@ $ cargo run --example fermi
 
 
 ## Features
 ## Features
 
 
-Broadly our feature set to required to be released includes:
+Broadly our feature set required to be released includes:
 - [x] Support for Atoms
 - [x] Support for Atoms
-- [x] Support for AtomRef (for values that aren't clone)
+- [x] Support for AtomRef (for values that aren't `Clone`)
 - [ ] Support for Atom Families
 - [ ] Support for Atom Families
 - [ ] Support for memoized Selectors
 - [ ] Support for memoized Selectors
 - [ ] Support for memoized SelectorFamilies
 - [ ] Support for memoized SelectorFamilies

+ 1 - 1
packages/hooks/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 
 [dependencies]
 [dependencies]

+ 2 - 2
packages/hooks/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-hooks/latest/dioxus-hooks) |
+[API Docs](https://docs.rs/dioxus-hooks/latest/dioxus_hooks) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -54,5 +54,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 2 - 2
packages/html/Cargo.toml

@@ -7,8 +7,8 @@ description = "HTML Element pack for Dioxus - a concurrent renderer-agnostic Vir
 license = "MIT/Apache-2.0"
 license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
-documentation = "https://docs.rs/dioxus"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+documentation = "https://dioxuslabs.com"
+keywords = ["dom", "ui", "gui", "react"]
 
 
 [dependencies]
 [dependencies]
 dioxus-core = { path = "../core", version = "^0.3.0" }
 dioxus-core = { path = "../core", version = "^0.3.0" }

+ 5 - 11
packages/html/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-html/latest/dioxus-html) |
+[API Docs](https://docs.rs/dioxus-html/latest/dioxus_html) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -61,7 +61,7 @@ impl DioxusElement for div {
 
 
 All elements should be defined as a zero-sized-struct (also known as unit struct). These structs are zero-cost and just provide the type-level trickery to Rust for compile-time correct templates.
 All elements should be defined as a zero-sized-struct (also known as unit struct). These structs are zero-cost and just provide the type-level trickery to Rust for compile-time correct templates.
 
 
-Attributes would then be implemented as methods on these unit structs.
+Attributes would then be implemented as constants on these unit structs.
 
 
 The HTML namespace is defined mostly with macros. However, the expanded form would look something like this:
 The HTML namespace is defined mostly with macros. However, the expanded form would look something like this:
 ```rust
 ```rust
@@ -71,14 +71,8 @@ impl DioxusElement for base {
     const NAME_SPACE: Option<&'static str> = None;
     const NAME_SPACE: Option<&'static str> = None;
 }
 }
 impl base {
 impl base {
-    #[inline]
-    fn href<'a>(&self, f: NodeFactory<'a>, v: Arguments) -> Attribute<'a> {
-        f.attr("href", v, None, false)
-    }
-    #[inline]
-    fn target<'a>(&self, f: NodeFactory<'a>, v: Arguments) -> Attribute<'a> {
-        f.attr("target", v, None, false)
-    }
+    const href: (&'static str, Option<'static str>, bool) = ("href", None, false);
+    const target: (&'static str, Option<'static str>, bool) = ("target", None, false);
 }
 }
 ```
 ```
 Because attributes are defined as methods on the unit struct, they guard the attribute creation behind a compile-time correct interface.
 Because attributes are defined as methods on the unit struct, they guard the attribute creation behind a compile-time correct interface.
@@ -114,5 +108,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 10 - 0
packages/html/src/web_sys_bind/events.rs

@@ -4,6 +4,7 @@ use crate::events::{
 };
 };
 use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
 use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
 use crate::input_data::{decode_key_location, decode_mouse_button_set, MouseButton};
 use crate::input_data::{decode_key_location, decode_mouse_button_set, MouseButton};
+use crate::DragData;
 use keyboard_types::{Code, Key, Modifiers};
 use keyboard_types::{Code, Key, Modifiers};
 use std::convert::TryInto;
 use std::convert::TryInto;
 use std::str::FromStr;
 use std::str::FromStr;
@@ -40,6 +41,7 @@ uncheck_convert![
     CompositionEvent => CompositionData,
     CompositionEvent => CompositionData,
     KeyboardEvent    => KeyboardData,
     KeyboardEvent    => KeyboardData,
     MouseEvent       => MouseData,
     MouseEvent       => MouseData,
+    MouseEvent       => DragData,
     TouchEvent       => TouchData,
     TouchEvent       => TouchData,
     PointerEvent     => PointerData,
     PointerEvent     => PointerData,
     WheelEvent       => WheelData,
     WheelEvent       => WheelData,
@@ -117,6 +119,14 @@ impl From<&MouseEvent> for MouseData {
     }
     }
 }
 }
 
 
+impl From<&MouseEvent> for DragData {
+    fn from(value: &MouseEvent) -> Self {
+        Self {
+            mouse: MouseData::from(value),
+        }
+    }
+}
+
 impl From<&TouchEvent> for TouchData {
 impl From<&TouchEvent> for TouchData {
     fn from(e: &TouchEvent) -> Self {
     fn from(e: &TouchEvent) -> Self {
         Self {
         Self {

+ 2 - 2
packages/interpreter/README.md

@@ -20,7 +20,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-interpreter-js/latest/dioxus-interpreter-js) |
+[API Docs](https://docs.rs/dioxus-interpreter-js/latest/dioxus_interpreter_js) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -42,5 +42,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 1 - 1
packages/liveview/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react", "liveview"]
 description = "Build server-side apps with Dioxus"
 description = "Build server-side apps with Dioxus"
 license = "MIT/Apache-2.0"
 license = "MIT/Apache-2.0"
 
 

+ 5 - 5
packages/liveview/README.md

@@ -20,13 +20,13 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-liveview/latest/dioxus-liveview) |
+[API Docs](https://docs.rs/dioxus-liveview/latest/dioxus_liveview) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
 ## Overview
 ## Overview
 
 
-`dioxus-liveview` provides adapters for running the Dioxus VirtualDom over a websocket connection.
+`dioxus-liveview` provides adapters for running the Dioxus VirtualDom over a WebSocket connection.
 
 
 The current backend frameworks supported include:
 The current backend frameworks supported include:
 
 
@@ -34,9 +34,9 @@ The current backend frameworks supported include:
 - Warp
 - Warp
 - Salvo
 - Salvo
 
 
-Dioxus-LiveView exports a number of primitives to wire up an app into an existing backend framework.
+Dioxus-LiveView exports some primitives to wire up an app into an existing backend framework.
 
 
-- A threadpool for spawning the `!Send` VirtualDom and interacting with it from the websocket
+- A ThreadPool for spawning the `!Send` VirtualDom and interacting with it from WebSockets
 - An adapter for transforming various socket types into the `LiveViewSocket` type
 - An adapter for transforming various socket types into the `LiveViewSocket` type
 - The glue to load the interpreter into your app
 - The glue to load the interpreter into your app
 
 
@@ -51,5 +51,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 11 - 2
packages/liveview/src/main.js

@@ -12,7 +12,13 @@ class IPC {
 
 
     let ws = new WebSocket(WS_ADDR);
     let ws = new WebSocket(WS_ADDR);
 
 
+    function ping() {
+      ws.send("__ping__");
+    }
+
     ws.onopen = () => {
     ws.onopen = () => {
+      // we ping every 30 seconds to keep the websocket alive
+      setInterval(ping, 30000);
       ws.send(serializeIpcMessage("initialize"));
       ws.send(serializeIpcMessage("initialize"));
     };
     };
 
 
@@ -21,8 +27,11 @@ class IPC {
     };
     };
 
 
     ws.onmessage = (event) => {
     ws.onmessage = (event) => {
-      let edits = JSON.parse(event.data);
-      window.interpreter.handleEdits(edits);
+      // Ignore pongs
+      if (event.data != "__pong__") {
+        let edits = JSON.parse(event.data);
+        window.interpreter.handleEdits(edits);
+      }
     };
     };
 
 
     this.ws = ws;
     this.ws = ws;

+ 6 - 2
packages/liveview/src/pool.rs

@@ -141,9 +141,13 @@ where
             _ = vdom.wait_for_work() => {}
             _ = vdom.wait_for_work() => {}
 
 
             evt = ws.next() => {
             evt = ws.next() => {
-                match evt {
+                match evt.as_ref().map(|o| o.as_deref()) {
+                    // respond with a pong every ping to keep the websocket alive
+                    Some(Ok("__ping__")) => {
+                        ws.send("__pong__".to_string()).await?;
+                    }
                     Some(Ok(evt)) => {
                     Some(Ok(evt)) => {
-                        if let Ok(IpcMessage { params }) = serde_json::from_str::<IpcMessage>(&evt) {
+                        if let Ok(IpcMessage { params }) = serde_json::from_str::<IpcMessage>(evt) {
                             vdom.handle_event(&params.name, params.data.into_any(), params.element, params.bubbles);
                             vdom.handle_event(&params.name, params.data.into_any(), params.element, params.bubbles);
                         }
                         }
                     }
                     }

+ 1 - 1
packages/mobile/Cargo.toml

@@ -7,7 +7,7 @@ description = "Mobile-compatible renderer for Dioxus"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 license = "MIT/Apache-2.0"
 license = "MIT/Apache-2.0"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 

+ 3 - 3
packages/mobile/README.md

@@ -19,7 +19,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-mobile/latest/dioxus-mobile) |
+[API Docs](https://docs.rs/dioxus-mobile/latest/dioxus_mobile) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -94,7 +94,7 @@ fn app(cx: Scope) -> Element {
 }
 }
 ```
 ```
 
 
-To configure the webview, menubar, and other important desktop-specific features, checkout out some of the launch configuration in the [API reference](https://docs.rs/dioxus-mobile/).
+To configure the web view, menubar, and other important desktop-specific features, checkout out some of the launch configurations in the [API reference](https://docs.rs/dioxus-mobile/).
 
 
 ## Future Steps
 ## Future Steps
 
 
@@ -113,5 +113,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 1 - 1
packages/native-core-macro/Cargo.toml

@@ -7,7 +7,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 
 
 
 
 [lib]
 [lib]

+ 3 - 3
packages/native-core-macro/README.md

@@ -19,13 +19,13 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-native-core-macro/latest/dioxus-native-core-macro) |
+[API Docs](https://docs.rs/dioxus-native-core-macro/latest/dioxus_native_core_macro) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
 ## Overview
 ## Overview
 
 
-`dioxus-native-core-macro` provides a handful of macros used by native-core for native renderers like TUI, Blitz, and Freya to derive their own state.
+`dioxus-native-core-macro` provides a handful of macros used by native-core for native renderers like TUI, Blitz, and Freya to derive their state.
 
 
 
 
 ## Contributing
 ## Contributing
@@ -39,5 +39,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 3 - 1
packages/native-core/Cargo.toml

@@ -7,7 +7,7 @@ repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 description = "Build natively rendered apps with Dioxus"
 description = "Build natively rendered apps with Dioxus"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react"]
 
 
 
 
 [dependencies]
 [dependencies]
@@ -30,3 +30,5 @@ lightningcss = "1.0.0-alpha.39"
 [dev-dependencies]
 [dev-dependencies]
 rand = "0.8.5"
 rand = "0.8.5"
 dioxus = { path = "../dioxus", version = "^0.3.0" }
 dioxus = { path = "../dioxus", version = "^0.3.0" }
+dioxus-native-core-macro = { path = "../native-core-macro" }
+tokio = { version = "*", features = ["full"] }

+ 4 - 4
packages/native-core/README.md

@@ -19,15 +19,15 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-native-core/latest/dioxus-native-core) |
+[API Docs](https://docs.rs/dioxus-native-core/latest/dioxus_native_core) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
 ## Overview
 ## Overview
 
 
-`dioxus-native-core` provides a number of helpful utilities for lazily resolving computed values of the Dioxus VirtualDom to be used in conjunction with a native rendering engine.
+`dioxus-native-core` provides several helpful utilities for lazily resolving computed values of the Dioxus VirtualDom to be used in conjunction with a native rendering engine.
 
 
-The main "value-add" of this crate over implementing your own native tree is that this tree is incrementally recomputed using the Dioxus VirtualDom's edit stream. Only parts of the tree that rely on each other will be redrawn - all else will be ignored.
+The main "value-add" of this crate over implementing your native tree is that this tree is incrementally recomputed using the Dioxus VirtualDom's edit stream. Only parts of the tree that rely on each other will be redrawn - all else will be ignored.
 
 
 
 
 ## Contributing
 ## Contributing
@@ -41,5 +41,5 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.

+ 109 - 148
packages/native-core/src/passes.rs

@@ -1,112 +1,100 @@
 use crate::tree::{NodeId, TreeView};
 use crate::tree::{NodeId, TreeView};
-use crate::{FxDashMap, FxDashSet, SendAnyMap};
+use crate::{FxDashSet, SendAnyMap};
 use rustc_hash::{FxHashMap, FxHashSet};
 use rustc_hash::{FxHashMap, FxHashSet};
 use std::collections::BTreeMap;
 use std::collections::BTreeMap;
 use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
 use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
-use std::sync::atomic::{AtomicU64, Ordering};
 use std::sync::Arc;
 use std::sync::Arc;
 
 
-#[derive(Debug, Clone, PartialEq, Eq, Default)]
-pub struct DirtyNodes {
-    map: BTreeMap<u16, FxHashSet<NodeId>>,
+#[derive(Default)]
+struct DirtyNodes {
+    passes_dirty: Vec<u64>,
 }
 }
 
 
 impl DirtyNodes {
 impl DirtyNodes {
-    pub fn insert(&mut self, depth: u16, node_id: NodeId) {
-        self.map
-            .entry(depth)
-            .or_insert_with(FxHashSet::default)
-            .insert(node_id);
-    }
-
-    fn pop_front(&mut self) -> Option<NodeId> {
-        let (&depth, values) = self.map.iter_mut().next()?;
-        let key = *values.iter().next()?;
-        let node_id = values.take(&key)?;
-        if values.is_empty() {
-            self.map.remove(&depth);
+    fn add_node(&mut self, node_id: NodeId) {
+        let node_id = node_id.0;
+        let index = node_id / 64;
+        let bit = node_id % 64;
+        let encoded = 1 << bit;
+        if let Some(passes) = self.passes_dirty.get_mut(index) {
+            *passes |= encoded;
+        } else {
+            self.passes_dirty.resize(index + 1, 0);
+            self.passes_dirty[index] |= encoded;
         }
         }
-        Some(node_id)
     }
     }
 
 
-    fn pop_back(&mut self) -> Option<NodeId> {
-        let (&depth, values) = self.map.iter_mut().rev().next()?;
-        let key = *values.iter().next()?;
-        let node_id = values.take(&key)?;
-        if values.is_empty() {
-            self.map.remove(&depth);
-        }
-        Some(node_id)
+    fn is_empty(&self) -> bool {
+        self.passes_dirty.iter().all(|dirty| *dirty == 0)
     }
     }
-}
 
 
-#[test]
-fn dirty_nodes() {
-    let mut dirty_nodes = DirtyNodes::default();
-
-    dirty_nodes.insert(1, NodeId(1));
-    dirty_nodes.insert(0, NodeId(0));
-    dirty_nodes.insert(2, NodeId(3));
-    dirty_nodes.insert(1, NodeId(2));
-
-    assert_eq!(dirty_nodes.pop_front(), Some(NodeId(0)));
-    assert!(matches!(dirty_nodes.pop_front(), Some(NodeId(1 | 2))));
-    assert!(matches!(dirty_nodes.pop_front(), Some(NodeId(1 | 2))));
-    assert_eq!(dirty_nodes.pop_front(), Some(NodeId(3)));
+    fn pop(&mut self) -> Option<NodeId> {
+        let index = self.passes_dirty.iter().position(|dirty| *dirty != 0)?;
+        let passes = self.passes_dirty[index];
+        let node_id = passes.trailing_zeros();
+        let encoded = 1 << node_id;
+        self.passes_dirty[index] &= !encoded;
+        Some(NodeId((index * 64) + node_id as usize))
+    }
 }
 }
 
 
 #[derive(Default)]
 #[derive(Default)]
 pub struct DirtyNodeStates {
 pub struct DirtyNodeStates {
-    dirty: FxDashMap<NodeId, Vec<AtomicU64>>,
+    dirty: BTreeMap<u16, FxHashMap<PassId, DirtyNodes>>,
 }
 }
 
 
 impl DirtyNodeStates {
 impl DirtyNodeStates {
-    pub fn new(starting_nodes: FxHashMap<NodeId, FxHashSet<PassId>>) -> Self {
-        let this = Self::default();
-        for (node, nodes) in starting_nodes {
-            for pass_id in nodes {
-                this.insert(pass_id, node);
+    pub fn insert(&mut self, pass_id: PassId, node_id: NodeId, height: u16) {
+        if let Some(dirty) = self.dirty.get_mut(&height) {
+            if let Some(entry) = dirty.get_mut(&pass_id) {
+                entry.add_node(node_id);
+            } else {
+                let mut entry = DirtyNodes::default();
+                entry.add_node(node_id);
+                dirty.insert(pass_id, entry);
             }
             }
+        } else {
+            let mut entry = DirtyNodes::default();
+            entry.add_node(node_id);
+            let mut hm = FxHashMap::default();
+            hm.insert(pass_id, entry);
+            self.dirty.insert(height, hm);
         }
         }
-        this
     }
     }
 
 
-    pub fn insert(&self, pass_id: PassId, node_id: NodeId) {
-        let pass_id = pass_id.0;
-        let index = pass_id / 64;
-        let bit = pass_id % 64;
-        let encoded = 1 << bit;
-        if let Some(dirty) = self.dirty.get(&node_id) {
-            if let Some(atomic) = dirty.get(index as usize) {
-                atomic.fetch_or(encoded, Ordering::Relaxed);
-            } else {
-                drop(dirty);
-                let mut write = self.dirty.get_mut(&node_id).unwrap();
-                write.resize_with(index as usize + 1, || AtomicU64::new(0));
-                write[index as usize].fetch_or(encoded, Ordering::Relaxed);
-            }
-        } else {
-            let mut v = Vec::with_capacity(index as usize + 1);
-            v.resize_with(index as usize + 1, || AtomicU64::new(0));
-            v[index as usize].fetch_or(encoded, Ordering::Relaxed);
-            self.dirty.insert(node_id, v);
+    fn pop_front(&mut self, pass_id: PassId) -> Option<(u16, NodeId)> {
+        let (&height, values) = self
+            .dirty
+            .iter_mut()
+            .find(|(_, values)| values.contains_key(&pass_id))?;
+        let dirty = values.get_mut(&pass_id)?;
+        let node_id = dirty.pop()?;
+        if dirty.is_empty() {
+            values.remove(&pass_id);
         }
         }
+        if values.is_empty() {
+            self.dirty.remove(&height);
+        }
+
+        Some((height, node_id))
     }
     }
 
 
-    fn all_dirty<T>(&self, pass_id: PassId, dirty_nodes: &mut DirtyNodes, tree: &impl TreeView<T>) {
-        let pass_id = pass_id.0;
-        let index = pass_id / 64;
-        let bit = pass_id % 64;
-        let encoded = 1 << bit;
-        for entry in self.dirty.iter() {
-            let node_id = entry.key();
-            let dirty = entry.value();
-            if let Some(atomic) = dirty.get(index as usize) {
-                if atomic.load(Ordering::Relaxed) & encoded != 0 {
-                    dirty_nodes.insert(tree.height(*node_id).unwrap(), *node_id);
-                }
-            }
+    fn pop_back(&mut self, pass_id: PassId) -> Option<(u16, NodeId)> {
+        let (&height, values) = self
+            .dirty
+            .iter_mut()
+            .rev()
+            .find(|(_, values)| values.contains_key(&pass_id))?;
+        let dirty = values.get_mut(&pass_id)?;
+        let node_id = dirty.pop()?;
+        if dirty.is_empty() {
+            values.remove(&pass_id);
+        }
+        if values.is_empty() {
+            self.dirty.remove(&height);
         }
         }
+
+        Some((height, node_id))
     }
     }
 }
 }
 
 
@@ -174,12 +162,12 @@ pub trait UpwardPass<T>: Pass {
 fn resolve_upward_pass<T, P: UpwardPass<T> + ?Sized>(
 fn resolve_upward_pass<T, P: UpwardPass<T> + ?Sized>(
     tree: &mut impl TreeView<T>,
     tree: &mut impl TreeView<T>,
     pass: &P,
     pass: &P,
-    mut dirty: DirtyNodes,
-    dirty_states: &DirtyNodeStates,
+    dirty_states: &mut DirtyNodeStates,
     nodes_updated: &FxDashSet<NodeId>,
     nodes_updated: &FxDashSet<NodeId>,
     ctx: &SendAnyMap,
     ctx: &SendAnyMap,
 ) {
 ) {
-    while let Some(id) = dirty.pop_back() {
+    let pass_id = pass.pass_id();
+    while let Some((height, id)) = dirty_states.pop_back(pass_id) {
         let (node, mut children) = tree.parent_child_mut(id).unwrap();
         let (node, mut children) = tree.parent_child_mut(id).unwrap();
         let result = pass.pass(node, &mut children, ctx);
         let result = pass.pass(node, &mut children, ctx);
         drop(children);
         drop(children);
@@ -188,12 +176,11 @@ fn resolve_upward_pass<T, P: UpwardPass<T> + ?Sized>(
             if let Some(id) = tree.parent_id(id) {
             if let Some(id) = tree.parent_id(id) {
                 if result.mark_dirty {
                 if result.mark_dirty {
                     for dependant in pass.dependants() {
                     for dependant in pass.dependants() {
-                        dirty_states.insert(*dependant, id);
+                        dirty_states.insert(*dependant, id, height - 1);
                     }
                     }
                 }
                 }
-                if result.progress {
-                    let height = tree.height(id).unwrap();
-                    dirty.insert(height, id);
+                if result.progress && height > 0 {
+                    dirty_states.insert(pass_id, id, height - 1);
                 }
                 }
             }
             }
         }
         }
@@ -207,12 +194,12 @@ pub trait DownwardPass<T>: Pass {
 fn resolve_downward_pass<T, P: DownwardPass<T> + ?Sized>(
 fn resolve_downward_pass<T, P: DownwardPass<T> + ?Sized>(
     tree: &mut impl TreeView<T>,
     tree: &mut impl TreeView<T>,
     pass: &P,
     pass: &P,
-    mut dirty: DirtyNodes,
-    dirty_states: &DirtyNodeStates,
+    dirty_states: &mut DirtyNodeStates,
     nodes_updated: &FxDashSet<NodeId>,
     nodes_updated: &FxDashSet<NodeId>,
     ctx: &SendAnyMap,
     ctx: &SendAnyMap,
 ) {
 ) {
-    while let Some(id) = dirty.pop_front() {
+    let pass_id = pass.pass_id();
+    while let Some((height, id)) = dirty_states.pop_front(pass_id) {
         let (node, parent) = tree.node_parent_mut(id).unwrap();
         let (node, parent) = tree.node_parent_mut(id).unwrap();
         let result = pass.pass(node, parent, ctx);
         let result = pass.pass(node, parent, ctx);
         if result.mark_dirty {
         if result.mark_dirty {
@@ -222,12 +209,11 @@ fn resolve_downward_pass<T, P: DownwardPass<T> + ?Sized>(
             for id in tree.children_ids(id).unwrap() {
             for id in tree.children_ids(id).unwrap() {
                 if result.mark_dirty {
                 if result.mark_dirty {
                     for dependant in pass.dependants() {
                     for dependant in pass.dependants() {
-                        dirty_states.insert(*dependant, *id);
+                        dirty_states.insert(*dependant, *id, height + 1);
                     }
                     }
                 }
                 }
                 if result.progress {
                 if result.progress {
-                    let height = tree.height(*id).unwrap();
-                    dirty.insert(height, *id);
+                    dirty_states.insert(pass_id, *id, height + 1);
                 }
                 }
             }
             }
         }
         }
@@ -241,17 +227,17 @@ pub trait NodePass<T>: Pass {
 fn resolve_node_pass<T, P: NodePass<T> + ?Sized>(
 fn resolve_node_pass<T, P: NodePass<T> + ?Sized>(
     tree: &mut impl TreeView<T>,
     tree: &mut impl TreeView<T>,
     pass: &P,
     pass: &P,
-    mut dirty: DirtyNodes,
-    dirty_states: &DirtyNodeStates,
+    dirty_states: &mut DirtyNodeStates,
     nodes_updated: &FxDashSet<NodeId>,
     nodes_updated: &FxDashSet<NodeId>,
     ctx: &SendAnyMap,
     ctx: &SendAnyMap,
 ) {
 ) {
-    while let Some(id) = dirty.pop_back() {
+    let pass_id = pass.pass_id();
+    while let Some((height, id)) = dirty_states.pop_back(pass_id) {
         let node = tree.get_mut(id).unwrap();
         let node = tree.get_mut(id).unwrap();
         if pass.pass(node, ctx) {
         if pass.pass(node, ctx) {
             nodes_updated.insert(id);
             nodes_updated.insert(id);
             for dependant in pass.dependants() {
             for dependant in pass.dependants() {
-                dirty_states.insert(*dependant, id);
+                dirty_states.insert(*dependant, id, height);
             }
             }
         }
         }
     }
     }
@@ -280,32 +266,21 @@ impl<T> AnyPass<T> {
         }
         }
     }
     }
 
 
-    fn mask(&self) -> MemberMask {
-        match self {
-            Self::Upward(pass) => pass.mask(),
-            Self::Downward(pass) => pass.mask(),
-            Self::Node(pass) => pass.mask(),
-        }
-    }
-
     fn resolve(
     fn resolve(
         &self,
         &self,
         tree: &mut impl TreeView<T>,
         tree: &mut impl TreeView<T>,
-        dirty: DirtyNodes,
-        dirty_states: &DirtyNodeStates,
+        dirty_states: &mut DirtyNodeStates,
         nodes_updated: &FxDashSet<NodeId>,
         nodes_updated: &FxDashSet<NodeId>,
         ctx: &SendAnyMap,
         ctx: &SendAnyMap,
     ) {
     ) {
         match self {
         match self {
             Self::Downward(pass) => {
             Self::Downward(pass) => {
-                resolve_downward_pass(tree, *pass, dirty, dirty_states, nodes_updated, ctx)
+                resolve_downward_pass(tree, *pass, dirty_states, nodes_updated, ctx)
             }
             }
             Self::Upward(pass) => {
             Self::Upward(pass) => {
-                resolve_upward_pass(tree, *pass, dirty, dirty_states, nodes_updated, ctx)
-            }
-            Self::Node(pass) => {
-                resolve_node_pass(tree, *pass, dirty, dirty_states, nodes_updated, ctx)
+                resolve_upward_pass(tree, *pass, dirty_states, nodes_updated, ctx)
             }
             }
+            Self::Node(pass) => resolve_node_pass(tree, *pass, dirty_states, nodes_updated, ctx),
         }
         }
     }
     }
 }
 }
@@ -374,40 +349,26 @@ pub fn resolve_passes_single_threaded<T, Tr: TreeView<T>>(
     mut passes: Vec<&AnyPass<T>>,
     mut passes: Vec<&AnyPass<T>>,
     ctx: SendAnyMap,
     ctx: SendAnyMap,
 ) -> FxDashSet<NodeId> {
 ) -> FxDashSet<NodeId> {
-    let dirty_states = Arc::new(dirty_nodes);
+    let mut dirty_states = dirty_nodes;
     let mut resolved_passes: FxHashSet<PassId> = FxHashSet::default();
     let mut resolved_passes: FxHashSet<PassId> = FxHashSet::default();
-    let mut resolving = Vec::new();
     let nodes_updated = Arc::new(FxDashSet::default());
     let nodes_updated = Arc::new(FxDashSet::default());
     let ctx = Arc::new(ctx);
     let ctx = Arc::new(ctx);
     while !passes.is_empty() {
     while !passes.is_empty() {
-        let mut currently_borrowed = MemberMask::default();
-        let mut i = 0;
-        while i < passes.len() {
-            let pass = &passes[i];
+        for (i, pass) in passes.iter().enumerate() {
             let pass_id = pass.pass_id();
             let pass_id = pass.pass_id();
-            let pass_mask = pass.mask();
             if pass
             if pass
                 .dependancies()
                 .dependancies()
                 .iter()
                 .iter()
                 .all(|d| resolved_passes.contains(d) || *d == pass_id)
                 .all(|d| resolved_passes.contains(d) || *d == pass_id)
-                && !pass_mask.overlaps(currently_borrowed)
             {
             {
                 let pass = passes.remove(i);
                 let pass = passes.remove(i);
-                resolving.push(pass_id);
-                currently_borrowed |= pass_mask;
-                let dirty_states = dirty_states.clone();
                 let nodes_updated = nodes_updated.clone();
                 let nodes_updated = nodes_updated.clone();
                 let ctx = ctx.clone();
                 let ctx = ctx.clone();
-                // this is safe because the member_mask acts as a per-member mutex and we have verified that the pass does not overlap with any other pass
-                let mut dirty = DirtyNodes::default();
-                dirty_states.all_dirty(pass_id, &mut dirty, tree);
-                pass.resolve(tree, dirty, &dirty_states, &nodes_updated, &ctx);
-            } else {
-                i += 1;
+                pass.resolve(tree, &mut dirty_states, &nodes_updated, &ctx);
+                resolved_passes.insert(pass_id);
+                break;
             }
             }
         }
         }
-        resolved_passes.extend(resolving.iter().copied());
-        resolving.clear()
     }
     }
     std::sync::Arc::try_unwrap(nodes_updated).unwrap()
     std::sync::Arc::try_unwrap(nodes_updated).unwrap()
 }
 }
@@ -445,8 +406,8 @@ fn node_pass() {
 
 
     let add_pass = AnyPass::Node(&AddPass);
     let add_pass = AnyPass::Node(&AddPass);
     let passes = vec![&add_pass];
     let passes = vec![&add_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(0), tree.root());
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(0), tree.root(), 0);
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     assert_eq!(tree.get(tree.root()).unwrap(), &1);
     assert_eq!(tree.get(tree.root()).unwrap(), &1);
@@ -512,8 +473,8 @@ fn dependant_node_pass() {
     let add_pass = AnyPass::Node(&AddPass);
     let add_pass = AnyPass::Node(&AddPass);
     let subtract_pass = AnyPass::Node(&SubtractPass);
     let subtract_pass = AnyPass::Node(&SubtractPass);
     let passes = vec![&add_pass, &subtract_pass];
     let passes = vec![&add_pass, &subtract_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(1), tree.root());
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(1), tree.root(), 0);
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     assert_eq!(*tree.get(tree.root()).unwrap(), 0);
     assert_eq!(*tree.get(tree.root()).unwrap(), 0);
@@ -579,9 +540,9 @@ fn independant_node_pass() {
     let add_pass1 = AnyPass::Node(&AddPass1);
     let add_pass1 = AnyPass::Node(&AddPass1);
     let add_pass2 = AnyPass::Node(&AddPass2);
     let add_pass2 = AnyPass::Node(&AddPass2);
     let passes = vec![&add_pass1, &add_pass2];
     let passes = vec![&add_pass1, &add_pass2];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(0), tree.root());
-    dirty_nodes.insert(PassId(1), tree.root());
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(0), tree.root(), 0);
+    dirty_nodes.insert(PassId(1), tree.root(), 0);
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     assert_eq!(tree.get(tree.root()).unwrap(), &(1, 1));
     assert_eq!(tree.get(tree.root()).unwrap(), &(1, 1));
@@ -634,8 +595,8 @@ fn down_pass() {
 
 
     let add_pass = AnyPass::Downward(&AddPass);
     let add_pass = AnyPass::Downward(&AddPass);
     let passes = vec![&add_pass];
     let passes = vec![&add_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(0), tree.root());
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(0), tree.root(), 0);
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     assert_eq!(tree.get(tree.root()).unwrap(), &1);
     assert_eq!(tree.get(tree.root()).unwrap(), &1);
@@ -729,8 +690,8 @@ fn dependant_down_pass() {
     let add_pass = AnyPass::Downward(&AddPass);
     let add_pass = AnyPass::Downward(&AddPass);
     let subtract_pass = AnyPass::Downward(&SubtractPass);
     let subtract_pass = AnyPass::Downward(&SubtractPass);
     let passes = vec![&add_pass, &subtract_pass];
     let passes = vec![&add_pass, &subtract_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(1), tree.root());
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(1), tree.root(), 0);
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     // Tree before:
     // Tree before:
@@ -819,9 +780,9 @@ fn up_pass() {
 
 
     let add_pass = AnyPass::Upward(&AddPass);
     let add_pass = AnyPass::Upward(&AddPass);
     let passes = vec![&add_pass];
     let passes = vec![&add_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(0), grandchild1);
-    dirty_nodes.insert(PassId(0), grandchild2);
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(0), grandchild1, tree.height(grandchild1).unwrap());
+    dirty_nodes.insert(PassId(0), grandchild2, tree.height(grandchild2).unwrap());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     assert_eq!(tree.get(tree.root()).unwrap(), &2);
     assert_eq!(tree.get(tree.root()).unwrap(), &2);
@@ -919,9 +880,9 @@ fn dependant_up_pass() {
     let add_pass = AnyPass::Upward(&AddPass);
     let add_pass = AnyPass::Upward(&AddPass);
     let subtract_pass = AnyPass::Upward(&SubtractPass);
     let subtract_pass = AnyPass::Upward(&SubtractPass);
     let passes = vec![&add_pass, &subtract_pass];
     let passes = vec![&add_pass, &subtract_pass];
-    let dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
-    dirty_nodes.insert(PassId(1), grandchild1);
-    dirty_nodes.insert(PassId(1), grandchild2);
+    let mut dirty_nodes: DirtyNodeStates = DirtyNodeStates::default();
+    dirty_nodes.insert(PassId(1), grandchild1, tree.height(grandchild1).unwrap());
+    dirty_nodes.insert(PassId(1), grandchild2, tree.height(grandchild2).unwrap());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
     resolve_passes(&mut tree, dirty_nodes, passes, SendAnyMap::new());
 
 
     // Tree before:
     // Tree before:

+ 3 - 3
packages/native-core/src/real_dom.rs

@@ -335,13 +335,13 @@ impl<S: State<V>, V: FromAnyValue> RealDom<S, V> {
             }
             }
         }
         }
 
 
-        let dirty_nodes = DirtyNodeStates::default();
+        let mut dirty_nodes = DirtyNodeStates::default();
         for (&n, mask) in &nodes_updated {
         for (&n, mask) in &nodes_updated {
             // remove any nodes that were created and then removed in the same mutations from the dirty nodes list
             // remove any nodes that were created and then removed in the same mutations from the dirty nodes list
-            if self.tree.contains(n) {
+            if let Some(height) = self.tree.height(n) {
                 for (m, p) in S::MASKS.iter().zip(S::PASSES.iter()) {
                 for (m, p) in S::MASKS.iter().zip(S::PASSES.iter()) {
                     if mask.overlaps(m) {
                     if mask.overlaps(m) {
-                        dirty_nodes.insert(p.pass_id(), n);
+                        dirty_nodes.insert(p.pass_id(), n, height);
                     }
                     }
                 }
                 }
             }
             }

+ 146 - 0
packages/native-core/tests/miri_native.rs

@@ -0,0 +1,146 @@
+use dioxus::prelude::*;
+use dioxus_native_core::*;
+use dioxus_native_core::{
+    node_ref::{AttributeMask, NodeView},
+    real_dom::RealDom,
+    state::{ParentDepState, State},
+    NodeMask, SendAnyMap,
+};
+use dioxus_native_core_macro::{sorted_str_slice, State};
+use std::{
+    sync::{Arc, Mutex},
+    time::Duration,
+};
+use tokio::time::sleep;
+
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct BlablaState {}
+
+/// Font style are inherited by default if not specified otherwise by some of the supported attributes.
+impl ParentDepState for BlablaState {
+    type Ctx = ();
+    type DepState = (Self,);
+
+    const NODE_MASK: NodeMask =
+        NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
+
+    fn reduce<'a>(
+        &mut self,
+        _node: NodeView,
+        _parent: Option<(&'a Self,)>,
+        _ctx: &Self::Ctx,
+    ) -> bool {
+        false
+    }
+}
+
+#[derive(Clone, State, Default, Debug)]
+pub struct NodeState {
+    #[parent_dep_state(blabla)]
+    blabla: BlablaState,
+}
+
+mod dioxus_elements {
+    macro_rules! builder_constructors {
+        (
+            $(
+                $(#[$attr:meta])*
+                $name:ident {
+                    $(
+                        $(#[$attr_method:meta])*
+                        $fil:ident: $vil:ident,
+                    )*
+                };
+            )*
+        ) => {
+            $(
+                #[allow(non_camel_case_types)]
+                $(#[$attr])*
+                pub struct $name;
+
+                impl $name {
+                    pub const TAG_NAME: &'static str = stringify!($name);
+                    pub const NAME_SPACE: Option<&'static str> = None;
+
+                    $(
+                        pub const $fil: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false);
+                    )*
+                }
+
+                impl GlobalAttributes for $name {}
+            )*
+        }
+    }
+
+    pub trait GlobalAttributes {}
+
+    pub trait SvgAttributes {}
+
+    builder_constructors! {
+        blabla {
+
+        };
+    }
+}
+
+#[test]
+fn native_core_is_okay() {
+    use std::time::Duration;
+
+    fn app(cx: Scope) -> Element {
+        let colors = use_state(&cx, || vec!["green", "blue", "red"]);
+        let padding = use_state(&cx, || 10);
+
+        use_effect(&cx, colors, |colors| async move {
+            sleep(Duration::from_millis(1000)).await;
+            colors.with_mut(|colors| colors.reverse());
+        });
+
+        use_effect(&cx, padding, |padding| async move {
+            sleep(Duration::from_millis(10)).await;
+            padding.with_mut(|padding| {
+                if *padding < 65 {
+                    *padding += 1;
+                } else {
+                    *padding = 5;
+                }
+            });
+        });
+
+        let big = colors[0];
+        let mid = colors[1];
+        let small = colors[2];
+
+        cx.render(rsx! {
+            blabla {}
+        })
+    }
+
+    let rt = tokio::runtime::Builder::new_current_thread()
+        .enable_time()
+        .build()
+        .unwrap();
+
+    rt.block_on(async {
+        let rdom = Arc::new(Mutex::new(RealDom::<NodeState>::new()));
+        let mut dom = VirtualDom::new(app);
+
+        let muts = dom.rebuild();
+        let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(muts);
+
+        let ctx = SendAnyMap::new();
+        let ctx = SendAnyMap::new();
+        rdom.lock().unwrap().update_state(to_update, ctx);
+
+        for x in 0..10 {
+            dom.wait_for_work().await;
+
+            let mutations = dom.render_immediate();
+            let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(mutations);
+
+            let ctx = SendAnyMap::new();
+            let ctx = SendAnyMap::new();
+            rdom.lock().unwrap().update_state(to_update, ctx);
+        }
+    });
+}

+ 3 - 3
packages/router/README.md

@@ -19,13 +19,13 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-router/latest/dioxus-router) |
+[API Docs](https://docs.rs/dioxus-router/latest/dioxus_router) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
 ## Overview
 ## Overview
 
 
-Dioxus Router is a first-party Router for all your Dioxus Apps. It provides a React-Router style interface using somewhat loose typing rules.
+Dioxus Router is a first-party Router for all your Dioxus Apps. It provides a React-Router-style interface using somewhat loose typing rules.
 
 
 ```rust, ignore
 ```rust, ignore
 fn app() {
 fn app() {
@@ -52,6 +52,6 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.
 
 

+ 2 - 0
packages/rsx-rosetta/src/lib.rs

@@ -73,6 +73,7 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
                 attributes,
                 attributes,
                 _is_static: false,
                 _is_static: false,
                 key: None,
                 key: None,
+                brace: Default::default(),
             }))
             }))
         }
         }
 
 
@@ -107,6 +108,7 @@ pub fn collect_svgs(children: &mut [BodyNode], out: &mut Vec<BodyNode>) {
                     fields: vec![],
                     fields: vec![],
                     children: vec![],
                     children: vec![],
                     manual_props: None,
                     manual_props: None,
+                    brace: Default::default(),
                 });
                 });
 
 
                 std::mem::swap(child, &mut new_comp);
                 std::mem::swap(child, &mut new_comp);

+ 2 - 2
packages/rsx/Cargo.toml

@@ -6,8 +6,8 @@ license = "MIT/Apache-2.0"
 description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"
 description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
-documentation = "https://docs.rs/dioxus-rsx"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+documentation = "https://dioxuslabs.com"
+keywords = ["dom", "ui", "gui", "react"]
 
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 

+ 2 - 2
packages/rsx/README.md

@@ -19,7 +19,7 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/dioxus-rsx/latest/dioxus-rsx) |
+[API Docs](https://docs.rs/dioxus-rsx/latest/dioxus_rsx) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 
 
@@ -38,6 +38,6 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT, without any additional
 terms or conditions.
 terms or conditions.
 
 

+ 7 - 10
packages/rsx/src/component.rs

@@ -19,8 +19,7 @@ use syn::{
     ext::IdentExt,
     ext::IdentExt,
     parse::{Parse, ParseBuffer, ParseStream},
     parse::{Parse, ParseBuffer, ParseStream},
     spanned::Spanned,
     spanned::Spanned,
-    token, AngleBracketedGenericArguments, Error, Expr, Ident, LitStr, PathArguments, Result,
-    Token,
+    AngleBracketedGenericArguments, Error, Expr, Ident, LitStr, PathArguments, Result, Token,
 };
 };
 
 
 #[derive(PartialEq, Eq, Clone, Debug, Hash)]
 #[derive(PartialEq, Eq, Clone, Debug, Hash)]
@@ -30,6 +29,7 @@ pub struct Component {
     pub fields: Vec<ComponentField>,
     pub fields: Vec<ComponentField>,
     pub children: Vec<BodyNode>,
     pub children: Vec<BodyNode>,
     pub manual_props: Option<Expr>,
     pub manual_props: Option<Expr>,
+    pub brace: syn::token::Brace,
 }
 }
 
 
 impl Component {
 impl Component {
@@ -88,13 +88,9 @@ impl Parse for Component {
 
 
         // if we see a `{` then we have a block
         // if we see a `{` then we have a block
         // else parse as a function-like call
         // else parse as a function-like call
-        if stream.peek(token::Brace) {
-            syn::braced!(content in stream);
-        } else {
-            syn::parenthesized!(content in stream);
-        }
+        let brace = syn::braced!(content in stream);
 
 
-        let mut body = Vec::new();
+        let mut fields = Vec::new();
         let mut children = Vec::new();
         let mut children = Vec::new();
         let mut manual_props = None;
         let mut manual_props = None;
 
 
@@ -104,7 +100,7 @@ impl Parse for Component {
                 content.parse::<Token![..]>()?;
                 content.parse::<Token![..]>()?;
                 manual_props = Some(content.parse::<Expr>()?);
                 manual_props = Some(content.parse::<Expr>()?);
             } else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
             } else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
-                body.push(content.parse::<ComponentField>()?);
+                fields.push(content.parse::<ComponentField>()?);
             } else {
             } else {
                 children.push(content.parse::<BodyNode>()?);
                 children.push(content.parse::<BodyNode>()?);
             }
             }
@@ -117,9 +113,10 @@ impl Parse for Component {
         Ok(Self {
         Ok(Self {
             name,
             name,
             prop_gen_args,
             prop_gen_args,
-            fields: body,
+            fields,
             children,
             children,
             manual_props,
             manual_props,
+            brace,
         })
         })
     }
     }
 }
 }

+ 3 - 1
packages/rsx/src/element.rs

@@ -17,6 +17,7 @@ pub struct Element {
     pub attributes: Vec<ElementAttrNamed>,
     pub attributes: Vec<ElementAttrNamed>,
     pub children: Vec<BodyNode>,
     pub children: Vec<BodyNode>,
     pub _is_static: bool,
     pub _is_static: bool,
+    pub brace: syn::token::Brace,
 }
 }
 
 
 impl Parse for Element {
 impl Parse for Element {
@@ -25,7 +26,7 @@ impl Parse for Element {
 
 
         // parse the guts
         // parse the guts
         let content: ParseBuffer;
         let content: ParseBuffer;
-        syn::braced!(content in stream);
+        let brace = syn::braced!(content in stream);
 
 
         let mut attributes: Vec<ElementAttrNamed> = vec![];
         let mut attributes: Vec<ElementAttrNamed> = vec![];
         let mut children: Vec<BodyNode> = vec![];
         let mut children: Vec<BodyNode> = vec![];
@@ -152,6 +153,7 @@ impl Parse for Element {
             name: el_name,
             name: el_name,
             attributes,
             attributes,
             children,
             children,
+            brace,
             _is_static: false,
             _is_static: false,
         })
         })
     }
     }

+ 1 - 1
packages/ssr/Cargo.toml

@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
 repository = "https://github.com/DioxusLabs/dioxus/"
 repository = "https://github.com/DioxusLabs/dioxus/"
 homepage = "https://dioxuslabs.com"
 homepage = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
 documentation = "https://dioxuslabs.com"
-keywords = ["dom", "ui", "gui", "react", "wasm"]
+keywords = ["dom", "ui", "gui", "react", "ssr"]
 
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 

+ 23 - 18
packages/ssr/README.md

@@ -15,7 +15,7 @@ This crate is a part of the broader Dioxus ecosystem. For more resources about D
 
 
 ## Overview
 ## Overview
 
 
-Dioxus SSR provides utilities to render Dioxus components to valid HTML. Once rendered, the HTML can be rehydrated client side or served from your web-server of choice.
+Dioxus SSR provides utilities to render Dioxus components to valid HTML. Once rendered, the HTML can be rehydrated client-side or served from your web server of choice.
 
 
 ```rust, ignore
 ```rust, ignore
 let app: Component = |cx| cx.render(rsx!(div {"hello world!"}));
 let app: Component = |cx| cx.render(rsx!(div {"hello world!"}));
@@ -23,17 +23,17 @@ let app: Component = |cx| cx.render(rsx!(div {"hello world!"}));
 let mut vdom = VirtualDom::new(app);
 let mut vdom = VirtualDom::new(app);
 let _ = vdom.rebuild();
 let _ = vdom.rebuild();
 
 
-let text = dioxus_ssr::render_vdom(&vdom);
+let text = dioxus_ssr::render(&vdom);
 assert_eq!(text, "<div>hello world!</div>")
 assert_eq!(text, "<div>hello world!</div>")
 ```
 ```
 
 
 
 
 ## Basic Usage
 ## Basic Usage
 
 
-The simplest example is to simply render some `rsx!` nodes to html. This can be done with the [`render_lazy`] api.
+The simplest example is to simply render some `rsx!` nodes to HTML. This can be done with the [`render_lazy`] API.
 
 
 ```rust, ignore
 ```rust, ignore
-let content = dioxus_ssr::render(rsx!{
+let content = dioxus_ssr::render_lazy(rsx!{
     div {
     div {
         (0..5).map(|i| rsx!(
         (0..5).map(|i| rsx!(
             "Number: {i}"
             "Number: {i}"
@@ -45,10 +45,10 @@ let content = dioxus_ssr::render(rsx!{
 ## Rendering a VirtualDom
 ## Rendering a VirtualDom
 
 
 ```rust, ignore
 ```rust, ignore
-let mut dom = VirtualDom::new(app);
-let _ = dom.rebuild();
+let mut vdom = VirtualDom::new(app);
+let _ = vdom.rebuild();
 
 
-let content = dioxus_ssr::render_vdom(&dom);
+let content = dioxus_ssr::render(&vdom);
 ```
 ```
 
 
 
 
@@ -57,37 +57,42 @@ let content = dioxus_ssr::render_vdom(&dom);
 
 
 ## Usage in pre-rendering
 ## Usage in pre-rendering
 
 
-This crate is particularly useful in pre-generating pages server-side and then selectively loading dioxus client-side to pick up the reactive elements.
+This crate is particularly useful in pre-generating pages server-side and then selectively loading Dioxus client-side to pick up the reactive elements.
 
 
-In fact, this crate supports hydration out of the box. However, it is extremely important that both the client and server will generate the exact same VirtualDOMs - the client picks up its VirtualDOM assuming that the pre-rendered page output is the same. To do this, you need to make sure that your VirtualDOM implementation is deterministic! This could involve either serializing our app state and sending it to the client, hydrating only parts of the page, or building tests to ensure what's rendered on the server is the same as the client.
+This crate supports hydration out of the box. However, both the client and server must generate the *exact* same VirtualDOMs - the client picks up its VirtualDOM assuming that the pre-rendered page output is the same. To do this, you need to make sure that your VirtualDOM implementation is deterministic! This could involve either serializing our app state and sending it to the client, hydrating only parts of the page, or building tests to ensure what's rendered on the server is the same as the client.
 
 
 With pre-rendering enabled, this crate will generate element nodes with Element IDs pre-associated. During hydration, the Dioxus-WebSys renderer will attach the Virtual nodes to these real nodes after a page query.
 With pre-rendering enabled, this crate will generate element nodes with Element IDs pre-associated. During hydration, the Dioxus-WebSys renderer will attach the Virtual nodes to these real nodes after a page query.
 
 
-To enable pre-rendering, simply configure the `SsrConfig` with pre-rendering enabled.
+To enable pre-rendering, simply set the pre-rendering flag to true.
 
 
 ```rust, ignore
 ```rust, ignore
-let dom = VirtualDom::new(App);
+let mut vdom = VirtualDom::new(App);
+
+let _ = vdom.rebuild();
+
+let mut renderer = dioxus_ssr::Renderer::new();
+renderer.pre_render = true;
 
 
-let text = dioxus_ssr::render_vdom(App, Config { pre_render: true, ..Default::default() });
+let text = renderer.render(&vdom);
 ```
 ```
 
 
 ## Usage in server-side rendering
 ## Usage in server-side rendering
 
 
-Dioxus SSR can also be to render on the server. Obviously, you can just render the VirtualDOM to a string and send that down.
+Dioxus SSR can also be used to render on the server. You can just render the VirtualDOM to a string and send that to the client.
 
 
 ```rust, ignore
 ```rust, ignore
-let text = dioxus_ssr::render_vdom(&vdom);
+let text = dioxus_ssr::render(&vdom);
 assert_eq!(text, "<div>hello world!</div>")
 assert_eq!(text, "<div>hello world!</div>")
 ```
 ```
 
 
-The rest of the space - IE doing this more efficiently, caching the virtualdom, etc, will all need to be a custom implementation for now.
+The rest of the space - IE doing this more efficiently, caching the VirtualDom, etc, will all need to be a custom implementation for now.
 
 
 ## Usage without a VirtualDom
 ## Usage without a VirtualDom
 
 
-Dioxus SSR needs an arena to allocate from - whether it be the VirtualDom or a dedicated Bump allocator. To render `rsx!` directly to a string, you'll want to create an `SsrRenderer` and call `render_lazy`.
+Dioxus SSR needs an arena to allocate from - whether it be the VirtualDom or a dedicated Bump allocator. To render `rsx!` directly to a string, you'll want to create a `Renderer` and call `render_lazy`.
 
 
 ```rust, ignore
 ```rust, ignore
-let text = dioxus_ssr::SsrRenderer::new().render_lazy(rsx!{
+let text = dioxus_ssr::Renderer::new().render_lazy(rsx!{
     div { "hello world" }
     div { "hello world" }
 });
 });
 assert_eq!(text, "<div>hello world!</div>")
 assert_eq!(text, "<div>hello world!</div>")
@@ -104,4 +109,4 @@ let text = render_lazy!(rsx!( div { "hello world" } ));
 Dioxus SSR is a powerful tool to generate static sites. Using Dioxus for static site generation _is_ a bit overkill, however. The new documentation generation library, Doxie, is essentially Dioxus SSR on steroids designed for static site generation with client-side hydration.
 Dioxus SSR is a powerful tool to generate static sites. Using Dioxus for static site generation _is_ a bit overkill, however. The new documentation generation library, Doxie, is essentially Dioxus SSR on steroids designed for static site generation with client-side hydration.
 
 
 
 
-Again, simply render the VirtualDOM to a string using `render_vdom` or any of the other render methods.
+Again, simply render the VirtualDOM to a string using `render` or any of the other render methods.

+ 9 - 8
packages/tui/README.md

@@ -61,9 +61,9 @@ fn app(cx: Scope) -> Element {
 
 
 ## Background
 ## Background
 
 
-You can use Html-like semantics with stylesheets, inline styles, tree hierarchy, components, and more in your  [`text-based user interface (TUI)`](https://en.wikipedia.org/wiki/Text-based_user_interface) application.
+You can use Html-like semantics with inline styles, tree hierarchy, components, and more in your [`text-based user interface (TUI)`](https://en.wikipedia.org/wiki/Text-based_user_interface) application.
 
 
-Rink is basically a port of [Ink](https://github.com/vadimdemedes/ink) but for [`Rust`](https://www.rust-lang.org/) and [`Dioxus`](https://dioxuslabs.com/). Rink doesn't depend on Node.js or any other JavaScript runtime, so your binaries are portable and beautiful.
+Rink is essentially a port of [Ink](https://github.com/vadimdemedes/ink) but for [`Rust`](https://www.rust-lang.org/) and [`Dioxus`](https://dioxuslabs.com/). Rink doesn't depend on Node.js or any other JavaScript runtime, so your binaries are portable and beautiful.
 
 
 ## Limitations
 ## Limitations
 
 
@@ -82,13 +82,14 @@ Rendering a VirtualDom works fine, but the ecosystem of hooks is not yet ready.
 ## Features
 ## Features
 
 
 Rink features:
 Rink features:
-- [x] Flexbox based layout system
+- [x] Flexbox-based layout system
 - [ ] CSS selectors
 - [ ] CSS selectors
 - [x] inline CSS support
 - [x] inline CSS support
 - [x] Built-in focusing system
 - [x] Built-in focusing system
-- [ ] high-quality keyboard support
-* [ ] Support for events, hooks, and callbacks<sup>1</sup>
-* [ ] Html tags<sup>2</sup>
+* [x] Widgets<sup>1</sup>
+* [ ] Support for events, hooks, and callbacks<sup>2</sup>
+* [ ] Html tags<sup>3</sup>
 
 
-<sup>1</sup> Basic keyboard and mouse events are implemented.
-<sup>2</sup> Currently, HTML tags don't translate into any meaning inside of rink. So an `input` won't really mean anything nor does it have any additional functionality.
+<sup>1</sup> Currently only a subset of the input element is implemented as a component (not an element). The `Input` component supports sliders, text, numbers, passwords, buttons, and checkboxes.
+<sup>2</sup> Basic keyboard, mouse, and focus events are implemented.
+<sup>3</sup> Currently, most HTML tags don't translate into any meaning inside of Dioxus TUI. So an `input` *element* won't mean anything nor does it have any additional functionality.

+ 6 - 6
packages/web/README.md

@@ -5,8 +5,8 @@
 [![Build Status][actions-badge]][actions-url]
 [![Build Status][actions-badge]][actions-url]
 [![Discord chat][discord-badge]][discord-url]
 [![Discord chat][discord-badge]][discord-url]
 
 
-[crates-badge]: https://img.shields.io/crates/v/rsx-rosetta.svg
-[crates-url]: https://crates.io/crates/rsx-rosetta
+[crates-badge]: https://img.shields.io/crates/v/dioxus-web.svg
+[crates-url]: https://crates.io/crates/dioxus-web
 
 
 [mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
 [mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
 [mit-url]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE
 [mit-url]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE
@@ -19,15 +19,15 @@
 
 
 [Website](https://dioxuslabs.com) |
 [Website](https://dioxuslabs.com) |
 [Guides](https://dioxuslabs.com/guide/) |
 [Guides](https://dioxuslabs.com/guide/) |
-[API Docs](https://docs.rs/rsx-rosetta/latest/rsx-rosetta) |
+[API Docs](https://docs.rs/dioxus-web/latest/dioxus_web) |
 [Chat](https://discord.gg/XgGxMSkvUM)
 [Chat](https://discord.gg/XgGxMSkvUM)
 
 
 ## Overview
 ## Overview
 
 
 Run Dioxus in the browser using WebAssembly.
 Run Dioxus in the browser using WebAssembly.
 
 
-- Relies on sledgehammer and websys to modify the dom
-- Supports instant hotreloading via the Dioxus CLI
+- Relies on [sledgehammer-bindgen](https://github.com/Demonthos/sledgehammer_bindgen) and [web-sys](https://github.com/rustwasm/wasm-bindgen/tree/main/crates/web-sys) to modify the dom
+- Supports instant hot reloading via the Dioxus CLI
 - Around 60k gzipped
 - Around 60k gzipped
 
 
 ## Contributing
 ## Contributing
@@ -41,6 +41,6 @@ This project is licensed under the [MIT license].
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 [mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
 
 
 Unless you explicitly state otherwise, any contribution intentionally submitted
 Unless you explicitly state otherwise, any contribution intentionally submitted
-for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
+for inclusion in Dioxus by you shall be licensed as MIT without any additional
 terms or conditions.
 terms or conditions.
 
 

+ 5 - 3
packages/web/src/dom.rs

@@ -229,11 +229,13 @@ pub fn virtual_event_from_websys_event(event: web_sys::Event, target: Element) -
 
 
         "change" | "input" | "invalid" | "reset" | "submit" => read_input_to_data(target),
         "change" | "input" | "invalid" | "reset" | "submit" => read_input_to_data(target),
 
 
-        "click" | "contextmenu" | "dblclick" | "doubleclick" | "drag" | "dragend" | "dragenter"
-        | "dragexit" | "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown"
-        | "mouseenter" | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => {
+        "click" | "contextmenu" | "dblclick" | "doubleclick" | "mousedown" | "mouseenter"
+        | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => {
             Rc::new(MouseData::from(event))
             Rc::new(MouseData::from(event))
         }
         }
+        "drag" | "dragend" | "dragenter" | "dragexit" | "dragleave" | "dragover" | "dragstart"
+        | "drop" => Rc::new(DragData::from(event)),
+
         "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture"
         "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture"
         | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => {
         | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => {
             Rc::new(PointerData::from(event))
             Rc::new(PointerData::from(event))