From d559fdaeab7a3f69541aae0c61e6d6672f348e9e Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 12 Aug 2023 19:19:46 -0500 Subject: [PATCH 01/15] fix borrowed props with temp values --- .../props_safety_temporary_values.rs | 24 +++++++++++++++++++ .../props_safety_temporary_values.stderr | 12 ++++++++++ packages/core/src/properties.rs | 1 + packages/core/src/scopes.rs | 4 +++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/core/compile_tests/props_safety_temporary_values.rs create mode 100644 packages/core/compile_tests/props_safety_temporary_values.stderr diff --git a/packages/core/compile_tests/props_safety_temporary_values.rs b/packages/core/compile_tests/props_safety_temporary_values.rs new file mode 100644 index 000000000..c332f63c4 --- /dev/null +++ b/packages/core/compile_tests/props_safety_temporary_values.rs @@ -0,0 +1,24 @@ +use dioxus::prelude::*; + +fn main() {} + +fn app(cx: Scope) -> Element { + let count = vec![1, 2, 3]; + + render! { + unsafe_child_component { + borrowed: &count + } + } +} + +#[derive(Props)] +struct Testing<'a> { + borrowed: &'a Vec, +} + +fn unsafe_child_component<'a>(cx: Scope<'a, Testing<'a>>) -> Element<'a> { + cx.render(rsx! { + div { "{cx.props.borrowed:?}" } + }) +} diff --git a/packages/core/compile_tests/props_safety_temporary_values.stderr b/packages/core/compile_tests/props_safety_temporary_values.stderr new file mode 100644 index 000000000..c1ef443c9 --- /dev/null +++ b/packages/core/compile_tests/props_safety_temporary_values.stderr @@ -0,0 +1,12 @@ +error[E0515]: cannot return value referencing local variable `count` + --> compile_tests/props_safety_temporary_values.rs:8:5 + | +8 | / render! { +9 | | unsafe_child_component { +10 | | borrowed: &count + | | ------ `count` is borrowed here +11 | | } +12 | | } + | |_____^ returns a value referencing data owned by the current function + | + = note: this error originates in the macro `render` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/packages/core/src/properties.rs b/packages/core/src/properties.rs index f754f8b68..3f0d9ef97 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -79,4 +79,5 @@ pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element<'a>) fn unsafe_props_fail() { let t = trybuild::TestCases::new(); t.compile_fail("compile_tests/props_safety.rs"); + t.compile_fail("compile_tests/props_safety_temporary_values.rs"); } diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 5ada89069..17e499d62 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -424,7 +424,9 @@ impl<'src> ScopeState { fn_name: &'static str, ) -> DynamicNode<'src> where - P: Properties + 'child, + // The properties must be valid until the next bump frame + P: Properties + 'src, + // The current bump allocator frame must outlive the child's borrowed props 'src: 'child, { let vcomp = VProps::new(component, P::memoize, props); From d8704a0447ae1376cee18cf6cd556dc0e157eb4a Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 21 Aug 2023 21:28:32 +0700 Subject: [PATCH 02/15] deps: Update keyboard-types to 0.7. (#1378) --- packages/html/Cargo.toml | 2 +- packages/native-core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/html/Cargo.toml b/packages/html/Cargo.toml index 86ccb029d..5644b440c 100644 --- a/packages/html/Cargo.toml +++ b/packages/html/Cargo.toml @@ -17,7 +17,7 @@ serde_repr = { version = "0.1", optional = true } wasm-bindgen = { workspace = true, optional = true } euclid = "0.22.7" enumset = "1.0.11" -keyboard-types = "0.6.2" +keyboard-types = "0.7" async-trait = "0.1.58" serde-value = "0.7.0" tokio = { workspace = true, features = ["fs", "io-util"], optional = true } diff --git a/packages/native-core/Cargo.toml b/packages/native-core/Cargo.toml index 5f084732d..6f3f5aa04 100644 --- a/packages/native-core/Cargo.toml +++ b/packages/native-core/Cargo.toml @@ -12,7 +12,7 @@ authors = ["Jonathan Kelley", "Evan Almloff"] [dependencies] dioxus-core = { workspace = true, optional = true } -keyboard-types = "0.6.2" +keyboard-types = "0.7" smallvec = "1.6" rustc-hash = { workspace = true } anymap = "1.0.0-beta.2" From 9c03d68d888453c96be7f1c5ad68b2ec16d64756 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 21 Aug 2023 14:33:52 -0500 Subject: [PATCH 03/15] expose new_in_scope for signals --- packages/signals/src/signal.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index a5599a1ce..f41624f96 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -145,6 +145,21 @@ impl Signal { } } + /// Create a new signal with a custom owner scope. The signal will be dropped when the owner scope is dropped instead of the current scope. + pub fn new_in_scope(value: T, owner: ScopeId) -> Self { + Self { + inner: CopyValue::new_in_scope( + SignalData { + subscribers: Default::default(), + effect_subscribers: Default::default(), + update_any: schedule_update_any().expect("in a virtual dom"), + value, + }, + owner, + ), + } + } + /// Get the scope the signal was created in. pub fn origin_scope(&self) -> ScopeId { self.inner.origin_scope() From 882c3c9dfb6abd061263bbaeaf162633a315762a Mon Sep 17 00:00:00 2001 From: Yolo <92775570+HashCookie@users.noreply.github.com> Date: Tue, 22 Aug 2023 23:39:22 +0800 Subject: [PATCH 04/15] Update ZH_CN.md to use 0.4 version of guide (#1388) * fix: readme awesome link * Update ZH_CN.md to use 0.4 version of guide --- notes/README/ZH_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/README/ZH_CN.md b/notes/README/ZH_CN.md index 1c4abc667..45bf82f09 100644 --- a/notes/README/ZH_CN.md +++ b/notes/README/ZH_CN.md @@ -40,7 +40,7 @@ | 代码示例 | - 开发指南 + 开发指南 | English | From da4794d7937ae9d554a1be7e2d7b5dfe6645e80d Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 22 Aug 2023 11:56:13 -0700 Subject: [PATCH 05/15] bump core to 0.4.2 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b55f4628..252e9c83e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,12 +50,12 @@ members = [ exclude = ["examples/mobile_demo"] [workspace.package] -version = "0.4.1" +version = "0.4.2" # dependencies that are shared across packages [workspace.dependencies] dioxus = { path = "packages/dioxus", version = "0.4.0" } -dioxus-core = { path = "packages/core", version = "0.4.1" } +dioxus-core = { path = "packages/core", version = "0.4.2" } dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" } dioxus-router = { path = "packages/router", version = "0.4.1" } dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" } From de87ba6548adbf5af08a3148da50e5ea07668083 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 22 Aug 2023 20:48:03 -0400 Subject: [PATCH 06/15] Update all uncommented commands to remove actions-rs (#1366) * Update all uncommented commands to remove actions-rs (#1) * install target in toolchain action * add linux target explicitly * try latest * fix install --- .github/workflows/main.yml | 46 ++++++++-------- .github/workflows/playwright.yml | 71 ++++++++++++------------- packages/cli/.github/workflows/main.yml | 34 ++++-------- 3 files changed, 65 insertions(+), 86 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6e14ab6f..04f367b8e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,52 +85,56 @@ jobs: matrix_test: runs-on: ${{ matrix.platform.os }} + env: + RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }} strategy: matrix: platform: - { target: x86_64-pc-windows-msvc, os: windows-latest, - toolchain: '1.70.0', + toolchain: "1.70.0", cross: false, - command: 'test', - args: '--all --tests' + command: "test", + args: "--all --tests", } - { target: x86_64-apple-darwin, os: macos-latest, - toolchain: '1.70.0', + toolchain: "1.70.0", cross: false, - command: 'test', - args: '--all --tests' + command: "test", + args: "--all --tests", } - { target: aarch64-apple-ios, os: macos-latest, - toolchain: '1.70.0', + toolchain: "1.70.0", cross: false, - command: 'build', - args: '--package dioxus-mobile' + command: "build", + args: "--package dioxus-mobile", } - { target: aarch64-linux-android, os: ubuntu-latest, - toolchain: '1.70.0', + toolchain: "1.70.0", cross: true, - command: 'build', - args: '--package dioxus-mobile' + command: "build", + args: "--package dioxus-mobile", } steps: - uses: actions/checkout@v3 - name: install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.platform.toolchain }} - target: ${{ matrix.platform.target }} - override: true - default: true + targets: ${{ matrix.platform.target }} + + - name: Install cross + if: ${{ matrix.platform.cross == true }} + uses: taiki-e/install-action@cross - uses: Swatinem/rust-cache@v2 with: @@ -138,13 +142,8 @@ jobs: save-if: ${{ matrix.features.key == 'all' }} - name: test - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.platform.cross }} - command: ${{ matrix.platform.command }} - args: --target ${{ matrix.platform.target }} ${{ matrix.platform.args }} - - + run: | + ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }} # Coverage is disabled until we can fix it # coverage: @@ -166,4 +165,3 @@ jobs: # uses: codecov/codecov-action@v2 # with: # fail_ci_if_error: false - diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 41fa92fa7..dba32d257 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,9 +1,9 @@ name: Playwright Tests on: push: - branches: [ main, master ] + branches: [main, master] pull_request: - branches: [ main, master ] + branches: [main, master] defaults: run: working-directory: ./playwright-tests @@ -16,39 +16,36 @@ jobs: test: if: github.event.pull_request.draft == false timeout-minutes: 60 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - # Do our best to cache the toolchain and node install steps - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: Swatinem/rust-cache@v2 - - name: Install WASM toolchain - run: rustup target add wasm32-unknown-unknown - - name: Install dependencies - run: npm ci - - name: Install Playwright - run: npm install -D @playwright/test - - name: Install Playwright Browsers - run: npx playwright install --with-deps - # Cache the CLI by using cargo run internally - # - name: Install Dioxus CLI - # uses: actions-rs/cargo@v1 - # with: - # command: install - # args: --path packages/cli - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v3 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 + # Do our best to cache the toolchain and node install steps + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v2 + - name: Install dependencies + run: npm ci + - name: Install Playwright + run: npm install -D @playwright/test + - name: Install Playwright Browsers + run: npx playwright install --with-deps + # Cache the CLI by using cargo run internally + # - name: Install Dioxus CLI + # uses: actions-rs/cargo@v1 + # with: + # command: install + # args: --path packages/cli + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/packages/cli/.github/workflows/main.yml b/packages/cli/.github/workflows/main.yml index f978ba7a2..b22f78eae 100644 --- a/packages/cli/.github/workflows/main.yml +++ b/packages/cli/.github/workflows/main.yml @@ -8,47 +8,31 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - name: Install Rust + uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: check + - run: cargo check test: name: Test Suite runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - name: Install Rust + uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: test + - run: cargo test fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - name: Install Rust + uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v1 - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all -- --check # clippy: # name: Clippy From 31f8bab20d818506c0cfd902887e66e23515c6d2 Mon Sep 17 00:00:00 2001 From: Jani Mustonen Date: Fri, 25 Aug 2023 16:31:23 +0300 Subject: [PATCH 07/15] Add ScopeId::ROOT (#1398) * add ScopeId::ROOT * replace ScopeId(0) with ScopeId::ROOT --------- Co-authored-by: Jani Mustonen --- examples/mobile_demo/src/lib.rs | 2 +- packages/core/src/arena.rs | 4 +-- packages/core/src/events.rs | 2 +- packages/core/src/scope_context.rs | 4 +-- packages/core/src/scopes.rs | 15 ++++++++ packages/core/src/virtual_dom.rs | 10 +++--- packages/core/tests/attr_cleanup.rs | 8 ++--- packages/core/tests/bubble_error.rs | 2 +- packages/core/tests/context_api.rs | 6 ++-- packages/core/tests/cycle.rs | 6 ++-- packages/core/tests/diff_component.rs | 6 ++-- packages/core/tests/diff_element.rs | 14 ++++---- packages/core/tests/diff_keyed_list.rs | 24 ++++++------- packages/core/tests/diff_unkeyed_list.rs | 36 +++++++++---------- packages/core/tests/lifecycle.rs | 16 ++++----- packages/core/tests/miri_simple.rs | 12 +++---- packages/core/tests/miri_stress.rs | 16 ++++----- .../src/utils/persistant_iterator.rs | 4 +-- packages/signals/tests/create.rs | 2 +- packages/signals/tests/selector.rs | 4 +-- packages/signals/tests/subscribe.rs | 2 +- packages/ssr/src/renderer.rs | 2 +- 22 files changed, 106 insertions(+), 91 deletions(-) diff --git a/examples/mobile_demo/src/lib.rs b/examples/mobile_demo/src/lib.rs index 9d533e52d..992c53541 100644 --- a/examples/mobile_demo/src/lib.rs +++ b/examples/mobile_demo/src/lib.rs @@ -72,7 +72,7 @@ fn app(cx: Scope) -> Element { onclick: move|_| { println!("Clicked!"); items.push(items.len()); - cx.needs_update_any(ScopeId(0)); + cx.needs_update_any(ScopeId::ROOT); println!("Requested update"); }, "Add item" diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs index c8f7ce3c9..b7f768755 100644 --- a/packages/core/src/arena.rs +++ b/packages/core/src/arena.rs @@ -35,7 +35,7 @@ impl ElementRef { Self { template: None, path: ElementPath::Root(0), - scope: ScopeId(0), + scope: ScopeId::ROOT, } } } @@ -60,7 +60,7 @@ impl VirtualDom { fn next_reference(&mut self, template: &VNode, path: ElementPath) -> ElementId { let entry = self.elements.vacant_entry(); let id = entry.key(); - let scope = self.runtime.current_scope_id().unwrap_or(ScopeId(0)); + let scope = self.runtime.current_scope_id().unwrap_or(ScopeId::ROOT); entry.insert(ElementRef { // We know this is non-null because it comes from a reference diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index b85e0394d..4778ff4d3 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -143,7 +143,7 @@ pub struct EventHandler<'bump, T = ()> { impl Default for EventHandler<'_, T> { fn default() -> Self { Self { - origin: ScopeId(0), + origin: ScopeId::ROOT, callback: Default::default(), } } diff --git a/packages/core/src/scope_context.rs b/packages/core/src/scope_context.rs index 14366eefb..173f43e18 100644 --- a/packages/core/src/scope_context.rs +++ b/packages/core/src/scope_context.rs @@ -179,7 +179,7 @@ impl ScopeContext { pub fn provide_root_context(&self, context: T) -> T { with_runtime(|runtime| { runtime - .get_context(ScopeId(0)) + .get_context(ScopeId::ROOT) .unwrap() .provide_context(context) }) @@ -203,7 +203,7 @@ impl ScopeContext { /// This is good for tasks that need to be run after the component has been dropped. pub fn spawn_forever(&self, fut: impl Future + 'static) -> TaskId { // The root scope will never be unmounted so we can just add the task at the top of the app - let id = self.tasks.spawn(ScopeId(0), fut); + let id = self.tasks.spawn(ScopeId::ROOT, fut); // wake up the scheduler if it is sleeping self.tasks diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 17e499d62..996529a0d 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -63,6 +63,21 @@ impl<'a, T> std::ops::Deref for Scoped<'a, T> { #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub struct ScopeId(pub usize); +impl ScopeId { + /// The root ScopeId. + /// + /// This scope will last for the entire duration of your app, making it convenient for long-lived state + /// that is created dynamically somewhere down the component tree. + /// + /// # Example + /// + /// ```rust, ignore + /// use dioxus_signals::*; + /// let my_persistent_state = Signal::new_in_scope(ScopeId::ROOT, String::new()); + /// ``` + pub const ROOT: ScopeId = ScopeId(0); +} + /// A component's state separate from its props. /// /// This struct exists to provide a common interface for all scopes without relying on generics. diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index a1def71d2..c2e56c776 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -270,7 +270,7 @@ impl VirtualDom { ); // Unlike react, we provide a default error boundary that just renders the error as a string - root.provide_context(Rc::new(ErrorBoundary::new(ScopeId(0)))); + root.provide_context(Rc::new(ErrorBoundary::new(ScopeId::ROOT))); // the root element is always given element ID 0 since it's the container for the entire tree dom.elements.insert(ElementRef::none()); @@ -289,7 +289,7 @@ impl VirtualDom { /// /// This scope has a ScopeId of 0 and is the root of the tree pub fn base_scope(&self) -> &ScopeState { - self.get_scope(ScopeId(0)).unwrap() + self.get_scope(ScopeId::ROOT).unwrap() } /// Build the virtualdom with a global context inserted into the base scope @@ -547,10 +547,10 @@ impl VirtualDom { /// ``` pub fn rebuild(&mut self) -> Mutations { let _runtime = RuntimeGuard::new(self.runtime.clone()); - match unsafe { self.run_scope(ScopeId(0)).extend_lifetime_ref() } { + match unsafe { self.run_scope(ScopeId::ROOT).extend_lifetime_ref() } { // Rebuilding implies we append the created elements to the root RenderReturn::Ready(node) => { - let m = self.create_scope(ScopeId(0), node); + let m = self.create_scope(ScopeId::ROOT, node); self.mutations.edits.push(Mutation::AppendChildren { id: ElementId(0), m, @@ -663,6 +663,6 @@ impl VirtualDom { impl Drop for VirtualDom { fn drop(&mut self) { // Simply drop this scope which drops all of its children - self.drop_scope(ScopeId(0), true); + self.drop_scope(ScopeId::ROOT, true); } } diff --git a/packages/core/tests/attr_cleanup.rs b/packages/core/tests/attr_cleanup.rs index 683f02260..539a0b399 100644 --- a/packages/core/tests/attr_cleanup.rs +++ b/packages/core/tests/attr_cleanup.rs @@ -34,7 +34,7 @@ fn attrs_cycle() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -56,7 +56,7 @@ fn attrs_cycle() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -65,7 +65,7 @@ fn attrs_cycle() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -88,7 +88,7 @@ fn attrs_cycle() { ); // we take the node taken by attributes since we reused it - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ diff --git a/packages/core/tests/bubble_error.rs b/packages/core/tests/bubble_error.rs index 7d6966c46..af2a34219 100644 --- a/packages/core/tests/bubble_error.rs +++ b/packages/core/tests/bubble_error.rs @@ -24,7 +24,7 @@ fn bubbles_error() { let _edits = dom.rebuild().santize(); } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } diff --git a/packages/core/tests/context_api.rs b/packages/core/tests/context_api.rs index 696810cb0..05c66a41e 100644 --- a/packages/core/tests/context_api.rs +++ b/packages/core/tests/context_api.rs @@ -27,11 +27,11 @@ fn state_shares() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); assert_eq!(dom.base_scope().consume_context::().unwrap(), 1); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); assert_eq!(dom.base_scope().consume_context::().unwrap(), 2); @@ -41,7 +41,7 @@ fn state_shares() { [SetText { value: "Value is 2", id: ElementId(1,) },] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); dom.mark_dirty(ScopeId(2)); let edits = dom.render_immediate(); assert_eq!( diff --git a/packages/core/tests/cycle.rs b/packages/core/tests/cycle.rs index 10498f5cc..20d1c9343 100644 --- a/packages/core/tests/cycle.rs +++ b/packages/core/tests/cycle.rs @@ -23,7 +23,7 @@ fn cycling_elements() { ); } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -33,7 +33,7 @@ fn cycling_elements() { ); // notice that the IDs cycle back to ElementId(1), preserving a minimal memory footprint - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -42,7 +42,7 @@ fn cycling_elements() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ diff --git a/packages/core/tests/diff_component.rs b/packages/core/tests/diff_component.rs index 69ab6de6d..4766ad378 100644 --- a/packages/core/tests/diff_component.rs +++ b/packages/core/tests/diff_component.rs @@ -75,7 +75,7 @@ fn component_swap() { ); } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -84,7 +84,7 @@ fn component_swap() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -93,7 +93,7 @@ fn component_swap() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ diff --git a/packages/core/tests/diff_element.rs b/packages/core/tests/diff_element.rs index 3ab9b284a..a0b9bfa84 100644 --- a/packages/core/tests/diff_element.rs +++ b/packages/core/tests/diff_element.rs @@ -12,19 +12,19 @@ fn text_diff() { let mut vdom = VirtualDom::new(app); _ = vdom.rebuild(); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().edits, [SetText { value: "hello 1", id: ElementId(2) }] ); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().edits, [SetText { value: "hello 2", id: ElementId(2) }] ); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().edits, [SetText { value: "hello 3", id: ElementId(2) }] @@ -46,7 +46,7 @@ fn element_swap() { let mut vdom = VirtualDom::new(app); _ = vdom.rebuild(); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().santize().edits, [ @@ -55,7 +55,7 @@ fn element_swap() { ] ); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().santize().edits, [ @@ -64,7 +64,7 @@ fn element_swap() { ] ); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().santize().edits, [ @@ -73,7 +73,7 @@ fn element_swap() { ] ); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); assert_eq!( vdom.render_immediate().santize().edits, [ diff --git a/packages/core/tests/diff_keyed_list.rs b/packages/core/tests/diff_keyed_list.rs index be26e00c0..ed14c2d95 100644 --- a/packages/core/tests/diff_keyed_list.rs +++ b/packages/core/tests/diff_keyed_list.rs @@ -39,7 +39,7 @@ fn keyed_diffing_out_of_order() { ); } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().edits, [ @@ -64,7 +64,7 @@ fn keyed_diffing_out_of_order_adds() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().edits, [ @@ -90,7 +90,7 @@ fn keyed_diffing_out_of_order_adds_3() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().edits, [ @@ -116,7 +116,7 @@ fn keyed_diffing_out_of_order_adds_4() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().edits, [ @@ -142,7 +142,7 @@ fn keyed_diffing_out_of_order_adds_5() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().edits, [ @@ -167,7 +167,7 @@ fn keyed_diffing_additions() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -192,7 +192,7 @@ fn keyed_diffing_additions_and_moves_on_ends() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -222,7 +222,7 @@ fn keyed_diffing_additions_and_moves_in_middle() { _ = dom.rebuild(); // LIS: 4, 5, 6 - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -256,7 +256,7 @@ fn controlled_keyed_diffing_out_of_order() { _ = dom.rebuild(); // LIS: 5, 6 - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -289,7 +289,7 @@ fn controlled_keyed_diffing_out_of_order_max_test() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -318,7 +318,7 @@ fn remove_list() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -343,7 +343,7 @@ fn no_common_keys() { _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ diff --git a/packages/core/tests/diff_unkeyed_list.rs b/packages/core/tests/diff_unkeyed_list.rs index 4934f6080..b5be161ef 100644 --- a/packages/core/tests/diff_unkeyed_list.rs +++ b/packages/core/tests/diff_unkeyed_list.rs @@ -27,7 +27,7 @@ fn list_creates_one_by_one() { ); // Rendering the first item should replace the placeholder with an element - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -38,7 +38,7 @@ fn list_creates_one_by_one() { ); // Rendering the next item should insert after the previous - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -49,7 +49,7 @@ fn list_creates_one_by_one() { ); // ... and again! - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -60,7 +60,7 @@ fn list_creates_one_by_one() { ); // once more - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -107,14 +107,14 @@ fn removes_one_by_one() { // Remove div(3) // Rendering the first item should replace the placeholder with an element - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [Remove { id: ElementId(6) }] ); // Remove div(2) - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [Remove { id: ElementId(4) }] @@ -122,7 +122,7 @@ fn removes_one_by_one() { // Remove div(1) and replace with a placeholder // todo: this should just be a remove with no placeholder - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -133,7 +133,7 @@ fn removes_one_by_one() { // load the 3 and replace the placeholder // todo: this should actually be append to, but replace placeholder is fine for now - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -170,7 +170,7 @@ fn list_shrink_multiroot() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -182,7 +182,7 @@ fn list_shrink_multiroot() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -194,7 +194,7 @@ fn list_shrink_multiroot() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -249,19 +249,19 @@ fn removes_one_by_one_multiroot() { ] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [Remove { id: ElementId(10) }, Remove { id: ElementId(12) }] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [Remove { id: ElementId(6) }, Remove { id: ElementId(8) }] ); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); assert_eq!( dom.render_immediate().santize().edits, [ @@ -328,7 +328,7 @@ fn remove_many() { } { - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); let edits = dom.render_immediate().santize(); assert_eq!( edits.edits, @@ -341,7 +341,7 @@ fn remove_many() { } { - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); let edits = dom.render_immediate().santize(); assert_eq!( edits.edits, @@ -360,7 +360,7 @@ fn remove_many() { } { - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); let edits = dom.render_immediate().santize(); assert_eq!( edits.edits, @@ -376,7 +376,7 @@ fn remove_many() { } { - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); let edits = dom.render_immediate().santize(); assert_eq!( edits.edits, diff --git a/packages/core/tests/lifecycle.rs b/packages/core/tests/lifecycle.rs index 04f6bc3cf..08b342631 100644 --- a/packages/core/tests/lifecycle.rs +++ b/packages/core/tests/lifecycle.rs @@ -58,7 +58,7 @@ fn events_generate() { dom.handle_event("click", Rc::new(MouseData::default()), ElementId(1), true); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); let edits = dom.render_immediate(); assert_eq!( @@ -107,7 +107,7 @@ fn events_generate() { // ); // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateElement { root: Some(2), tag: "div", children: 0 }, // ReplaceWith { root: Some(1), nodes: vec![2] } @@ -115,7 +115,7 @@ fn events_generate() { // ); // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateTextNode { root: Some(1), text: "Text2" }, // ReplaceWith { root: Some(2), nodes: vec![1] } @@ -124,7 +124,7 @@ fn events_generate() { // // child {} // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateElement { root: Some(2), tag: "h1", children: 0 }, // ReplaceWith { root: Some(1), nodes: vec![2] } @@ -133,7 +133,7 @@ fn events_generate() { // // placeholder // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreatePlaceholder { root: Some(1) }, // ReplaceWith { root: Some(2), nodes: vec![1] } @@ -141,7 +141,7 @@ fn events_generate() { // ); // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateTextNode { root: Some(2), text: "text 3" }, // ReplaceWith { root: Some(1), nodes: vec![2] } @@ -149,7 +149,7 @@ fn events_generate() { // ); // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateTextNode { text: "text 0", root: Some(1) }, // CreateTextNode { text: "text 1", root: Some(3) }, @@ -158,7 +158,7 @@ fn events_generate() { // ); // assert_eq!( -// dom.hard_diff(ScopeId(0)).edits, +// dom.hard_diff(ScopeId::ROOT).edits, // [ // CreateElement { tag: "h1", root: Some(2), children: 0 }, // ReplaceWith { root: Some(1), nodes: vec![2] }, diff --git a/packages/core/tests/miri_simple.rs b/packages/core/tests/miri_simple.rs index 6da2c4bf4..2282cb4e2 100644 --- a/packages/core/tests/miri_simple.rs +++ b/packages/core/tests/miri_simple.rs @@ -11,7 +11,7 @@ fn app_drops() { let mut dom = VirtualDom::new(app); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } @@ -31,7 +31,7 @@ fn hooks_drop() { let mut dom = VirtualDom::new(app); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } @@ -58,7 +58,7 @@ fn contexts_drop() { let mut dom = VirtualDom::new(app); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } @@ -77,7 +77,7 @@ fn tasks_drop() { let mut dom = VirtualDom::new(app); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } @@ -91,7 +91,7 @@ fn root_props_drop() { ); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } @@ -121,7 +121,7 @@ fn diffing_drops_old() { let mut dom = VirtualDom::new(app); _ = dom.rebuild(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } diff --git a/packages/core/tests/miri_stress.rs b/packages/core/tests/miri_stress.rs index 15b7ebf41..ff8d69788 100644 --- a/packages/core/tests/miri_stress.rs +++ b/packages/core/tests/miri_stress.rs @@ -62,7 +62,7 @@ fn test_memory_leak() { _ = dom.rebuild(); for _ in 0..5 { - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); _ = dom.render_immediate(); } } @@ -97,13 +97,13 @@ fn memo_works_properly() { _ = dom.rebuild(); // todo!() - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); - // dom.hard_diff(ScopeId(0)); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); + // dom.hard_diff(ScopeId::ROOT); } #[test] diff --git a/packages/native-core/src/utils/persistant_iterator.rs b/packages/native-core/src/utils/persistant_iterator.rs index 5d4902b87..2442af29f 100644 --- a/packages/native-core/src/utils/persistant_iterator.rs +++ b/packages/native-core/src/utils/persistant_iterator.rs @@ -354,7 +354,7 @@ fn persist_removes() { // "3" iter2.next(&rdom).id(); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); let update = vdom.render_immediate(); println!("{update:#?}"); dioxus_state.apply_mutations(&mut rdom, update); @@ -419,7 +419,7 @@ fn persist_instertions_before() { // "2" iter.next(&rdom).id(); - vdom.mark_dirty(ScopeId(0)); + vdom.mark_dirty(ScopeId::ROOT); let update = vdom.render_immediate(); dioxus_state.apply_mutations(&mut rdom, update); diff --git a/packages/signals/tests/create.rs b/packages/signals/tests/create.rs index 0681263ea..57d8325af 100644 --- a/packages/signals/tests/create.rs +++ b/packages/signals/tests/create.rs @@ -51,7 +51,7 @@ fn drop_signals() { } let _ = dom.rebuild().santize(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); dom.render_immediate(); fn create_without_cx() -> Signal { diff --git a/packages/signals/tests/selector.rs b/packages/signals/tests/selector.rs index 17eb1c38a..811871e88 100644 --- a/packages/signals/tests/selector.rs +++ b/packages/signals/tests/selector.rs @@ -124,7 +124,7 @@ fn memos_prevents_component_rerun() { } let _ = dom.rebuild().santize(); - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); dom.render_immediate(); { @@ -133,7 +133,7 @@ fn memos_prevents_component_rerun() { assert_eq!(current_counter.effect, 2); } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); dom.render_immediate(); dom.render_immediate(); diff --git a/packages/signals/tests/subscribe.rs b/packages/signals/tests/subscribe.rs index 5c1a99347..e0e7d2072 100644 --- a/packages/signals/tests/subscribe.rs +++ b/packages/signals/tests/subscribe.rs @@ -77,7 +77,7 @@ fn reading_subscribes() { } } - dom.mark_dirty(ScopeId(0)); + dom.mark_dirty(ScopeId::ROOT); dom.render_immediate(); dom.render_immediate(); diff --git a/packages/ssr/src/renderer.rs b/packages/ssr/src/renderer.rs index f23e654fb..154fad641 100644 --- a/packages/ssr/src/renderer.rs +++ b/packages/ssr/src/renderer.rs @@ -40,7 +40,7 @@ impl Renderer { } pub fn render_to(&mut self, buf: &mut impl Write, dom: &VirtualDom) -> std::fmt::Result { - self.render_scope(buf, dom, ScopeId(0)) + self.render_scope(buf, dom, ScopeId::ROOT) } pub fn render_scope( From 37eb929d6988c3c762b48cefe244292ffbb69e65 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 25 Aug 2023 15:00:38 -0400 Subject: [PATCH 08/15] Explain features necessary for the `pre_cache_static_routes` function. (#1401) --- packages/router/examples/static_generation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/router/examples/static_generation.rs b/packages/router/examples/static_generation.rs index 4bdc1df5f..19e7c7341 100644 --- a/packages/router/examples/static_generation.rs +++ b/packages/router/examples/static_generation.rs @@ -30,6 +30,8 @@ async fn main() { .join("\n") ); + // This function is available if you enable the ssr feature + // on the dioxus_router crate. pre_cache_static_routes::( &mut renderer, &DefaultRenderer { From 392c744ad1e6ec7fe229d60cbc3f0fccb7b2c3d5 Mon Sep 17 00:00:00 2001 From: Jay Graves Date: Fri, 1 Sep 2023 08:55:44 -0600 Subject: [PATCH 09/15] Make incremental a cfg feature. (#1409) * Make incremental a cfg feature. * Make the incremental feature default. --- packages/ssr/Cargo.toml | 6 +++++- packages/ssr/src/lib.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ssr/Cargo.toml b/packages/ssr/Cargo.toml index d1f460c8f..1450bd46e 100644 --- a/packages/ssr/Cargo.toml +++ b/packages/ssr/Cargo.toml @@ -17,7 +17,7 @@ rustc-hash = "1.1.0" lru = "0.10.0" log = "0.4.13" http = "0.2.9" -tokio = { version = "1.28", features = ["full"] } +tokio = { version = "1.28", features = ["full"], optional = true } [dev-dependencies] dioxus = { workspace = true } @@ -29,3 +29,7 @@ argh = "0.1.4" serde = "1.0.120" serde_json = "1.0.61" fs_extra = "1.2.0" + +[features] +default = ["incremental"] +incremental = ["dep:tokio"] diff --git a/packages/ssr/src/lib.rs b/packages/ssr/src/lib.rs index 0f91e02d9..45e3f59ea 100644 --- a/packages/ssr/src/lib.rs +++ b/packages/ssr/src/lib.rs @@ -3,8 +3,11 @@ mod cache; pub mod config; mod fs_cache; +#[cfg(feature = "incremental")] pub mod incremental; +#[cfg(feature = "incremental")] mod incremental_cfg; + pub mod renderer; pub mod template; From 4511b37da875c5d49ef43fa803f5a2deb9da48b5 Mon Sep 17 00:00:00 2001 From: fanyang Date: Sat, 2 Sep 2023 19:44:31 +0800 Subject: [PATCH 10/15] Fix cli compile error due to tauri bundler adding fields (#1416) New fields for debian settings: - desktop_template For NSIS settings: - custom_language_files - template --- packages/cli/src/config.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs index 2e499451f..0654dc375 100644 --- a/packages/cli/src/config.rs +++ b/packages/cli/src/config.rs @@ -381,6 +381,7 @@ impl From for tauri_bundler::DebianSettings { tauri_bundler::DebianSettings { depends: val.depends, files: val.files, + desktop_template: None, } } } @@ -522,6 +523,8 @@ impl From for tauri_bundler::NsisSettings { install_mode: val.install_mode.into(), languages: val.languages, display_language_selector: val.display_language_selector, + custom_language_files: None, + template: None, } } } From 1b977fdce91822418f97fb33d416c295ce77180f Mon Sep 17 00:00:00 2001 From: Stygmates Date: Sat, 2 Sep 2023 17:24:30 +0200 Subject: [PATCH 11/15] Add query segment example and documentation (#1417) * fix a few new clippy lints * Add query segment example * Add trait documentation * Change core package to root package The core package contains the virtual dom implementation ([here](https://github.com/DioxusLabs/dioxus/tree/master/packages/core)). Root package might be a more clear way to refer to the main directory --------- Co-authored-by: Evan Almloff --- Cargo.toml | 1 + examples/query_segments_demo/Cargo.toml | 12 ++++ examples/query_segments_demo/src/main.rs | 73 ++++++++++++++++++++++++ packages/router/src/contexts/router.rs | 34 ++++++----- packages/router/src/routable.rs | 6 +- packages/web/src/dom.rs | 1 + 6 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 examples/query_segments_demo/Cargo.toml create mode 100644 examples/query_segments_demo/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 252e9c83e..54c54ebf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ members = [ # Full project examples "examples/tailwind", "examples/PWA-example", + "examples/query_segments_demo", # Playwright tests "playwright-tests/liveview", "playwright-tests/web", diff --git a/examples/query_segments_demo/Cargo.toml b/examples/query_segments_demo/Cargo.toml new file mode 100644 index 000000000..4a7d784c7 --- /dev/null +++ b/examples/query_segments_demo/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "query_segments_demo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus = { path = "../../packages/dioxus", version = "*" } +dioxus-router = { path = "../../packages/router", version = "*" } +dioxus-web = { path = "../../packages/web", version = "*" } +form_urlencoded = "1.2.0" diff --git a/examples/query_segments_demo/src/main.rs b/examples/query_segments_demo/src/main.rs new file mode 100644 index 000000000..2348f1fe5 --- /dev/null +++ b/examples/query_segments_demo/src/main.rs @@ -0,0 +1,73 @@ +#![allow(non_snake_case, unused)] +//! Example: Url query segments usage +//! ------------------------------------ +//! +//! This example shows how to access and use multiple query segments present in an url on the web. +//! +//! Run `dx serve` and navigate to `http://localhost:8080/blog?name=John&surname=Doe` +use std::fmt::Display; + +use dioxus::prelude::*; +use dioxus_router::prelude::*; + +// ANCHOR: route +#[derive(Routable, Clone)] +#[rustfmt::skip] +enum Route { + // segments that start with ?: are query segments + #[route("/blog?:query_params")] + BlogPost { + // You must include query segments in child variants + query_params: BlogQuerySegments, + }, +} + +#[derive(Debug, Clone, PartialEq)] +struct BlogQuerySegments { + name: String, + surname: String, +} + +/// The display impl needs to display the query in a way that can be parsed: +impl Display for BlogQuerySegments { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "name={}&surname={}", self.name, self.surname) + } +} + +/// The query segment is anything that implements https://docs.rs/dioxus-router/latest/dioxus_router/routable/trait.FromQuery.html. You can implement that trait for a struct if you want to parse multiple query parameters. +impl FromQuery for BlogQuerySegments { + fn from_query(query: &str) -> Self { + let mut name = None; + let mut surname = None; + let pairs = form_urlencoded::parse(query.as_bytes()); + pairs.for_each(|(key, value)| { + if key == "name" { + name = Some(value.clone().into()); + } + if key == "surname" { + surname = Some(value.clone().into()); + } + }); + Self { + name: name.unwrap(), + surname: surname.unwrap(), + } + } +} + +#[inline_props] +fn BlogPost(cx: Scope, query_params: BlogQuerySegments) -> Element { + render! { + div{"This is your blogpost with a query segment:"} + div{format!("{:?}", query_params)} + } +} + +fn App(cx: Scope) -> Element { + render! { Router::{} } +} + +fn main() { + dioxus_web::launch(App); +} diff --git a/packages/router/src/contexts/router.rs b/packages/router/src/contexts/router.rs index 5a9a3f0c4..b15956991 100644 --- a/packages/router/src/contexts/router.rs +++ b/packages/router/src/contexts/router.rs @@ -2,7 +2,7 @@ use std::{ any::Any, collections::HashSet, rc::Rc, - sync::{Arc, RwLock, RwLockWriteGuard}, + sync::{Arc, RwLock}, }; use dioxus::prelude::*; @@ -36,7 +36,7 @@ struct MutableRouterState { /// A collection of router data that manages all routing functionality. #[derive(Clone)] pub struct RouterContext { - state: Arc>, + state: Rc>, subscribers: Arc>>, subscriber_update: Arc, @@ -56,7 +56,7 @@ impl RouterContext { R: Clone, ::Err: std::fmt::Display, { - let state = Arc::new(RwLock::new(MutableRouterState { + let state = Rc::new(RefCell::new(MutableRouterState { prefix: Default::default(), history: cfg.take_history(), unresolved_error: None, @@ -105,7 +105,7 @@ impl RouterContext { // set the updater { - let mut state = myself.state.write().unwrap(); + let mut state = myself.state.borrow_mut(); state.history.updater(Arc::new(move || { for &id in subscribers.read().unwrap().iter() { (mark_dirty)(id); @@ -117,20 +117,20 @@ impl RouterContext { } pub(crate) fn route_from_str(&self, route: &str) -> Result, String> { - let state = self.state.read().unwrap(); + let state = self.state.borrow(); state.history.parse_route(route) } /// Check whether there is a previous page to navigate back to. #[must_use] pub fn can_go_back(&self) -> bool { - self.state.read().unwrap().history.can_go_back() + self.state.borrow().history.can_go_back() } /// Check whether there is a future page to navigate forward to. #[must_use] pub fn can_go_forward(&self) -> bool { - self.state.read().unwrap().history.can_go_forward() + self.state.borrow().history.can_go_forward() } /// Go back to the previous location. @@ -138,7 +138,7 @@ impl RouterContext { /// Will fail silently if there is no previous location to go to. pub fn go_back(&self) { { - self.state.write().unwrap().history.go_back(); + self.state.borrow_mut().history.go_back(); } self.change_route(); @@ -149,7 +149,7 @@ impl RouterContext { /// Will fail silently if there is no next location to go to. pub fn go_forward(&self) { { - self.state.write().unwrap().history.go_forward(); + self.state.borrow_mut().history.go_forward(); } self.change_route(); @@ -206,8 +206,7 @@ impl RouterContext { /// The route that is currently active. pub fn current(&self) -> R { self.state - .read() - .unwrap() + .borrow() .history .current_route() .downcast::() @@ -218,7 +217,7 @@ impl RouterContext { /// The route that is currently active. pub fn current_route_string(&self) -> String { - self.any_route_to_string(&*self.state.read().unwrap().history.current_route()) + self.any_route_to_string(&*self.state.borrow().history.current_route()) } pub(crate) fn any_route_to_string(&self, route: &dyn Any) -> String { @@ -243,7 +242,7 @@ impl RouterContext { /// The prefix that is currently active. pub fn prefix(&self) -> Option { - self.state.read().unwrap().prefix.clone() + self.state.borrow().prefix.clone() } fn external(&self, external: String) -> Option { @@ -261,8 +260,8 @@ impl RouterContext { } } - fn state_mut(&self) -> RwLockWriteGuard { - self.state.write().unwrap() + fn state_mut(&self) -> RefMut { + self.state.borrow_mut() } /// Manually subscribe to the current route @@ -283,15 +282,14 @@ impl RouterContext { /// Clear any unresolved errors pub fn clear_error(&self) { - self.state.write().unwrap().unresolved_error = None; + self.state.borrow_mut().unresolved_error = None; self.update_subscribers(); } pub(crate) fn render_error<'a>(&self, cx: Scope<'a>) -> Element<'a> { self.state - .read() - .unwrap() + .borrow() .unresolved_error .as_ref() .and_then(|_| (self.failure_external_navigation)(cx)) diff --git a/packages/router/src/routable.rs b/packages/router/src/routable.rs index cd3dd354d..d9f5b2346 100644 --- a/packages/router/src/routable.rs +++ b/packages/router/src/routable.rs @@ -22,7 +22,11 @@ impl std::fmt::Display for RouteParseError { } } -/// Something that can be created from a query string +/// Something that can be created from a query string. +/// +/// This trait needs to be implemented if you want to turn a query string into a struct. +/// +/// A working example can be found in the `examples` folder in the root package under `query_segments_demo` pub trait FromQuery { /// Create an instance of `Self` from a query string fn from_query(query: &str) -> Self; diff --git a/packages/web/src/dom.rs b/packages/web/src/dom.rs index 9d0d837c5..52f2ab1a9 100644 --- a/packages/web/src/dom.rs +++ b/packages/web/src/dom.rs @@ -392,6 +392,7 @@ fn read_input_to_data(target: Element) -> Rc { .dyn_ref() .and_then(|input: &web_sys::HtmlInputElement| { input.files().and_then(|files| { + #[allow(clippy::arc_with_non_send_sync)] crate::file_engine::WebFileEngine::new(files) .map(|f| std::sync::Arc::new(f) as std::sync::Arc) }) From a0d1e5de3a91dcf66d801ee60a2771859050a3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Sun, 3 Sep 2023 00:51:34 +0200 Subject: [PATCH 12/15] fix: Typo on use_on_unmount (#1421) --- packages/hooks/src/use_on_unmount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hooks/src/use_on_unmount.rs b/packages/hooks/src/use_on_unmount.rs index 1fa4449c1..1309ca122 100644 --- a/packages/hooks/src/use_on_unmount.rs +++ b/packages/hooks/src/use_on_unmount.rs @@ -1,4 +1,4 @@ -/// Creats a callback that will be run before the component is removed. This can be used to clean up side effects from the component (created with use_effect) +/// Creates a callback that will be run before the component is removed. This can be used to clean up side effects from the component (created with use_effect) /// /// Example: /// ```rust From 94f76946fcd2da9f4eaddd61c4a098cd07e798b2 Mon Sep 17 00:00:00 2001 From: Leonard Date: Sun, 3 Sep 2023 00:59:20 +0200 Subject: [PATCH 13/15] Improve CLI docs (#1404) * Improve CLI docs * Fixed all the typos (hopefully). * Improved the bad English. This encompasses grammar, vocabulary, generally awkward phrases, etc. The result is easier to read and understand, and in some cases shorter. * Made some formatting improvements. This includes making formatting more consistent, but I changed some of it to be better, at least in my opinion. * Removed certain unnecessities, the biggest one being the commands documentation. I think this is unnecessary because of the `dx --help` command. It also needs to be updated every time a command gets added/updated/removed. It doesn't really provide much extra insight than `dx --help`. * Improved plugin documentation. I added a warning to ignore all of it, which is ironic, but the fact is that plugins are probably going to change. But by the time I learned that, I already made some changes to the plugin docs. This includes a better guide on how to get started (although still bad since the plugin system is too messy), and some general changes like the aforementioned English or formatting. * And more. I can't list it all, but I didn't use any destructive changes. The content might be reformatted (to be shorter or easier to understand), but the meaning isn't lost. * Fix grammar in packages/cli/docs/src/creating.md Co-authored-by: Evan Simkowitz * Update README.md * Change config example --------- Co-authored-by: Evan Simkowitz --- packages/cli/Dioxus.toml | 39 ++-- packages/cli/README.md | 56 ++++-- packages/cli/docs/book.toml | 2 +- packages/cli/docs/src/SUMMARY.md | 23 +-- packages/cli/docs/src/cmd/README.md | 30 --- packages/cli/docs/src/cmd/build.md | 56 ------ packages/cli/docs/src/cmd/clean.md | 27 --- packages/cli/docs/src/cmd/serve.md | 70 ------- packages/cli/docs/src/cmd/translate.md | 68 ------- packages/cli/docs/src/configure.md | 181 ++++++++---------- packages/cli/docs/src/creating.md | 20 +- packages/cli/docs/src/installation.md | 15 +- packages/cli/docs/src/introduction.md | 27 ++- packages/cli/docs/src/plugin/README.md | 87 +++++++-- .../cli/docs/src/plugin/interface/command.md | 8 +- .../cli/docs/src/plugin/interface/dirs.md | 19 +- packages/cli/docs/src/plugin/interface/log.md | 22 +-- .../cli/docs/src/plugin/interface/network.md | 15 +- packages/cli/docs/src/plugin/interface/os.md | 6 +- .../cli/docs/src/plugin/interface/path.md | 25 +-- 20 files changed, 308 insertions(+), 488 deletions(-) delete mode 100644 packages/cli/docs/src/cmd/README.md delete mode 100644 packages/cli/docs/src/cmd/build.md delete mode 100644 packages/cli/docs/src/cmd/clean.md delete mode 100644 packages/cli/docs/src/cmd/serve.md delete mode 100644 packages/cli/docs/src/cmd/translate.md diff --git a/packages/cli/Dioxus.toml b/packages/cli/Dioxus.toml index 792a15165..323f17da2 100644 --- a/packages/cli/Dioxus.toml +++ b/packages/cli/Dioxus.toml @@ -1,29 +1,31 @@ [application] -# dioxus project name -name = "dioxus-cli" +# App name +name = "project_name" -# default platfrom -# you can also use `dx serve/build --platform XXX` to use other platform -# value: web | desktop -default_platform = "desktop" +# The Dioxus platform to default to +default_platform = "web" -# Web `build` & `serve` dist path +# `build` & `serve` output path out_dir = "dist" -# resource (static) file folder +# The static resource path asset_dir = "public" [web.app] # HTML title tag content -title = "dioxus | ⛺" +title = "project_name" [web.watcher] -watch_path = ["src"] +# When watcher is triggered, regenerate the `index.html` +reload_html = true -# include `assets` in web platform +# Which files or dirs will be monitored +watch_path = ["src", "public"] + +# Include style or script assets [web.resource] # CSS style file @@ -34,12 +36,13 @@ script = [] [web.resource.dev] -# Javascript code file -# serve: [dev-server] only +# Same as [web.resource], but for development servers + +# CSS style file +style = [] + +# JavaScript files script = [] -[application.tools] - -# use binaryen.wasm-opt for output Wasm file -# binaryen just will trigger in `web` platform -binaryen = { wasm_opt = true } +[[web.proxy]] +backend = "http://localhost:8000/api/" \ No newline at end of file diff --git a/packages/cli/README.md b/packages/cli/README.md index 3167a6746..fcd9d25b4 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,43 +1,69 @@ -
-

📦✨ Dioxus CLI

+
+

📦✨ Dioxus CLI

Tooling to supercharge Dioxus projects

-**dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. -It handles all build, bundling, development and publishing to simplify web development. +The **dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. +It handles all building, bundling, development and publishing to simplify development. ## Installation -### Install stable version +### Install the stable version (recommended) + ``` cargo install dioxus-cli ``` -### Install from git repository + +### Install the latest development build through git + +To get the latest bug fixes and features, you can install the development version from git. +However, this is not fully tested. +That means you're probably going to have more bugs despite having the latest bug fixes. + ``` cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli ``` + +This will download the CLI from the master branch, +and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). + ### Install from local folder ``` cargo install --path . --debug ``` +## Get started -## Get Started - -Use `dx create project-name` to initialize a new Dioxus project.
- +Use `dx create project-name` to initialize a new Dioxus project. It will be cloned from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template) repository. -
- Alternatively, you can specify the template path: ``` dx create hello --template gh:dioxuslabs/dioxus-template ``` -## Dioxus Config File +Run `dx --help` for a list of all the available commands. +Furthermore, you can run `dx --help` to get help with a specific command. -Dioxus CLI will use `Dioxus.toml` file to Identify some project info and switch some cli feature. +## Dioxus config file -You can get more configure information from [Dioxus CLI Document](https://dioxuslabs.com/cli/configure.html). +You can use the `Dioxus.toml` file for further configuration. +Some fields are mandatory, but the CLI tool will tell you which ones are missing. +You can create a `Dioxus.toml` with all fields already set using `dx config init project-name`, +or you can use this bare-bones template (only mandatory fields) to get started: +```toml +[application] +name = "project-name" +# Currently supported platforms: web, desktop +default_platform = "web" + +[web.app] +title = "Hello" + +[web.watcher] + +[web.resource.dev] +``` + +The full anatomy of `Dioxus.toml` is shown on the [Dioxus website](https://dioxuslabs.com/learn/0.4/CLI/configure). diff --git a/packages/cli/docs/book.toml b/packages/cli/docs/book.toml index c5c216fe4..a1e57f634 100644 --- a/packages/cli/docs/book.toml +++ b/packages/cli/docs/book.toml @@ -3,4 +3,4 @@ authors = ["YuKun Liu"] language = "en" multilingual = false src = "src" -title = "Dioxus Cli" +title = "Dioxus CLI" diff --git a/packages/cli/docs/src/SUMMARY.md b/packages/cli/docs/src/SUMMARY.md index b5e3b91ae..98a66ae21 100644 --- a/packages/cli/docs/src/SUMMARY.md +++ b/packages/cli/docs/src/SUMMARY.md @@ -2,17 +2,12 @@ - [Introduction](./introduction.md) - [Installation](./installation.md) -- [Create a Project](./creating.md) -- [Configure Project](./configure.md) -- [Commands](./cmd/README.md) - - [Build](./cmd/build.md) - - [Serve](./cmd/serve.md) - - [Clean](./cmd/clean.md) - - [Translate](./cmd/translate.md) -- [Plugin Development](./plugin/README.md) - - [API.Log](./plugin/interface/log.md) - - [API.Command](./plugin/interface/command.md) - - [API.OS](./plugin/interface/os.md) - - [API.Directories](./plugin/interface/dirs.md) - - [API.Network](./plugin/interface/network.md) - - [API.Path](./plugin/interface/path.md) \ No newline at end of file +- [Create a project](./creating.md) +- [Configure a project](./configure.md) +- [Plugin development](./plugin/README.md) + - [API.Log](plugin/interface/log.md) + - [API.Command](plugin/interface/command.md) + - [API.OS](plugin/interface/os.md) + - [API.Directories](plugin/interface/dirs.md) + - [API.Network](plugin/interface/network.md) + - [API.Path](plugin/interface/path.md) \ No newline at end of file diff --git a/packages/cli/docs/src/cmd/README.md b/packages/cli/docs/src/cmd/README.md deleted file mode 100644 index 735794635..000000000 --- a/packages/cli/docs/src/cmd/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Commands - -In this chapter we will introduce all `dioxus-cli` commands. - -> You can also use `dx --help` to get cli help info. - -``` -Build, Bundle & Ship Dioxus Apps - -Usage: dx [OPTIONS] - -Commands: - build Build the Rust WASM app and all of its assets - translate Translate some source file into Dioxus code - serve Build, watch & serve the Rust WASM app and all of its assets - create Init a new project for Dioxus - clean Clean output artifacts - bundle Bundle the Rust desktop app and all of its assets - version Print the version of this extension - fmt Format some rsx - check Check the Rust files in the project for issues - config Dioxus config file controls - help Print this message or the help of the given subcommand(s) - -Options: - -v Enable verbose logging - --bin Specify bin target - -h, --help Print help - -V, --version Print version -``` diff --git a/packages/cli/docs/src/cmd/build.md b/packages/cli/docs/src/cmd/build.md deleted file mode 100644 index 6109d14f1..000000000 --- a/packages/cli/docs/src/cmd/build.md +++ /dev/null @@ -1,56 +0,0 @@ -# Build - -The `dx build` command can help you `pack & build` a dioxus project. - -``` -dioxus-build -Build the Rust WASM app and all of its assets - -USAGE: - dx build [OPTIONS] - -OPTIONS: - --example [default: ""] - --platform [default: "default_platform"] - --release [default: false] - --bin [default: None] -``` - -You can use this command to build a project: - -``` -dx build --release -``` - -## Target platform - -Use the `platform` option to choose your target platform: - -``` -# for desktop project -dx build --platform desktop -``` - -`platform` currently only supports `desktop` & `web`. - -``` -# for web project -dx build --platform web -``` - -## Specify workspace bin - -You can add the `--bin` option to select which crate you want Dioxus to build: - -``` -dx build --bin app -``` - -## Build Example - -You can use the `example` option to select a example to build: - -``` -# build the `test` example -dx build --exmaple test -``` diff --git a/packages/cli/docs/src/cmd/clean.md b/packages/cli/docs/src/cmd/clean.md deleted file mode 100644 index ef938d245..000000000 --- a/packages/cli/docs/src/cmd/clean.md +++ /dev/null @@ -1,27 +0,0 @@ -# Clean - -`dx clean` will clear the build artifacts (the out_dir and the cargo cache) - -``` -dioxus-clean -Clean build artifacts - -USAGE: - dx clean [OPTIONS] - -OPTIONS: - --bin [default: None] -``` - -# Example - -``` -dx clean -``` - -# Specify workspace bin -You can add the `--bin` option to select which crate you want Dioxus to clean artifacts from: - -``` -dx clean --bin app -``` diff --git a/packages/cli/docs/src/cmd/serve.md b/packages/cli/docs/src/cmd/serve.md deleted file mode 100644 index d8b4e0d42..000000000 --- a/packages/cli/docs/src/cmd/serve.md +++ /dev/null @@ -1,70 +0,0 @@ -# Serve - -The `dx serve` can start a dev server with hot-reloading - -``` -dioxus-serve -Build, watch & serve the Rust WASM app and all of its assets - -USAGE: - dx serve [OPTIONS] - -OPTIONS: - --example [default: ""] - --platform [default: "default_platform"] - --release [default: false] - --hot-reload [default: false] - --bin [default: None] -``` - -You can use this command to build project and start a dev server: - -``` -dx serve -``` - -## Serve Example - -You can use the `example` option to serve a example: - -``` -# serve the `test` example -dx serve --exmaple test -``` - -## Specify workspace bin - -You can add the `--bin` option to select which crate you want Dioxus to build and serve: - -``` -dx serve --bin app -``` - -## Open Browser - -You can add the `--open` option to open system default browser when server startup: - -``` -dx serve --open -``` - -## RSX Hot Reloading - -You can add the `--hot-reload` flag to enable [rsx hot reloading](https://dioxuslabs.com/docs/0.3/guide/en/getting_started/hot_reload.html). This will allow you to reload some rsx changes without a full recompile: - -``` -dx serve --open -``` - -## Cross Origin Policy - -You can add the `cross-origin-policy` option to change cross-origin header to: - -``` - Cross-Origin-Opener-Policy: same-origin - Cross-Origin-Embedder-Policy: require-corp -``` - -``` -dx serve --corss-origin-policy -``` diff --git a/packages/cli/docs/src/cmd/translate.md b/packages/cli/docs/src/cmd/translate.md deleted file mode 100644 index b03b4422c..000000000 --- a/packages/cli/docs/src/cmd/translate.md +++ /dev/null @@ -1,68 +0,0 @@ -# Translate - -`dx translate` can translate some `html` file into a Dioxus compoent - -``` -dioxus-translate -Translate some source file into a Dioxus component - -USAGE: - dx translate [OPTIONS] [OUTPUT] - -ARGS: - Output file, defaults to stdout if not present - -OPTIONS: - -c, --component Activate debug mode - -f, --file Input file -``` - -## Translate HTML to stdout - -You can use the `file` option to set path to the `html` file to translate: - -``` -dx transtale --file ./index.html -``` - -## Output rsx to a file - -You can pass a file to the traslate command to set the path to write the output of the command to: - -``` -dx translate --file ./index.html component.rsx -``` - -## Output rsx to a file - -Setting the `component` option will create a compoent from the HTML: - -``` -dx translate --file ./index.html --component -``` - -## Example - -This HTML: -```html -
-

Hello World

- Link -
-``` - -Translates into this Dioxus component: - -```rust -fn component(cx: Scope) -> Element { - cx.render(rsx! { - div { - h1 { "Hello World" }, - a { - href: "https://dioxuslabs.com/", - "Link" - } - } - }) -} -``` diff --git a/packages/cli/docs/src/configure.md b/packages/cli/docs/src/configure.md index 9d0cb0a9b..3b9f6189b 100644 --- a/packages/cli/docs/src/configure.md +++ b/packages/cli/docs/src/configure.md @@ -1,166 +1,155 @@ # Configure Project +This chapter will teach you how to configure the CLI with the `Dioxus.toml` file. +There's an [example](#config-example) which has comments to describe individual keys. +You can copy that or view this documentation for a more complete learning experience. -This chapter will introduce you to how to configure the CLI with your `Dioxus.toml` file - -Be aware that if the config file is present in the folder, some fields must be filled out, or the CLI tool will abort. The mandatory [table headers](https://toml.io/en/v1.0.0#table) and keys will have a '✍' sign beside it. +"🔒" indicates a mandatory item. Some headers are mandatory, but none of the keys inside them are. It might look weird, but it's normal. Simply don't include any keys. ## Structure -The CLI uses a `Dioxus.toml` file in the root of your crate to define some configuration for your `dioxus` project. +Each header has it's TOML form directly under it. -### Application ✍ +### Application 🔒 -General application confiration: - -``` +```toml [application] -# configuration ``` -1. ***name*** ✍ - project name & title -2. ***default_platform*** ✍ - which platform target for this project. +Application-wide configuration. Applies to both web and desktop. + +1. **name** 🔒 - Project name & title. + ```toml + name = "my_project" ``` - name = "my-project" - ``` -2. ***default_platform*** - The platform this project targets - ```ß - # current supported platforms: web, desktop - # default: web + +2. **default_platform** 🔒 - The platform this project targets + ```toml + # Currently supported platforms: web, desktop default_platform = "web" ``` - if you change this to `desktop`, the `dx build` will default building a desktop app -3. ***out_dir*** - The directory to place the build artifacts from `dx build` or `dx service` into. This is also where the `assets` directory will be copied to - ``` + +3. **out_dir** - The directory to place the build artifacts from `dx build` or `dx serve` into. This is also where the `assets` directory will be copied into. + ```toml out_dir = "dist" ``` -4. ***asset_dir*** - The directory with your static assets. The CLI will automatically copy these assets into the ***out_dir*** after a build/serve. - ``` + +4. **asset_dir** - The directory with your static assets. The CLI will automatically copy these assets into the **out_dir** after a build/serve. + ```toml asset_dir = "public" ``` -5. ***sub_package*** - The sub package in the workspace to build by default - ``` + +5. **sub_package** - The sub package in the workspace to build by default. + ```toml sub_package = "my-crate" ``` -### Web.App ✍ +### Web.App 🔒 -Configeration specific to web applications: - -``` +```toml [web.app] -# configuration ``` -1. ***title*** - The title of the web page - ``` +Web-specific configuration. + +1. **title** - The title of the web page. + ```toml # HTML title tag content - title = "dioxus app | ⛺" - ``` -2. ***base_path*** - The base path to build the appliation for serving at. This can be useful when serving your application in a subdirectory under a domain. For example when building a site to be served on github pages. + title = "project_name" ``` + +2. **base_path** - The base path to build the application for serving at. This can be useful when serving your application in a subdirectory under a domain. For example when building a site to be served on GitHub Pages. + ```toml # The application will be served at domain.com/my_application/, so we need to modify the base_path to the path where the application will be served base_path = "my_application" ``` ### Web.Watcher ✍ -Configeration related to the development server: - -``` +```toml [web.watcher] -# configuration ``` -1. ***reload_html*** - If this is true, the cli will rebuild the index.html file every time the application is rebuilt - ``` +Development server configuration. + +1. **reload_html** - If this is true, the cli will rebuild the index.html file every time the application is rebuilt + ```toml reload_html = true ``` -2. ***watch_path*** - The files & directories to moniter for changes - ``` + +2. **watch_path** - The files & directories to monitor for changes + ```toml watch_path = ["src", "public"] ``` -3. ***index_on_404*** - If enabled, Dioxus CLI will serve the root page when a route is not found. *This is needed when serving an application that uses the router* - ``` + +3. **index_on_404** - If enabled, Dioxus will serve the root page when a route is not found. +*This is needed when serving an application that uses the router*. +However, when serving your app using something else than Dioxus (e.g. GitHub Pages), you will have to check how to configure it on that platform. +In GitHub Pages, you can make a copy of `index.html` named `404.html` in the same directory. + ```toml index_on_404 = true ``` -### Web.Resource ✍ +### Web.Resource 🔒 -Configeration related to static resources your application uses: -``` +```toml [web.resource] -# configuration ``` -1. ***style*** - The styles (`.css` files) to include in your application - ``` +Static resource configuration. + +1. **style** - CSS files to include in your application. + ```toml style = [ - # include from public_dir. + # Include from public_dir. "./assets/style.css", - # or some asset from online cdn. + # Or some asset from online cdn. "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" ] ``` -2. ***script*** - The additional scripts (`.js` files) to include in your application - ``` - style = [ - # include from public_dir. - "./assets/index.js", - # or some asset from online cdn. + +2. **script** - JavaScript files to include in your application. + ```toml + script = [ + # Include from asset_dir. + "./public/index.js", + # Or from an online CDN. "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" ] ``` -### Web.Resource.Dev ✍ +### Web.Resource.Dev 🔒 -Configeration related to static resources your application uses in development: -``` +```toml [web.resource.dev] -# configuration ``` -1. ***style*** - The styles (`.css` files) to include in your application - ``` - style = [ - # include from public_dir. - "./assets/style.css", - # or some asset from online cdn. - "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" - ] - ``` -2. ***script*** - The additional scripts (`.js` files) to include in your application - ``` - style = [ - # include from public_dir. - "./assets/index.js", - # or some asset from online cdn. - "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" - ] - ``` +This is the same as [`[web.resource]`](#webresource-), but it only works in development servers. +For example, if you want to include a file in a `dx serve` server, but not a `dx serve --release` server, put it here. ### Web.Proxy -Configeration related to any proxies your application requires durring development. Proxies will forward requests to a new service - -``` +```toml [[web.proxy]] -# configuration ``` -1. ***backend*** - The URL to the server to proxy. The CLI will forward any requests under the backend relative route to the backend instead of returning 404 - ``` +Configuration related to any proxies your application requires during development. Proxies will forward requests to a new service. + +1. **backend** - The URL to the server to proxy. The CLI will forward any requests under the backend relative route to the backend instead of returning 404 + ```toml backend = "http://localhost:8000/api/" ``` - This will cause any requests made to the dev server with prefix /api/ to be redirected to the backend server at http://localhost:8000. The path and query parameters will be passed on as-is (path rewriting is not currently supported). + This will cause any requests made to the dev server with prefix /api/ to be redirected to the backend server at http://localhost:8000. The path and query parameters will be passed on as-is (path rewriting is currently not supported). ## Config example +This includes all fields, mandatory or not. + ```toml [application] -# App (Project) Name -name = "{{project-name}}" +# App name +name = "project_name" # The Dioxus platform to default to default_platform = "web" @@ -168,23 +157,23 @@ default_platform = "web" # `build` & `serve` output path out_dir = "dist" -# the static resource path +# The static resource path asset_dir = "public" [web.app] # HTML title tag content -title = "dioxus | ⛺" +title = "project_name" [web.watcher] -# when watcher is triggered, regenerate the `index.html` +# When watcher is triggered, regenerate the `index.html` reload_html = true -# which files or dirs will be monitored +# Which files or dirs will be monitored watch_path = ["src", "public"] -# include `assets` in web platform +# Include style or script assets [web.resource] # CSS style file @@ -195,12 +184,12 @@ script = [] [web.resource.dev] -# serve: [dev-server] only +# Same as [web.resource], but for development servers # CSS style file style = [] -# Javascript code file +# JavaScript files script = [] [[web.proxy]] diff --git a/packages/cli/docs/src/creating.md b/packages/cli/docs/src/creating.md index 6c2d5754c..4c594dfd8 100644 --- a/packages/cli/docs/src/creating.md +++ b/packages/cli/docs/src/creating.md @@ -1,39 +1,37 @@ # Create a Project -Once you have the Dioxus CLI tool installed, you can use it to create dioxus project. +Once you have the Dioxus CLI installed, you can use it to create your own project! ## Initializing a default project -First, run the `dx create` command to create a new project ready to be used with Dioxus and the Dioxus CLI: - +First, run the `dx create` command to create a new project: ``` dx create hello-dioxus ``` -> It will clone a default template from github template: [DioxusLabs/dioxus-template](https://github.com/DioxusLabs/dioxus-template) -> This default template is use for `web` platform application. +> It will clone this [template](https://github.com/DioxusLabs/dioxus-template). +> This default template is used for `web` platform application. > > You can choose to create your project from a different template by passing the `template` argument: > ``` > dx init hello-dioxus --template=gh:dioxuslabs/dioxus-template > ``` -Next, move the current directory into your new project: +Next, navigate into your new project: ``` cd hello-dioxus ``` -> Make sure `wasm32 target` is installed before running the Web project. -> You can install the wasm target for rust using rustup: +> Make sure the WASM target is installed before running the projects. +> You can install the WASM target for rust using rustup: > ``` > rustup target add wasm32-unknown-unknown > ``` -Finally, create serve your project with the Dioxus CLI: - +Finally, serve your project: ``` dx serve ``` -By default, the CLI serve your site at: [`http://127.0.0.1:8080/`](http://127.0.0.1:8080/) +By default, the CLI serves your website at [`http://127.0.0.1:8080/`](http://127.0.0.1:8080/). diff --git a/packages/cli/docs/src/installation.md b/packages/cli/docs/src/installation.md index b4326d296..5030170f4 100644 --- a/packages/cli/docs/src/installation.md +++ b/packages/cli/docs/src/installation.md @@ -1,22 +1,23 @@ # Installation -Choose any one of the methods below to install the Dioxus CLI: +## Install the latest development build through git -## Install from latest git version - -To get the most up to date bug fixes and features of the Dioxus CLI, you can install the development version from git. +To get the latest bug fixes and features, you can install the development version from git. ``` cargo install --git https://github.com/Dioxuslabs/cli ``` -This will automatically download `Dioxus-CLI` source from github master branch, +This will download `Dioxus-CLI` source from GitHub master branch, and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). -## Install from `crates.io` version +## Install stable through `crates.io` -The published version of the Dioxus CLI is updated less often, but should be more stable than the git version of the Dioxus CLI. +The published version of the Dioxus CLI is updated less often, but is more stable than the git version. ``` cargo install dioxus-cli ``` + +Run `dx --help` for a list of all the available commands. +Furthermore, you can run `dx --help` to get help with a specific command. \ No newline at end of file diff --git a/packages/cli/docs/src/introduction.md b/packages/cli/docs/src/introduction.md index 2f857a2a5..8b10b0546 100644 --- a/packages/cli/docs/src/introduction.md +++ b/packages/cli/docs/src/introduction.md @@ -1,21 +1,18 @@ # Introduction -📦✨ **Dioxus-Cli** is a tool to help get dioxus projects off the ground. - -![dioxus-logo](https://dioxuslabs.com/guide/images/dioxuslogo_full.png) - -It includes `dev server`, `hot reload` and some `quick command` to help you use dioxus. +The 📦✨ **Dioxus CLI** is a tool to help get Dioxus projects off the ground. ## Features +* Build and pack a Dioxus project +* `html` to `rsx` conversion tool +* Hot Reload for `web` platform +* Create a Dioxus project from `git` repo +* And more! + \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/README.md b/packages/cli/docs/src/plugin/README.md index 0a1a7b606..fe7375618 100644 --- a/packages/cli/docs/src/plugin/README.md +++ b/packages/cli/docs/src/plugin/README.md @@ -1,24 +1,85 @@ -# CLI Plugin Development +# CLI Plugin development -> For Cli 0.2.0 we will add `plugin-develop` support. +**IMPORTANT: Ignore this documentation. Plugins are yet to be released and chances are it won't work for you. This is just what plugins *could* look like.** -Before the 0.2.0 we use `dx tool` to use & install some plugin, but we think that is not good for extend cli program, some people want tailwind support, some people want sass support, we can't add all this thing in to the cli source code and we don't have time to maintain a lot of tools that user request, so maybe user make plugin by themself is a good choice. +In the past we used `dx tool` to use and install tools, but it was a flawed system. +Tools were hard-coded by us, but people want more tools than we could code, so this plugin system was made to let +anyone develop plugins and use them in Dioxus projects. -### Why Lua ? +Plugin resources: +* [Source code](https://github.com/DioxusLabs/dioxus/tree/master/packages/cli/src/plugin) +* [Unofficial Dioxus plugin community](https://github.com/DioxusPluginCommunity). Contains certain plugins you can use right now. -We choose `Lua: 5.4` to be the plugin develop language, because cli plugin is not complex, just like a workflow, and user & developer can write some easy code for their plugin. We have **vendored** lua in cli program, and user don't need install lua runtime in their computer, and the lua parser & runtime doesn't take up much disk memory. +### Why Lua? -### Event Management +We chose Lua `5.4` to be the plugin developing language, +because it's extremely lightweight, embeddable and easy to learn. +We installed Lua into the CLI, so you don't need to do it yourself. -The plugin library have pre-define some important event you can control: +Lua resources: +* [Official website](https://www.lua.org/). You can basically find everything here. +* [Awesome Lua](https://github.com/LewisJEllis/awesome-lua). Additional resources (such as Lua plugins for your favorite IDE), and other *awesome* tools! -- `build.on_start` -- `build.on_finished` -- `serve.on_start` -- `serve.on_rebuild` -- `serve.on_shutdown` -### Plugin Template +## Creating a plugin + +A plugin is just an `init.lua` file. +You can include other files using `dofile(path)`. +You need to have a plugin and a manager instance, which you can get using `require`: +```lua +local plugin = require("plugin") +local manager = require("manager") +``` + +You need to set some `manager` fields and then initialize the plugin: +```lua +manager.name = "My first plugin" +manager.repository = "https://github.com/john-doe/my-first-plugin" -- The repository URL. +manager.author = "John Doe " +manager.version = "0.1.0" +plugin.init(manager) +``` + +You also need to return the `manager`, which basically represents your plugin: +```lua +-- Your code here. +-- End of file. + +manager.serve.interval = 1000 +return manager +``` + +And you're ready to go. Now, go and have a look at the stuff below and the API documentation. + +### Plugin info + +You will encounter this type in the events below. The keys are as follows: +* `name: string` - The name of the plugin. +* `repository: string` - The plugin repository URL. +* `author: string` - The author of the plugin. +* `version: string` - The plugin version. + +### Event management + +The plugin library has certain events that you can subscribe to. + +* `manager.on_init` - Triggers the first time the plugin is loaded. +* `manager.build.on_start(info)` - Triggers before the build process. E.g., before `dx build`. +* `manager.build.on_finish(info)` - Triggers after the build process. E.g., after `dx build`. +* `manager.serve.on_start(info)` - Triggers before the serving process. E.g., before `dx serve`. +* `manager.serve.on_rebuild_start(info)` - Triggers before the server rebuilds the web with hot reload. +* `manager.serve.on_rebuild_end(info)` - Triggers after the server rebuilds the web with hot reload. +* `manager.serve.on_shutdown` - Triggers when the server is shutdown. E.g., when the `dx serve` process is terminated. + +To subscribe to an event, you simply need to assign it to a function: + +```lua +manager.build.on_start = function (info) + log.info("[plugin] Build starting: " .. info.name) +end +``` + +### Plugin template ```lua package.path = library_dir .. "/?.lua" diff --git a/packages/cli/docs/src/plugin/interface/command.md b/packages/cli/docs/src/plugin/interface/command.md index 18cd32769..2882e5153 100644 --- a/packages/cli/docs/src/plugin/interface/command.md +++ b/packages/cli/docs/src/plugin/interface/command.md @@ -1,15 +1,15 @@ # Command Functions -> you can use command functions to execute some code & script +You can use command functions to execute code and scripts. -Type Define: +Type definition: ``` Stdio: "Inherit" | "Piped" | "Null" ``` ### `exec(commands: [string], stdout: Stdio, stderr: Stdio)` -you can use this function to run some command on the current system. +You can use this function to run some commands on the current system. ```lua local cmd = plugin.command @@ -18,4 +18,4 @@ manager.test = function () cmd.exec({"git", "clone", "https://github.com/DioxusLabs/cli-plugin-library"}) end ``` -> Warning: This function don't have exception catch. \ No newline at end of file +> Warning: This function doesn't catch exceptions. \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/dirs.md b/packages/cli/docs/src/plugin/interface/dirs.md index 4173c922f..9984802ff 100644 --- a/packages/cli/docs/src/plugin/interface/dirs.md +++ b/packages/cli/docs/src/plugin/interface/dirs.md @@ -1,33 +1,28 @@ # Dirs Functions -> you can use Dirs functions to get some directory path +Dirs functions are for getting various directory paths. Not to be confused with `plugin.path`. +### `plugin_dir() -> string` -### plugin_dir() -> string - -You can get current plugin **root** directory path +Get the plugin's root directory path. ```lua local path = plugin.dirs.plugin_dir() -- example: ~/Development/DioxusCli/plugin/test-plugin/ ``` -### bin_dir() -> string +### `bin_dir() -> string` -You can get plugin **bin** direcotry path - -Sometime you need install some binary file like `tailwind-cli` & `sass-cli` to help your plugin work, then you should put binary file in this directory. +Get the plugin's binary directory path. Put binary files like `tailwind-cli` or `sass-cli` in this directory. ```lua local path = plugin.dirs.bin_dir() -- example: ~/Development/DioxusCli/plugin/test-plugin/bin/ ``` -### temp_dir() -> string +### `temp_dir() -> string` -You can get plugin **temp** direcotry path - -Just put some temporary file in this directory. +Get the plugin's temporary directory path. Put any temporary files here. ```lua local path = plugin.dirs.bin_dir() diff --git a/packages/cli/docs/src/plugin/interface/log.md b/packages/cli/docs/src/plugin/interface/log.md index fcd72595b..ee437b77a 100644 --- a/packages/cli/docs/src/plugin/interface/log.md +++ b/packages/cli/docs/src/plugin/interface/log.md @@ -1,46 +1,46 @@ # Log Functions -> You can use log function to print some useful log info +You can use log functions to print various logging information. -### Trace(info: string) +### `trace(info: string)` -Print trace log info +Print trace log info. ```lua local log = plugin.log log.trace("trace information") ``` -### Debug(info: string) +### `debug(info: string)` -Print debug log info +Print debug log info. ```lua local log = plugin.log log.debug("debug information") ``` -### Info(info: string) +### `info(info: string)` -Print info log info +Print info log info. ```lua local log = plugin.log log.info("info information") ``` -### Warn(info: string) +### `warn(info: string)` -Print warning log info +Print warning log info. ```lua local log = plugin.log log.warn("warn information") ``` -### Error(info: string) +### `error(info: string)` -Print error log info +Print error log info. ```lua local log = plugin.log diff --git a/packages/cli/docs/src/plugin/interface/network.md b/packages/cli/docs/src/plugin/interface/network.md index 358c9c498..566bc5073 100644 --- a/packages/cli/docs/src/plugin/interface/network.md +++ b/packages/cli/docs/src/plugin/interface/network.md @@ -1,12 +1,13 @@ # Network Functions -> you can use Network functions to download & read some data from internet +You can use Network functions to download & read some data from the internet. -### download_file(url: string, path: string) -> boolean +### `download_file(url: string, path: string) -> boolean` -This function can help you download some file from url, and it will return a *boolean* value to check the download status. (true: success | false: fail) +Downloads a file from the specified URL, +and returns a `boolean` that represents the download status (true: success, false: failure). -You need pass a target url and a local path (where you want to save this file) +You need to pass a target URL and a local path (where you want to save this file). ```lua -- this file will download to plugin temp directory @@ -19,9 +20,11 @@ if status != true then end ``` -### clone_repo(url: string, path: string) -> boolean +### `clone_repo(url: string, path: string) -> boolean` -This function can help you use `git clone` command (this system must have been installed git) +Clone a repository from the given URL into the given path. +Returns a `boolean` that represents the clone status (true: success, false: failure). +The system executing this function must have git installed. ```lua local status = plugin.network.clone_repo( diff --git a/packages/cli/docs/src/plugin/interface/os.md b/packages/cli/docs/src/plugin/interface/os.md index 72a17c336..84f4697b8 100644 --- a/packages/cli/docs/src/plugin/interface/os.md +++ b/packages/cli/docs/src/plugin/interface/os.md @@ -1,10 +1,10 @@ # OS Functions -> you can use OS functions to get some system information +OS functions are for getting system information. -### current_platform() -> string ("windows" | "macos" | "linux") +### `current_platform() -> string ("windows" | "macos" | "linux")` -This function can help you get system & platform type: +Get the current OS platform. ```lua local platform = plugin.os.current_platform() diff --git a/packages/cli/docs/src/plugin/interface/path.md b/packages/cli/docs/src/plugin/interface/path.md index ee787ecf9..a5bee1eb9 100644 --- a/packages/cli/docs/src/plugin/interface/path.md +++ b/packages/cli/docs/src/plugin/interface/path.md @@ -1,10 +1,13 @@ # Path Functions -> you can use path functions to operate valid path string +You can use path functions to perform operations on valid path strings. -### join(path: string, extra: string) -> string +### `join(path: string, extra: string) -> string` -This function can help you extend a path, you can extend any path, dirname or filename. + +Extend a path; you can extend both directory and file paths. ```lua local current_path = "~/hello/dioxus" @@ -12,9 +15,9 @@ local new_path = plugin.path.join(current_path, "world") -- new_path = "~/hello/dioxus/world" ``` -### parent(path: string) -> string +### `parent(path: string) -> string` -This function will return `path` parent-path string, back to the parent. +Return the parent path of the specified path. The parent path is always a directory. ```lua local current_path = "~/hello/dioxus" @@ -22,14 +25,14 @@ local new_path = plugin.path.parent(current_path) -- new_path = "~/hello/" ``` -### exists(path: string) -> boolean +### `exists(path: string) -> boolean` -This function can check some path (dir & file) is exists. +Check if the specified path exists, as either a file or a directory. -### is_file(path: string) -> boolean +### `is_file(path: string) -> boolean` -This function can check some path is a exist file. +Check if the specified path is a file. -### is_dir(path: string) -> boolean +### `is_dir(path: string) -> boolean` -This function can check some path is a exist dir. \ No newline at end of file +Check if the specified path is a directory. \ No newline at end of file From 2cfa0e4ea92b769f2f282b8632d56076a87a6b41 Mon Sep 17 00:00:00 2001 From: YuKun Liu Date: Sat, 2 Sep 2023 16:31:34 -0700 Subject: [PATCH 14/15] fix: prettier_build unavailabe (#1410) Co-authored-by: Evan Almloff --- packages/cli/Cargo.toml | 3 +-- packages/cli/src/builder.rs | 12 +++++------- packages/cli/src/cli/build.rs | 2 +- packages/cli/src/server/web/mod.rs | 6 +++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index a37798eee..1d497d84c 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -36,7 +36,7 @@ chrono = "0.4.19" anyhow = "1.0.53" hyper = "0.14.17" hyper-rustls = "0.23.2" -indicatif = "0.17.0-rc.11" +indicatif = "0.17.5" subprocess = "0.2.9" axum = { version = "0.5.1", features = ["ws", "headers"] } @@ -75,7 +75,6 @@ gitignore = "1.0.7" open = "4.1.0" cargo-generate = "0.18" toml_edit = "0.19.11" -# dioxus-rsx = "0.0.1" # bundling tauri-bundler = { version = "1.2", features = ["native-tls-vendored"] } diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 332490fda..7f1b49ace 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -22,7 +22,7 @@ pub struct BuildResult { pub elapsed_time: u128, } -pub fn build(config: &CrateConfig, quiet: bool) -> Result { +pub fn build(config: &CrateConfig) -> Result { // [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?) // [2] Generate the appropriate build folders // [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm @@ -53,7 +53,8 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { .arg("build") .arg("--target") .arg("wasm32-unknown-unknown") - .arg("--message-format=json"); + .arg("--message-format=json") + .arg("--quiet"); let cmd = if config.release { cmd.arg("--release") @@ -66,8 +67,6 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { cmd }; - let cmd = if quiet { cmd.arg("--quiet") } else { cmd }; - let cmd = if config.custom_profile.is_some() { let custom_profile = config.custom_profile.as_ref().unwrap(); cmd.arg("--profile").arg(custom_profile) @@ -386,10 +385,9 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { } } - StopSpinOnDrop(pb.clone()); - let stdout = cmd.detached().stream_stdout()?; let reader = std::io::BufReader::new(stdout); + for message in cargo_metadata::Message::parse_stream(reader) { match message.unwrap() { Message::CompilerMessage(msg) => { @@ -409,7 +407,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { } } Message::CompilerArtifact(artifact) => { - pb.set_message(format!("Compiling {} ", artifact.package_id)); + pb.set_message(format!("⚙️ Compiling {} ", artifact.package_id)); pb.tick(); } Message::BuildScriptExecuted(script) => { diff --git a/packages/cli/src/cli/build.rs b/packages/cli/src/cli/build.rs index 3053a6e5a..d701d2ee8 100644 --- a/packages/cli/src/cli/build.rs +++ b/packages/cli/src/cli/build.rs @@ -42,7 +42,7 @@ impl Build { match platform { Platform::Web => { - crate::builder::build(&crate_config, false)?; + crate::builder::build(&crate_config)?; } Platform::Desktop => { crate::builder::build_desktop(&crate_config, false)?; diff --git a/packages/cli/src/server/web/mod.rs b/packages/cli/src/server/web/mod.rs index 78eddb574..a780598e0 100644 --- a/packages/cli/src/server/web/mod.rs +++ b/packages/cli/src/server/web/mod.rs @@ -73,7 +73,7 @@ pub async fn serve_default( config: CrateConfig, start_browser: bool, ) -> Result<()> { - let first_build_result = crate::builder::build(&config, false)?; + let first_build_result = crate::builder::build(&config)?; log::info!("🚀 Starting development server..."); @@ -134,7 +134,7 @@ pub async fn serve_hot_reload( config: CrateConfig, start_browser: bool, ) -> Result<()> { - let first_build_result = crate::builder::build(&config, false)?; + let first_build_result = crate::builder::build(&config)?; log::info!("🚀 Starting development server..."); @@ -474,7 +474,7 @@ async fn ws_handler( } fn build(config: &CrateConfig, reload_tx: &Sender<()>) -> Result { - let result = builder::build(config, true)?; + let result = builder::build(config)?; // change the websocket reload state to true; // the page will auto-reload. if config From 95887e836c1a3a99f5f1ac4675c2a72e40ef75a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Mon, 4 Sep 2023 14:28:38 +0200 Subject: [PATCH 15/15] fix: Add the --locked param to every cli installation command (#1427) --- docs/guide/src/en/getting_started/web.md | 2 +- examples/PWA-example/README.md | 11 ++++++----- packages/cli/README.md | 4 +++- packages/cli/docs/src/installation.md | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/guide/src/en/getting_started/web.md b/docs/guide/src/en/getting_started/web.md index 48818bf8f..07139cce6 100644 --- a/docs/guide/src/en/getting_started/web.md +++ b/docs/guide/src/en/getting_started/web.md @@ -25,7 +25,7 @@ The Web is the best-supported target platform for Dioxus. To develop your Dioxus app for the web, you'll need a tool to build and serve your assets. We recommend using [dioxus-cli](https://github.com/DioxusLabs/dioxus/tree/master/packages/cli) which includes a build system, Wasm optimization, a dev server, and support hot reloading: ```shell -cargo install dioxus-cli +cargo install dioxus-cli --locked ``` Make sure the `wasm32-unknown-unknown` target for rust is installed: diff --git a/examples/PWA-example/README.md b/examples/PWA-example/README.md index d42a61311..d501df212 100644 --- a/examples/PWA-example/README.md +++ b/examples/PWA-example/README.md @@ -7,12 +7,13 @@ It is also very much usable as a template for your projects, if you're aiming to ## Try the example -Make sure you have Dioxus CLI installed (if you're unsure, run `cargo install dioxus-cli`). +Make sure you have Dioxus CLI installed (if you're unsure, run `cargo install dioxus-cli --locked`). You can run `dx serve` in this directory to start the web server locally, or run `dx build --release` to build the project so you can deploy it on a separate web-server. ## Project Structure + ``` ├── Cargo.toml ├── Dioxus.toml @@ -33,12 +34,12 @@ You can run `dx serve` in this directory to start the web server locally, or run If you're just getting started with PWAs, here are some useful resources: -* [PWABuilder docs](https://docs.pwabuilder.com/#/) -* [MDN article on PWAs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) +- [PWABuilder docs](https://docs.pwabuilder.com/#/) +- [MDN article on PWAs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) For service worker scripting (in JavaScript): -* [Service worker guide from PWABuilder](https://docs.pwabuilder.com/#/home/sw-intro) -* [Service worker examples, also from PWABuilder](https://github.com/pwa-builder/pwabuilder-serviceworkers) +- [Service worker guide from PWABuilder](https://docs.pwabuilder.com/#/home/sw-intro) +- [Service worker examples, also from PWABuilder](https://github.com/pwa-builder/pwabuilder-serviceworkers) If you want to stay as close to 100% Rust as possible, you can try using [wasi-worker](https://github.com/dunnock/wasi-worker) to replace the JS service worker file. The JSON manifest will still be required though. diff --git a/packages/cli/README.md b/packages/cli/README.md index fcd9d25b4..d868b1c9d 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -11,7 +11,7 @@ It handles all building, bundling, development and publishing to simplify develo ### Install the stable version (recommended) ``` -cargo install dioxus-cli +cargo install dioxus-cli --locked ``` ### Install the latest development build through git @@ -28,6 +28,7 @@ This will download the CLI from the master branch, and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). ### Install from local folder + ``` cargo install --path . --debug ``` @@ -52,6 +53,7 @@ You can use the `Dioxus.toml` file for further configuration. Some fields are mandatory, but the CLI tool will tell you which ones are missing. You can create a `Dioxus.toml` with all fields already set using `dx config init project-name`, or you can use this bare-bones template (only mandatory fields) to get started: + ```toml [application] name = "project-name" diff --git a/packages/cli/docs/src/installation.md b/packages/cli/docs/src/installation.md index 5030170f4..22803be61 100644 --- a/packages/cli/docs/src/installation.md +++ b/packages/cli/docs/src/installation.md @@ -16,8 +16,8 @@ and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). The published version of the Dioxus CLI is updated less often, but is more stable than the git version. ``` -cargo install dioxus-cli +cargo install dioxus-cli --locked ``` Run `dx --help` for a list of all the available commands. -Furthermore, you can run `dx --help` to get help with a specific command. \ No newline at end of file +Furthermore, you can run `dx --help` to get help with a specific command.