diff --git a/.github/workflows/cli_release.yml b/.github/workflows/cli_release.yml index c6c2b81e8..4cd33f47e 100644 --- a/.github/workflows/cli_release.yml +++ b/.github/workflows/cli_release.yml @@ -29,7 +29,7 @@ jobs: toolchain: "1.70.0", } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/docs stable.yml b/.github/workflows/docs stable.yml index 069d4308a..642216f0f 100644 --- a/.github/workflows/docs stable.yml +++ b/.github/workflows/docs stable.yml @@ -23,7 +23,7 @@ jobs: - name: Setup mdBook run: | cargo install mdbook --git https://github.com/Demonthos/mdBook.git --branch master - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: cd docs && diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3a452e770..107ad9638 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,7 +28,7 @@ jobs: - name: Setup mdBook run: | cargo install mdbook --git https://github.com/Demonthos/mdBook.git --branch master - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: cd docs && diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04f367b8e..037525557 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,7 +41,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - run: sudo apt-get update - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: cargo check --all --examples --tests test: @@ -56,7 +56,7 @@ jobs: - uses: davidB/rust-cargo-make@v1 - uses: browser-actions/setup-firefox@latest - uses: jetli/wasm-pack-action@v0.4.0 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: cargo make tests fmt: @@ -67,7 +67,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: cargo fmt --all -- --check clippy: @@ -80,7 +80,7 @@ jobs: - run: sudo apt-get update - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev - run: rustup component add clippy - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: cargo clippy --workspace --examples --tests -- -D warnings matrix_test: @@ -124,7 +124,7 @@ jobs: } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install stable uses: dtolnay/rust-toolchain@master @@ -154,7 +154,7 @@ jobs: # options: --security-opt seccomp=unconfined # steps: # - name: Checkout repository - # uses: actions/checkout@v3 + # uses: actions/checkout@v4 # - name: Generate code coverage # run: | # apt-get update &&\ diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index b1d772512..4a467b9b2 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -69,7 +69,7 @@ jobs: if: runner.os == 'Linux' run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Rust ${{ env.rust_nightly }} uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index dba32d257..500d41564 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: # Do our best to cache the toolchain and node install steps - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: 16 diff --git a/Cargo.toml b/Cargo.toml index 54c54ebf1..6378d9983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,8 @@ generational-box = { path = "packages/generational-box" } dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" } dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" } dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" } -log = "0.4.19" +tracing = "0.1.37" +tracing-futures = "0.2.5" tokio = "1.28" slab = "0.4.2" futures-channel = "0.3.21" 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/autofmt/src/collect_macros.rs b/packages/autofmt/src/collect_macros.rs index 10e0d185c..841af1316 100644 --- a/packages/autofmt/src/collect_macros.rs +++ b/packages/autofmt/src/collect_macros.rs @@ -17,7 +17,15 @@ struct MacroCollector<'a, 'b> { impl<'a, 'b> Visit<'b> for MacroCollector<'a, 'b> { fn visit_macro(&mut self, i: &'b Macro) { - self.macros.push(i); + if let Some("rsx" | "render") = i + .path + .segments + .last() + .map(|i| i.ident.to_string()) + .as_deref() + { + self.macros.push(i) + } } } diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index a37798eee..f325430aa 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-cli" -version = { workspace = true } +version = "0.4.1" authors = ["Jonathan Kelley"] edition = "2021" description = "CLI tool for developing, testing, and publishing Dioxus apps" @@ -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,11 +75,10 @@ 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"] } -tauri-utils = "1.3" +tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"] } +tauri-utils = "=1.4.*" dioxus-autofmt = { workspace = true } dioxus-check = { workspace = true } 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..d868b1c9d 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,43 +1,71 @@ -
-

📦✨ 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 +cargo install dioxus-cli --locked ``` -### 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..22803be61 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 +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. 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 diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 332490fda..c4d1bde6f 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -22,6 +22,7 @@ pub struct BuildResult { pub elapsed_time: u128, } +#[allow(unused)] pub fn build(config: &CrateConfig, quiet: bool) -> 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 @@ -53,7 +54,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 +68,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 +386,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 +408,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..7fe29f8ce 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, true)?; } Platform::Desktop => { crate::builder::build_desktop(&crate_config, false)?; diff --git a/packages/cli/src/lib.rs b/packages/cli/src/lib.rs index 2d5f6dfcb..c067ab148 100644 --- a/packages/cli/src/lib.rs +++ b/packages/cli/src/lib.rs @@ -1,4 +1,4 @@ -pub const DIOXUS_CLI_VERSION: &str = "0.1.5"; +pub const DIOXUS_CLI_VERSION: &str = "0.4.1"; pub mod builder; pub mod server; diff --git a/packages/cli/src/server/web/mod.rs b/packages/cli/src/server/web/mod.rs index 78eddb574..bb1c00c99 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, true)?; 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, true)?; log::info!("🚀 Starting development server..."); diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 71afe5825..ce7c6bccf 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -28,7 +28,7 @@ slab = { workspace = true } futures-channel = { workspace = true } smallbox = "0.8.1" -log = { workspace = true } +tracing = { workspace = true } # Serialize the Edits for use in Webview/Liveview instances serde = { version = "1", features = ["derive"], optional = true } diff --git a/packages/core/src/any_props.rs b/packages/core/src/any_props.rs index de403e5c6..f14a78065 100644 --- a/packages/core/src/any_props.rs +++ b/packages/core/src/any_props.rs @@ -68,7 +68,7 @@ unsafe impl<'a, P> AnyProps<'a> for VProps<'a, P> { Ok(None) => RenderReturn::default(), Err(err) => { let component_name = cx.name(); - log::error!("Error while rendering component `{component_name}`: {err:?}"); + tracing::error!("Error while rendering component `{component_name}`: {err:?}"); RenderReturn::default() } } diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 58fceaa48..74017db0f 100644 --- a/packages/core/src/diff.rs +++ b/packages/core/src/diff.rs @@ -196,7 +196,8 @@ impl<'b> VirtualDom { right.scope.set(Some(scope_id)); // copy out the box for both - let old = self.scopes[scope_id.0].props.as_ref(); + let old_scope = &self.scopes[scope_id.0]; + let old = old_scope.props.as_ref(); let new: Box = right.props.take().unwrap(); let new: Box = unsafe { std::mem::transmute(new) }; @@ -204,6 +205,11 @@ impl<'b> VirtualDom { // The target scopestate still has the reference to the old props, so there's no need to update anything // This also implicitly drops the new props since they're not used if left.static_props && unsafe { old.as_ref().unwrap().memoize(new.as_ref()) } { + tracing::trace!( + "Memoized props for component {:#?} ({})", + scope_id, + old_scope.context().name + ); return; } diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index 4778ff4d3..3b8edb05c 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -118,7 +118,7 @@ impl std::fmt::Debug for Event { /// /// ```rust, ignore /// rsx!{ -/// MyComponent { onclick: move |evt| log::info!("clicked") } +/// MyComponent { onclick: move |evt| tracing::debug!("clicked") } /// } /// /// #[derive(Props)] diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 2399c16b8..c83b1059a 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -691,7 +691,7 @@ impl<'a> IntoDynNode<'a> for &Element<'a> { impl<'a, 'b> IntoDynNode<'a> for LazyNodes<'a, 'b> { fn into_vnode(self, cx: &'a ScopeState) -> DynamicNode<'a> { - DynamicNode::Fragment(cx.bump().alloc([self.call(cx)])) + DynamicNode::Fragment(cx.bump().alloc([cx.render(self).unwrap()])) } } @@ -750,7 +750,7 @@ impl<'a> IntoTemplate<'a> for Element<'a> { } impl<'a, 'b> IntoTemplate<'a> for LazyNodes<'a, 'b> { fn into_template(self, cx: &'a ScopeState) -> VNode<'a> { - self.call(cx) + cx.render(self).unwrap() } } diff --git a/packages/core/src/scope_arena.rs b/packages/core/src/scope_arena.rs index 138431740..1ed5b816c 100644 --- a/packages/core/src/scope_arena.rs +++ b/packages/core/src/scope_arena.rs @@ -64,6 +64,7 @@ impl VirtualDom { let props: &dyn AnyProps = scope.props.as_ref().unwrap().as_ref(); let props: &dyn AnyProps = std::mem::transmute(props); + let _span = tracing::trace_span!("render", scope = %scope.context().name); props.render(scope).extend_lifetime() }; diff --git a/packages/core/src/scope_context.rs b/packages/core/src/scope_context.rs index 173f43e18..79ed05d75 100644 --- a/packages/core/src/scope_context.rs +++ b/packages/core/src/scope_context.rs @@ -107,20 +107,30 @@ impl ScopeContext { /// /// Clones the state if it exists. pub fn consume_context(&self) -> Option { + tracing::trace!( + "looking for context {} ({:?}) in {}", + std::any::type_name::(), + std::any::TypeId::of::(), + self.name + ); if let Some(this_ctx) = self.has_context() { return Some(this_ctx); } let mut search_parent = self.parent_id; - with_runtime(|runtime| { + match with_runtime(|runtime: &crate::runtime::Runtime| { while let Some(parent_id) = search_parent { let parent = runtime.get_context(parent_id).unwrap(); - if let Some(shared) = parent - .shared_contexts - .borrow() - .iter() - .find_map(|any| any.downcast_ref::()) - { + tracing::trace!( + "looking for context {} ({:?}) in {}", + std::any::type_name::(), + std::any::TypeId::of::(), + parent.name + ); + if let Some(shared) = parent.shared_contexts.borrow().iter().find_map(|any| { + tracing::trace!("found context {:?}", any.type_id()); + any.downcast_ref::() + }) { return Some(shared.clone()); } search_parent = parent.parent_id; @@ -128,6 +138,17 @@ impl ScopeContext { None }) .flatten() + { + Some(ctx) => Some(ctx), + None => { + tracing::trace!( + "context {} ({:?}) not found", + std::any::type_name::(), + std::any::TypeId::of::() + ); + None + } + } } /// Expose state to children further down the [`crate::VirtualDom`] Tree. Requires `Clone` on the context to allow getting values down the tree. @@ -152,6 +173,12 @@ impl ScopeContext { /// } /// ``` pub fn provide_context(&self, value: T) -> T { + tracing::trace!( + "providing context {} ({:?}) in {}", + std::any::type_name::(), + std::any::TypeId::of::(), + self.name + ); let mut contexts = self.shared_contexts.borrow_mut(); // If the context exists, swap it out for the new value diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index c2e56c776..500b2d888 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -306,6 +306,7 @@ impl VirtualDom { pub fn mark_dirty(&mut self, id: ScopeId) { if let Some(scope) = self.get_scope(id) { let height = scope.height(); + tracing::trace!("Marking scope {:?} ({}) as dirty", id, scope.context().name); self.dirty_scopes.insert(DirtyScope { height, id }); } } @@ -558,7 +559,7 @@ impl VirtualDom { } // If an error occurs, we should try to render the default error component and context where the error occured RenderReturn::Aborted(placeholder) => { - log::info!("Ran into suspended or aborted scope during rebuild"); + tracing::debug!("Ran into suspended or aborted scope during rebuild"); let id = self.next_null(); placeholder.id.set(Some(id)); self.mutations.push(Mutation::CreatePlaceholder { id }); diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index a17b52b1a..eb433d47b 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -18,7 +18,7 @@ dioxus-hot-reload = { workspace = true, optional = true } serde = "1.0.136" serde_json = "1.0.79" thiserror = { workspace = true } -log = { workspace = true } +tracing = { workspace = true } wry = { version = "0.31.0" } futures-channel = { workspace = true } tokio = { workspace = true, features = [ @@ -57,6 +57,8 @@ default = ["tokio_runtime", "hot-reload"] tokio_runtime = ["tokio"] fullscreen = ["wry/fullscreen"] transparent = ["wry/transparent"] +devtools = ["wry/devtools"] +dox = ["wry/dox"] hot-reload = ["dioxus-hot-reload"] [dev-dependencies] diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index d2c29f676..a48068d84 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -191,7 +191,7 @@ impl DesktopService { /// launch print modal pub fn print(&self) { if let Err(e) = self.webview.print() { - log::warn!("Open print modal failed: {e}"); + tracing::warn!("Open print modal failed: {e}"); } } @@ -206,7 +206,7 @@ impl DesktopService { self.webview.open_devtools(); #[cfg(not(debug_assertions))] - log::warn!("Devtools are disabled in release builds"); + tracing::warn!("Devtools are disabled in release builds"); } /// Create a wry event handler that listens for wry events. diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index a96cd5abf..b802dc0ef 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -336,7 +336,7 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) if temp.contains_key("href") { let open = webbrowser::open(temp["href"].as_str().unwrap()); if let Err(e) = open { - log::error!("Open Browser error: {:?}", e); + tracing::error!("Open Browser error: {:?}", e); } } } diff --git a/packages/desktop/src/query.rs b/packages/desktop/src/query.rs index 247f333e8..d38478c61 100644 --- a/packages/desktop/src/query.rs +++ b/packages/desktop/src/query.rs @@ -123,7 +123,7 @@ impl QueryEngine { }}) }})();"# )) { - log::warn!("Query error: {err}"); + tracing::warn!("Query error: {err}"); } Query { diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index ea052230b..72da45013 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -30,7 +30,7 @@ hot-reload = ["dioxus-hot-reload"] [dev-dependencies] futures-util = { workspace = true } -log = { workspace = true } +tracing = { workspace = true } rand = { version = "0.8.4", features = ["small_rng"] } criterion = "0.3.5" thiserror = { workspace = true } diff --git a/packages/fermi/Cargo.toml b/packages/fermi/Cargo.toml index a50a06852..92a0ede71 100644 --- a/packages/fermi/Cargo.toml +++ b/packages/fermi/Cargo.toml @@ -14,7 +14,7 @@ keywords = ["dom", "ui", "gui", "react", "state-management"] [dependencies] dioxus-core = { workspace = true } im-rc = { version = "15.0.0", features = ["serde"] } -log = { workspace = true } +tracing = { workspace = true } [dev-dependencies] closure = "0.3.0" diff --git a/packages/fermi/src/root.rs b/packages/fermi/src/root.rs index f77930c75..67f6514c7 100644 --- a/packages/fermi/src/root.rs +++ b/packages/fermi/src/root.rs @@ -66,14 +66,14 @@ impl AtomRoot { if let Some(slot) = atoms.get_mut(&ptr) { slot.value = Rc::new(value); - log::trace!("found item with subscribers {:?}", slot.subscribers); + tracing::trace!("found item with subscribers {:?}", slot.subscribers); for scope in &slot.subscribers { - log::trace!("updating subcsriber"); + tracing::trace!("updating subcsriber"); (self.update_any)(*scope); } } else { - log::trace!("no atoms found for {:?}", ptr); + tracing::trace!("no atoms found for {:?}", ptr); atoms.insert( ptr, Slot { @@ -96,7 +96,7 @@ impl AtomRoot { pub fn force_update(&self, ptr: AtomId) { if let Some(slot) = self.atoms.borrow_mut().get(&ptr) { for scope in slot.subscribers.iter() { - log::trace!("updating subcsriber"); + tracing::trace!("updating subcsriber"); (self.update_any)(*scope); } } diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index 82ed7c8d7..8ab213e78 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -44,7 +44,8 @@ dioxus-desktop = { workspace = true, optional = true } # Router Integration dioxus-router = { workspace = true, optional = true } -log = { workspace = true } +tracing = { workspace = true } +tracing-futures = { workspace = true } once_cell = "1.17.1" thiserror = { workspace = true } tokio = { workspace = true, features = ["full"], optional = true } diff --git a/packages/fullstack/examples/axum-hello-world/Cargo.toml b/packages/fullstack/examples/axum-hello-world/Cargo.toml index 2073e4655..a3b68b05a 100644 --- a/packages/fullstack/examples/axum-hello-world/Cargo.toml +++ b/packages/fullstack/examples/axum-hello-world/Cargo.toml @@ -12,8 +12,9 @@ dioxus-fullstack = { workspace = true } axum = { version = "0.6.12", optional = true } serde = "1.0.159" simple_logger = "4.2.0" -wasm-logger = "0.2.0" -log.workspace = true +tracing-wasm = "0.2.1" +tracing.workspace = true +tracing-subscriber = "0.3.17" reqwest = "0.11.18" [features] diff --git a/packages/fullstack/examples/axum-hello-world/src/main.rs b/packages/fullstack/examples/axum-hello-world/src/main.rs index 985a5a717..8f1d3c8c6 100644 --- a/packages/fullstack/examples/axum-hello-world/src/main.rs +++ b/packages/fullstack/examples/axum-hello-world/src/main.rs @@ -12,7 +12,6 @@ use dioxus_fullstack::{ prelude::*, }; use serde::{Deserialize, Serialize}; -use wasm_logger::Config; #[derive(Props, PartialEq, Debug, Default, Serialize, Deserialize, Clone)] struct AppProps { @@ -66,9 +65,9 @@ async fn get_server_data() -> Result { fn main() { #[cfg(feature = "web")] - wasm_logger::init(wasm_logger::Config::new(log::Level::Trace)); + tracing_wasm::set_as_global_default(); #[cfg(feature = "ssr")] - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt::init(); LaunchBuilder::new_with_props(app, AppProps { count: 0 }).launch() } diff --git a/packages/fullstack/examples/salvo-hello-world/Cargo.toml b/packages/fullstack/examples/salvo-hello-world/Cargo.toml index 977ad7843..ca0d85ecf 100644 --- a/packages/fullstack/examples/salvo-hello-world/Cargo.toml +++ b/packages/fullstack/examples/salvo-hello-world/Cargo.toml @@ -16,8 +16,9 @@ salvo = { version = "0.37.9", optional = true } execute = "0.2.12" reqwest = "0.11.18" simple_logger = "4.2.0" -log.workspace = true -wasm-logger = "0.2.0" +tracing-wasm = "0.2.1" +tracing.workspace = true +tracing-subscriber = "0.3.17" [features] default = [] diff --git a/packages/fullstack/examples/salvo-hello-world/src/main.rs b/packages/fullstack/examples/salvo-hello-world/src/main.rs index df119b4dd..838ee6f2c 100644 --- a/packages/fullstack/examples/salvo-hello-world/src/main.rs +++ b/packages/fullstack/examples/salvo-hello-world/src/main.rs @@ -60,9 +60,9 @@ async fn get_server_data() -> Result { fn main() { #[cfg(feature = "web")] - wasm_logger::init(wasm_logger::Config::new(log::Level::Trace)); + tracing_wasm::set_as_global_default(); #[cfg(feature = "ssr")] - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt::init(); LaunchBuilder::new_with_props(app, AppProps { count: 0 }).launch() } diff --git a/packages/fullstack/examples/warp-hello-world/Cargo.toml b/packages/fullstack/examples/warp-hello-world/Cargo.toml index d9e82b4c4..1474facf3 100644 --- a/packages/fullstack/examples/warp-hello-world/Cargo.toml +++ b/packages/fullstack/examples/warp-hello-world/Cargo.toml @@ -16,8 +16,9 @@ warp = { version = "0.3.3", optional = true } execute = "0.2.12" reqwest = "0.11.18" simple_logger = "4.2.0" -log.workspace = true -wasm-logger = "0.2.0" +tracing-wasm = "0.2.1" +tracing.workspace = true +tracing-subscriber = "0.3.17" [features] default = [] diff --git a/packages/fullstack/examples/warp-hello-world/src/main.rs b/packages/fullstack/examples/warp-hello-world/src/main.rs index df119b4dd..838ee6f2c 100644 --- a/packages/fullstack/examples/warp-hello-world/src/main.rs +++ b/packages/fullstack/examples/warp-hello-world/src/main.rs @@ -60,9 +60,9 @@ async fn get_server_data() -> Result { fn main() { #[cfg(feature = "web")] - wasm_logger::init(wasm_logger::Config::new(log::Level::Trace)); + tracing_wasm::set_as_global_default(); #[cfg(feature = "ssr")] - simple_logger::SimpleLogger::new().init().unwrap(); + tracing_subscriber::fmt::init(); LaunchBuilder::new_with_props(app, AppProps { count: 0 }).launch() } diff --git a/packages/fullstack/src/adapters/axum_adapter.rs b/packages/fullstack/src/adapters/axum_adapter.rs index 330d15bc3..f7bc4dfe1 100644 --- a/packages/fullstack/src/adapters/axum_adapter.rs +++ b/packages/fullstack/src/adapters/axum_adapter.rs @@ -389,7 +389,7 @@ pub async fn render_handler response } Err(e) => { - log::error!("Failed to render page: {}", e); + tracing::error!("Failed to render page: {}", e); report_err(e).into_response() } } diff --git a/packages/fullstack/src/adapters/salvo_adapter.rs b/packages/fullstack/src/adapters/salvo_adapter.rs index 671128b65..674722665 100644 --- a/packages/fullstack/src/adapters/salvo_adapter.rs +++ b/packages/fullstack/src/adapters/salvo_adapter.rs @@ -423,7 +423,7 @@ impl Handler for SSRHandler freshness.write(res.headers_mut()); } Err(err) => { - log::error!("Error rendering SSR: {}", err); + tracing::error!("Error rendering SSR: {}", err); res.write_body("Error rendering SSR").unwrap(); } }; diff --git a/packages/fullstack/src/adapters/warp_adapter.rs b/packages/fullstack/src/adapters/warp_adapter.rs index 723314ca3..e5239c01a 100644 --- a/packages/fullstack/src/adapters/warp_adapter.rs +++ b/packages/fullstack/src/adapters/warp_adapter.rs @@ -84,7 +84,7 @@ use warp::{ /// async move { /// let req = warp::hyper::Request::from_parts(parts, bytes.into()); /// service.run(req).await.map_err(|err| { -/// log::error!("Server function error: {}", err); +/// tracing::error!("Server function error: {}", err); /// warp::reject::reject() /// }) /// } @@ -142,7 +142,7 @@ pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl R async move { let req = warp::hyper::Request::from_parts(parts, bytes.into()); service.run(req).await.map_err(|err| { - log::error!("Server function error: {}", err); + tracing::error!("Server function error: {}", err); warp::reject::reject() }) } @@ -222,7 +222,7 @@ pub fn render_ssr( res } Err(err) => { - log::error!("Failed to render ssr: {}", err); + tracing::error!("Failed to render ssr: {}", err); Response::builder() .status(500) .body("Failed to render ssr".into()) diff --git a/packages/fullstack/src/hooks/server_cached.rs b/packages/fullstack/src/hooks/server_cached.rs index 80bb93008..519f70dae 100644 --- a/packages/fullstack/src/hooks/server_cached.rs +++ b/packages/fullstack/src/hooks/server_cached.rs @@ -23,7 +23,7 @@ pub fn server_cached(server_fn: impl let data = server_fn(); let sc = crate::prelude::server_context(); if let Err(err) = sc.push_html_data(&data) { - log::error!("Failed to push HTML data: {}", err); + tracing::error!("Failed to push HTML data: {}", err); } data } diff --git a/packages/fullstack/src/hooks/server_future.rs b/packages/fullstack/src/hooks/server_future.rs index 9a13df235..e4d89480e 100644 --- a/packages/fullstack/src/hooks/server_future.rs +++ b/packages/fullstack/src/hooks/server_future.rs @@ -47,13 +47,13 @@ where if first_run { match crate::html_storage::deserialize::take_server_data() { Some(data) => { - log::trace!("Loaded {data:?} from server"); + tracing::trace!("Loaded {data:?} from server"); *state.value.borrow_mut() = Some(Box::new(data)); state.needs_regen.set(false); return Some(state); } None => { - log::trace!("Failed to load from server... running future"); + tracing::trace!("Failed to load from server... running future"); } }; } @@ -82,7 +82,7 @@ where data = fut.await; if first_run { if let Err(err) = crate::prelude::server_context().push_html_data(&data) { - log::error!("Failed to push HTML data: {}", err); + tracing::error!("Failed to push HTML data: {}", err); }; } } @@ -99,7 +99,7 @@ where if first_run { #[cfg(feature = "ssr")] { - log::trace!("Suspending first run of use_server_future"); + tracing::trace!("Suspending first run of use_server_future"); cx.suspend(); } None diff --git a/packages/fullstack/src/hot_reload.rs b/packages/fullstack/src/hot_reload.rs index b94df4811..87f219df8 100644 --- a/packages/fullstack/src/hot_reload.rs +++ b/packages/fullstack/src/hot_reload.rs @@ -30,7 +30,7 @@ impl Default for HotReloadState { } if let Err(err) = tx.send(Some(template)) { - log::error!("Failed to send hot reload message: {}", err); + tracing::error!("Failed to send hot reload message: {}", err); } } dioxus_hot_reload::HotReloadMsg::Shutdown => { diff --git a/packages/fullstack/src/html_storage/deserialize.rs b/packages/fullstack/src/html_storage/deserialize.rs index 822b45076..7fc70ba6c 100644 --- a/packages/fullstack/src/html_storage/deserialize.rs +++ b/packages/fullstack/src/html_storage/deserialize.rs @@ -10,7 +10,7 @@ pub(crate) fn serde_from_bytes(string: &[u8]) -> Option let decompressed = match STANDARD.decode(string) { Ok(bytes) => bytes, Err(err) => { - log::error!("Failed to decode base64: {}", err); + tracing::error!("Failed to decode base64: {}", err); return None; } }; @@ -18,7 +18,7 @@ pub(crate) fn serde_from_bytes(string: &[u8]) -> Option match postcard::from_bytes(&decompressed) { Ok(data) => Some(data), Err(err) => { - log::error!("Failed to deserialize: {}", err); + tracing::error!("Failed to deserialize: {}", err); None } } @@ -32,14 +32,14 @@ static SERVER_DATA: once_cell::sync::Lazy> = let element = match window.get_element_by_id("dioxus-storage-data") { Some(element) => element, None => { - log::error!("Failed to get element by id: dioxus-storage-data"); + tracing::error!("Failed to get element by id: dioxus-storage-data"); return None; } }; let attribute = match element.get_attribute("data-serialized") { Some(attribute) => attribute, None => { - log::error!("Failed to get attribute: data-serialized"); + tracing::error!("Failed to get attribute: data-serialized"); return None; } }; diff --git a/packages/fullstack/src/html_storage/mod.rs b/packages/fullstack/src/html_storage/mod.rs index 2d64953ae..5b4d2804f 100644 --- a/packages/fullstack/src/html_storage/mod.rs +++ b/packages/fullstack/src/html_storage/mod.rs @@ -36,7 +36,7 @@ impl HTMLDataCursor { pub fn take(&self) -> Option { let current = self.index.load(std::sync::atomic::Ordering::SeqCst); if current >= self.data.len() { - log::error!( + tracing::error!( "Tried to take more data than was available, len: {}, index: {}", self.data.len(), current @@ -48,7 +48,7 @@ impl HTMLDataCursor { match postcard::from_bytes(cursor) { Ok(x) => Some(x), Err(e) => { - log::error!("Error deserializing data: {:?}", e); + tracing::error!("Error deserializing data: {:?}", e); None } } diff --git a/packages/fullstack/src/layer.rs b/packages/fullstack/src/layer.rs index cf5633db2..10e67b3f5 100644 --- a/packages/fullstack/src/layer.rs +++ b/packages/fullstack/src/layer.rs @@ -1,4 +1,5 @@ use std::pin::Pin; +use tracing_futures::Instrument; use http::{Request, Response}; @@ -45,7 +46,11 @@ where > + Send, >, > { - let fut = self.call(req); + let fut = self.call(req).instrument(tracing::trace_span!( + "service", + "{}", + std::any::type_name::() + )); Box::pin(async move { fut.await.map_err(|err| err.into()) }) } } diff --git a/packages/fullstack/src/render.rs b/packages/fullstack/src/render.rs index d389fa54e..cda41f82c 100644 --- a/packages/fullstack/src/render.rs +++ b/packages/fullstack/src/render.rs @@ -50,10 +50,10 @@ impl SsrRendererPool { let prev_context = SERVER_CONTEXT.with(|ctx| ctx.replace(server_context)); // poll the future, which may call server_context() - log::info!("Rebuilding vdom"); + tracing::info!("Rebuilding vdom"); let _ = vdom.rebuild(); vdom.wait_for_suspense().await; - log::info!("Suspense resolved"); + tracing::info!("Suspense resolved"); // after polling the future, we need to restore the context SERVER_CONTEXT.with(|ctx| ctx.replace(prev_context)); @@ -116,10 +116,10 @@ impl SsrRendererPool { let prev_context = SERVER_CONTEXT .with(|ctx| ctx.replace(Box::new(server_context))); // poll the future, which may call server_context() - log::info!("Rebuilding vdom"); + tracing::info!("Rebuilding vdom"); let _ = vdom.rebuild(); vdom.wait_for_suspense().await; - log::info!("Suspense resolved"); + tracing::info!("Suspense resolved"); // after polling the future, we need to restore the context SERVER_CONTEXT.with(|ctx| ctx.replace(prev_context)); }) diff --git a/packages/fullstack/src/router.rs b/packages/fullstack/src/router.rs index eee282c01..b556aa000 100644 --- a/packages/fullstack/src/router.rs +++ b/packages/fullstack/src/router.rs @@ -29,7 +29,7 @@ where .to_string() .parse() .unwrap_or_else(|err| { - log::error!("Failed to parse uri: {}", err); + tracing::error!("Failed to parse uri: {}", err); "/" .parse() .unwrap_or_else(|err| { diff --git a/packages/hooks/Cargo.toml b/packages/hooks/Cargo.toml index caa25cb1e..bf07389ff 100644 --- a/packages/hooks/Cargo.toml +++ b/packages/hooks/Cargo.toml @@ -16,7 +16,7 @@ nightly-features = [] [dependencies] dioxus-core = { workspace = true } futures-channel = { workspace = true } -log = { workspace = true } +tracing = { workspace = true } thiserror = { workspace = true } slab = { workspace = true } dioxus-debug-cell = "0.1.1" 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 diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index b900b9dc6..18ce1e5f1 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -81,10 +81,12 @@ pub(crate) struct ProvidedStateInner { value: T, notify_any: Arc, consumers: HashSet, + gen: usize, } impl ProvidedStateInner { pub(crate) fn notify_consumers(&mut self) { + self.gen += 1; for consumer in self.consumers.iter() { (self.notify_any)(*consumer); } @@ -157,7 +159,7 @@ impl ProvidedStateInner { /// /// Right now, there is not a distinction between read-only and write-only, so every consumer will be notified. pub fn use_shared_state(cx: &ScopeState) -> Option<&UseSharedState> { - let state: &Option> = &*cx.use_hook(move || { + let state_owner: &mut Option> = &mut *cx.use_hook(move || { let scope_id = cx.scope_id(); let root = cx.consume_context::>()?; @@ -167,7 +169,10 @@ pub fn use_shared_state(cx: &ScopeState) -> Option<&UseSharedState Drop for UseSharedStateOwner { /// State that is shared between components through the context system pub struct UseSharedState { pub(crate) inner: Rc>>, + gen: usize, } impl UseSharedState { fn new(inner: Rc>>) -> Self { - Self { inner } + let gen = inner.borrow().gen; + Self { inner, gen } } /// Notify all consumers of the state that it has changed. (This is called automatically when you call "write") @@ -302,15 +309,14 @@ impl Clone for UseSharedState { fn clone(&self) -> Self { Self { inner: self.inner.clone(), + gen: self.gen, } } } -impl PartialEq for UseSharedState { +impl PartialEq for UseSharedState { fn eq(&self, other: &Self) -> bool { - let first = self.inner.borrow(); - let second = other.inner.borrow(); - first.value == second.value + self.gen == other.gen } } @@ -360,6 +366,7 @@ pub fn use_shared_state_provider(cx: &ScopeState, f: impl FnOnce() - value: f(), notify_any: cx.schedule_update_any(), consumers: HashSet::new(), + gen: 0, })); cx.provide_context(state); diff --git a/packages/html/src/elements.rs b/packages/html/src/elements.rs index 7e5bed124..7800369a9 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -1258,6 +1258,8 @@ builder_constructors! { spellcheck: BoolOrDefault DEFAULT, wrap: Wrap DEFAULT, value: String volatile, + + initial_value: String DEFAULT, }; diff --git a/packages/html/src/events/mouse.rs b/packages/html/src/events/mouse.rs index 7899393ff..55d081900 100644 --- a/packages/html/src/events/mouse.rs +++ b/packages/html/src/events/mouse.rs @@ -108,7 +108,7 @@ impl_event! { /// /// ## Example /// ```rust, ignore - /// rsx!( button { "click me", onclick: move |_| log::info!("Clicked!`") } ) + /// rsx!( button { "click me", onclick: move |_| tracing::info!("Clicked!`") } ) /// ``` /// /// ## Reference diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml index 3dfce5bf4..6b4e49eb2 100644 --- a/packages/liveview/Cargo.toml +++ b/packages/liveview/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" [dependencies] thiserror = { workspace = true } -log = { workspace = true } +tracing = { workspace = true } slab = { workspace = true } futures-util = { workspace = true, default-features = false, features = [ "sink", diff --git a/packages/liveview/src/query.rs b/packages/liveview/src/query.rs index 8052c2afa..a638625c1 100644 --- a/packages/liveview/src/query.rs +++ b/packages/liveview/src/query.rs @@ -126,7 +126,7 @@ impl QueryEngine { }}) }})();"# )) { - log::warn!("Query error: {err}"); + tracing::warn!("Query error: {err}"); } Query { diff --git a/packages/router-macro/src/lib.rs b/packages/router-macro/src/lib.rs index c949cf2f4..b1ff7b0fe 100644 --- a/packages/router-macro/src/lib.rs +++ b/packages/router-macro/src/lib.rs @@ -210,7 +210,7 @@ pub fn routable(input: TokenStream) -> TokenStream { let display_impl = route_enum.impl_display(); let routable_impl = route_enum.routable_impl(); - quote! { + (quote! { #error_type #display_impl @@ -218,7 +218,7 @@ pub fn routable(input: TokenStream) -> TokenStream { #routable_impl #parse_impl - } + }) .into() } @@ -482,7 +482,8 @@ impl RouteEnum { let route = s; let (route, _hash) = route.split_once('#').unwrap_or((route, "")); let (route, query) = route.split_once('?').unwrap_or((route, "")); - let mut segments = route.split('/'); + let query = dioxus_router::exports::urlencoding::decode(query).unwrap_or(query.into()); + let mut segments = route.split('/').map(|s| dioxus_router::exports::urlencoding::decode(s).unwrap_or(s.into())); // skip the first empty segment if s.starts_with('/') { let _ = segments.next(); @@ -677,9 +678,9 @@ impl ToTokens for SegmentType { impl<'a> From<&'a RouteSegment> for SegmentType { fn from(value: &'a RouteSegment) -> Self { match value { - segment::RouteSegment::Static(s) => SegmentType::Static(s.to_string()), - segment::RouteSegment::Dynamic(s, _) => SegmentType::Dynamic(s.to_string()), - segment::RouteSegment::CatchAll(s, _) => SegmentType::CatchAll(s.to_string()), + RouteSegment::Static(s) => SegmentType::Static(s.to_string()), + RouteSegment::Dynamic(s, _) => SegmentType::Dynamic(s.to_string()), + RouteSegment::CatchAll(s, _) => SegmentType::CatchAll(s.to_string()), } } } diff --git a/packages/router-macro/src/query.rs b/packages/router-macro/src/query.rs index 8b9db9e51..c97d3be29 100644 --- a/packages/router-macro/src/query.rs +++ b/packages/router-macro/src/query.rs @@ -14,7 +14,7 @@ impl QuerySegment { let ident = &self.ident; let ty = &self.ty; quote! { - let #ident = <#ty as dioxus_router::routable::FromQuery>::from_query(query); + let #ident = <#ty as dioxus_router::routable::FromQuery>::from_query(&*query); } } diff --git a/packages/router-macro/src/route_tree.rs b/packages/router-macro/src/route_tree.rs index 399d20e5e..6b89c80ab 100644 --- a/packages/router-macro/src/route_tree.rs +++ b/packages/router-macro/src/route_tree.rs @@ -312,7 +312,8 @@ impl<'a> RouteTreeSegmentData<'a> { quote! { { let mut segments = segments.clone(); - if let Some(segment) = segments.next() { + let segment = segments.next(); + if let Some(segment) = segment.as_deref() { if #segment == segment { #(#children)* } @@ -369,7 +370,7 @@ impl<'a> RouteTreeSegmentData<'a> { quote! { let mut trailing = String::from("/"); for seg in segments.clone() { - trailing += seg; + trailing += &*seg; trailing += "/"; } trailing.pop(); @@ -506,7 +507,9 @@ fn return_constructed( let remaining_segments = segments.clone(); let mut segments_clone = segments.clone(); let next_segment = segments_clone.next(); + let next_segment = next_segment.as_deref(); let segment_after_next = segments_clone.next(); + let segment_after_next = segment_after_next.as_deref(); match (next_segment, segment_after_next) { // This is the last segment, return the parsed route (None, _) | (Some(""), None) => { @@ -516,7 +519,7 @@ fn return_constructed( _ => { let mut trailing = String::new(); for seg in remaining_segments { - trailing += seg; + trailing += &*seg; trailing += "/"; } trailing.pop(); diff --git a/packages/router-macro/src/segment.rs b/packages/router-macro/src/segment.rs index 62dea59a7..7e4e40662 100644 --- a/packages/router-macro/src/segment.rs +++ b/packages/router-macro/src/segment.rs @@ -25,7 +25,7 @@ impl RouteSegment { match self { Self::Static(segment) => quote! { write!(f, "/{}", #segment)?; }, Self::Dynamic(ident, _) => quote! { write!(f, "/{}", #ident)?; }, - Self::CatchAll(ident, _) => quote! { #ident.display_route_segements(f)?; }, + Self::CatchAll(ident, _) => quote! { #ident.display_route_segments(f)?; }, } } @@ -59,6 +59,7 @@ impl RouteSegment { { let mut segments = segments.clone(); let segment = segments.next(); + let segment = segment.as_deref(); let parsed = if let Some(#segment) = segment { Ok(()) } else { @@ -80,7 +81,8 @@ impl RouteSegment { quote! { { let mut segments = segments.clone(); - let parsed = if let Some(segment) = segments.next() { + let segment = segments.next(); + let parsed = if let Some(segment) = segment.as_deref() { <#ty as dioxus_router::routable::FromRouteSegment>::from_route_segment(segment).map_err(|err| #error_enum_name::#error_enum_varient(#inner_parse_enum::#error_name(err))) } else { Err(#error_enum_name::#error_enum_varient(#inner_parse_enum::#missing_error_name)) @@ -100,9 +102,12 @@ impl RouteSegment { quote! { { let parsed = { - let mut segments = segments.clone(); - let segments: Vec<_> = segments.collect(); - <#ty as dioxus_router::routable::FromRouteSegments>::from_route_segments(&segments).map_err(|err| #error_enum_name::#error_enum_varient(#inner_parse_enum::#error_name(err))) + let remaining_segments: Vec<_> = segments.collect(); + let mut new_segments: Vec<&str> = Vec::new(); + for segment in &remaining_segments { + new_segments.push(&*segment); + } + <#ty as dioxus_router::routable::FromRouteSegments>::from_route_segments(&new_segments).map_err(|err| #error_enum_name::#error_enum_varient(#inner_parse_enum::#error_name(err))) }; match parsed { Ok(#name) => { diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index 46d7536b6..80923d539 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -14,10 +14,10 @@ anyhow = "1.0.66" dioxus = { workspace = true } dioxus-router-macro = { workspace = true } gloo = { version = "0.8.0", optional = true } -log = { workspace = true } +tracing = { workspace = true } thiserror = { workspace = true } futures-util = { workspace = true } -serde_urlencoded = { version = "0.7.1", optional = true } +urlencoding = "2.1.3" serde = { version = "1", features = ["derive"], optional = true } url = "2.3.1" wasm-bindgen = { workspace = true, optional = true } diff --git a/packages/router/src/components/history_buttons.rs b/packages/router/src/components/history_buttons.rs index 6bd23d860..ad3d63583 100644 --- a/packages/router/src/components/history_buttons.rs +++ b/packages/router/src/components/history_buttons.rs @@ -1,5 +1,5 @@ use dioxus::prelude::*; -use log::error; +use tracing::error; use crate::utils::use_router_internal::use_router_internal; diff --git a/packages/router/src/components/link.rs b/packages/router/src/components/link.rs index bc55fec8c..c46fc49ef 100644 --- a/packages/router/src/components/link.rs +++ b/packages/router/src/components/link.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use std::rc::Rc; use dioxus::prelude::*; -use log::error; +use tracing::error; use crate::navigation::NavigationTarget; use crate::prelude::Routable; diff --git a/packages/router/src/history/web.rs b/packages/router/src/history/web.rs index 8b6089b20..375dba5ff 100644 --- a/packages/router/src/history/web.rs +++ b/packages/router/src/history/web.rs @@ -139,7 +139,7 @@ impl WebHistory { ); let current_route = myself.current_route(); - log::trace!("initial route: {:?}", current_route); + tracing::trace!("initial route: {:?}", current_route); let current_url = current_route.to_string(); let state = myself.create_state(current_route); let _ = replace_state_with_url(&myself.history, &state, Some(¤t_url)); diff --git a/packages/router/src/history/web_hash.rs b/packages/router/src/history/web_hash.rs index c910b1c97..c23bca237 100644 --- a/packages/router/src/history/web_hash.rs +++ b/packages/router/src/history/web_hash.rs @@ -1,8 +1,8 @@ use std::sync::{Arc, Mutex}; use gloo::{events::EventListener, render::AnimationFrame, utils::window}; -use log::error; use serde::{de::DeserializeOwned, Serialize}; +use tracing::error; use url::Url; use web_sys::{History, ScrollRestoration, Window}; diff --git a/packages/router/src/incremental.rs b/packages/router/src/incremental.rs index 79f4e24bf..cf1bc5d70 100644 --- a/packages/router/src/incremental.rs +++ b/packages/router/src/incremental.rs @@ -59,8 +59,8 @@ where .await?; } Err(e) => { - log::info!("@ route: {}", full_path); - log::error!("Error pre-caching static route: {}", e); + tracing::info!("@ route: {}", full_path); + tracing::error!("Error pre-caching static route: {}", e); } } } diff --git a/packages/router/src/lib.rs b/packages/router/src/lib.rs index 49b7ffc42..a92394513 100644 --- a/packages/router/src/lib.rs +++ b/packages/router/src/lib.rs @@ -82,3 +82,8 @@ pub mod prelude { mod utils { pub(crate) mod use_router_internal; } + +#[doc(hidden)] +pub mod exports { + pub use urlencoding; +} diff --git a/packages/router/src/routable.rs b/packages/router/src/routable.rs index d9f5b2346..768fa2cd5 100644 --- a/packages/router/src/routable.rs +++ b/packages/router/src/routable.rs @@ -3,16 +3,18 @@ #![allow(non_snake_case)] use dioxus::prelude::*; +use std::iter::FlatMap; +use std::slice::Iter; use std::{fmt::Display, str::FromStr}; -/// An error that occurs when parsing a route +/// An error that occurs when parsing a route. #[derive(Debug, PartialEq)] -pub struct RouteParseError { - /// The attempted routes that failed to match +pub struct RouteParseError { + /// The attempted routes that failed to match. pub attempted_routes: Vec, } -impl std::fmt::Display for RouteParseError { +impl Display for RouteParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Route did not match:\nAttempted Matches:\n")?; for (i, route) in self.attempted_routes.iter().enumerate() { @@ -26,63 +28,96 @@ impl std::fmt::Display for RouteParseError { /// /// 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` +/// 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 + /// Create an instance of `Self` from a query string. fn from_query(query: &str) -> Self; } impl From<&'a str>> FromQuery for T { fn from_query(query: &str) -> Self { - T::from(query) + T::from(&*urlencoding::decode(query).expect("Failed to decode url encoding")) } } -/// Something that can be created from a route segment +/// Something that can be created from a route segment. pub trait FromRouteSegment: Sized { - /// The error that can occur when parsing a route segment + /// The error that can occur when parsing a route segment. type Err; - /// Create an instance of `Self` from a route segment + /// Create an instance of `Self` from a route segment. fn from_route_segment(route: &str) -> Result; } impl FromRouteSegment for T where - ::Err: std::fmt::Display, + ::Err: Display, { type Err = ::Err; fn from_route_segment(route: &str) -> Result { - T::from_str(route) + match urlencoding::decode(route) { + Ok(segment) => T::from_str(&segment), + Err(err) => { + tracing::error!("Failed to decode url encoding: {}", err); + T::from_str(route) + } + } } } -/// Something that can be converted to route segments -pub trait ToRouteSegments { - /// Display the route segments - fn display_route_segements(self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result; +#[test] +fn full_circle() { + let route = "testing 1234 hello world"; + assert_eq!(String::from_route_segment(route).unwrap(), route); } -impl ToRouteSegments for I +/// Something that can be converted to route segments. +pub trait ToRouteSegments { + /// Display the route segments. + fn display_route_segments(self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result; +} + +impl ToRouteSegments for I where I: IntoIterator, { - fn display_route_segements(self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn display_route_segments(self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for segment in self { write!(f, "/")?; - write!(f, "{}", segment)?; + let segment = segment.to_string(); + match urlencoding::decode(&segment) { + Ok(segment) => write!(f, "{}", segment)?, + Err(err) => { + tracing::error!("Failed to decode url encoding: {}", err); + write!(f, "{}", segment)? + } + } } Ok(()) } } -/// Something that can be created from route segments +#[test] +fn to_route_segments() { + struct DisplaysRoute; + + impl Display for DisplaysRoute { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let segments = vec!["hello", "world"]; + segments.display_route_segments(f) + } + } + + assert_eq!(DisplaysRoute.to_string(), "/hello/world"); +} + +/// Something that can be created from route segments. pub trait FromRouteSegments: Sized { - /// The error that can occur when parsing route segments + /// The error that can occur when parsing route segments. type Err; - /// Create an instance of `Self` from route segments + /// Create an instance of `Self` from route segments. fn from_route_segments(segments: &[&str]) -> Result; } @@ -97,20 +132,45 @@ impl> FromRouteSegments for I { } } +/// A flattened version of [`Routable::SITE_MAP`]. +/// This essentially represents a `Vec>`, which you can collect it into. +type SiteMapFlattened<'a> = FlatMap< + Iter<'a, SiteMapSegment>, + Vec>, + fn(&SiteMapSegment) -> Vec>, +>; + +fn seg_strs_to_route(segs_maybe: &Option>) -> Option +where + T: Routable, +{ + if let Some(str) = seg_strs_to_str(segs_maybe) { + T::from_str(&str).ok() + } else { + None + } +} + +fn seg_strs_to_str(segs_maybe: &Option>) -> Option { + segs_maybe + .as_ref() + .map(|segs| String::from('/') + &segs.join("/")) +} + /// Something that can be: -/// 1. Converted from a route -/// 2. Converted to a route -/// 3. Rendered as a component +/// 1. Converted from a route. +/// 2. Converted to a route. +/// 3. Rendered as a component. /// -/// This trait can be derived using the `#[derive(Routable)]` macro -pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static { - /// The error that can occur when parsing a route +/// This trait can be derived using the `#[derive(Routable)]` macro. +pub trait Routable: FromStr + Display + Clone + 'static { + /// The error that can occur when parsing a route. const SITE_MAP: &'static [SiteMapSegment]; /// Render the route at the given level fn render<'a>(&self, cx: &'a ScopeState, level: usize) -> Element<'a>; - /// Checks if this route is a child of the given route + /// Checks if this route is a child of the given route. /// /// # Example /// ```rust @@ -152,7 +212,7 @@ pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static { true } - /// Get the parent route of this route + /// Get the parent route of this route. /// /// # Example /// ```rust @@ -192,72 +252,67 @@ pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static { Self::from_str(&new_route).ok() } - /// Gets a list of all static routes + /// Returns a flattened version of [`Self::SITE_MAP`]. + fn flatten_site_map<'a>() -> SiteMapFlattened<'a> { + Self::SITE_MAP.iter().flat_map(SiteMapSegment::flatten) + } + + /// Gets a list of all the static routes. + /// Example static route: `#[route("/static/route")]` fn static_routes() -> Vec { - Self::SITE_MAP - .iter() - .flat_map(|segment| segment.flatten()) + Self::flatten_site_map() .filter_map(|route| { - if route + let route_if_static = &route .iter() - .all(|segment| matches!(segment, SegmentType::Static(_))) - { - Self::from_str( - &route - .iter() - .map(|segment| match segment { - SegmentType::Static(s) => s.to_string(), - _ => unreachable!(), - }) - .collect::>() - .join("/"), - ) - .ok() - } else { - None - } + .map(|segment| match segment { + SegmentType::Static(s) => Some(*s), + _ => None, + }) + .collect::>>(); + + seg_strs_to_route(route_if_static) }) .collect() } } trait RoutableFactory { - type Err: std::fmt::Display; + type Err: Display; type Routable: Routable + FromStr; } impl RoutableFactory for R where - ::Err: std::fmt::Display, + ::Err: Display, { type Err = ::Err; type Routable = R; } -trait RouteRenderable: std::fmt::Display + 'static { +trait RouteRenderable: Display + 'static { fn render<'a>(&self, cx: &'a ScopeState, level: usize) -> Element<'a>; } impl RouteRenderable for R where - ::Err: std::fmt::Display, + ::Err: Display, { fn render<'a>(&self, cx: &'a ScopeState, level: usize) -> Element<'a> { self.render(cx, level) } } -/// A type erased map of the site structurens +/// A type erased map of the site structure. #[derive(Debug, Clone, PartialEq)] pub struct SiteMapSegment { - /// The type of the route segment + /// The type of the route segment. pub segment_type: SegmentType, - /// The children of the route segment + /// The children of the route segment. pub children: &'static [SiteMapSegment], } impl SiteMapSegment { - /// Take a map of the site structure and flatten it into a vector of routes + /// Take a map of the site structure and flatten it into a vector of routes. pub fn flatten(&self) -> Vec> { let mut routes = Vec::new(); self.flatten_inner(&mut routes, Vec::new()); @@ -277,16 +332,16 @@ impl SiteMapSegment { } } -/// The type of a route segment +/// The type of a route segment. #[derive(Debug, Clone, PartialEq)] pub enum SegmentType { - /// A static route segment + /// A static route segment. Static(&'static str), - /// A dynamic route segment + /// A dynamic route segment. Dynamic(&'static str), - /// A catch all route segment + /// A catch all route segment. CatchAll(&'static str), - /// A child router + /// A child router. Child, } @@ -296,7 +351,7 @@ impl Display for SegmentType { SegmentType::Static(s) => write!(f, "/{}", s), SegmentType::Child => Ok(()), SegmentType::Dynamic(s) => write!(f, "/:{}", s), - SegmentType::CatchAll(s) => write!(f, "/:...{}", s), + SegmentType::CatchAll(s) => write!(f, "/:..{}", s), } } } diff --git a/packages/signals/Cargo.toml b/packages/signals/Cargo.toml index 0017a1545..56e19bbd8 100644 --- a/packages/signals/Cargo.toml +++ b/packages/signals/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] dioxus-core = { workspace = true } generational-box = { workspace = true } -log.workspace = true +tracing = { workspace = true } simple_logger = "4.2.0" serde = { version = "1", features = ["derive"], optional = true } diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index f41624f96..c20d95005 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -177,7 +177,7 @@ impl Signal { } else if let Some(current_scope_id) = current_scope_id() { // only subscribe if the vdom is rendering if dioxus_core::vdom_is_rendering() { - log::trace!( + tracing::trace!( "{:?} subscribed to {:?}", self.inner.value, current_scope_id @@ -209,7 +209,7 @@ impl Signal { { let inner = self.inner.read(); for &scope_id in &*inner.subscribers.borrow() { - log::trace!( + tracing::trace!( "Write on {:?} triggered update on {:?}", self.inner.value, scope_id @@ -224,7 +224,7 @@ impl Signal { std::mem::take(&mut *effects) }; for effect in subscribers { - log::trace!( + tracing::trace!( "Write on {:?} triggered effect {:?}", self.inner.value, effect diff --git a/packages/ssr/Cargo.toml b/packages/ssr/Cargo.toml index 1450bd46e..5804c6b5e 100644 --- a/packages/ssr/Cargo.toml +++ b/packages/ssr/Cargo.toml @@ -15,14 +15,14 @@ askama_escape = "0.10.3" thiserror = "1.0.23" rustc-hash = "1.1.0" lru = "0.10.0" -log = "0.4.13" +tracing = { workspace = true } http = "0.2.9" tokio = { version = "1.28", features = ["full"], optional = true } [dev-dependencies] dioxus = { workspace = true } thiserror = { workspace = true } -log = { workspace = true } +tracing = { workspace = true } fern = { version = "0.6.0", features = ["colored"] } anyhow = "1.0" argh = "0.1.4" diff --git a/packages/ssr/src/incremental.rs b/packages/ssr/src/incremental.rs index 9647124de..c3bb25314 100644 --- a/packages/ssr/src/incremental.rs +++ b/packages/ssr/src/incremental.rs @@ -139,13 +139,13 @@ impl IncrementalRenderer { let age = elapsed.as_secs(); if let Some(invalidate_after) = self.invalidate_after { if elapsed < invalidate_after { - log::trace!("memory cache hit {:?}", route); + tracing::trace!("memory cache hit {:?}", route); output.write_all(cache_hit).await?; let max_age = invalidate_after.as_secs(); return Ok(Some(RenderFreshness::new(age, max_age))); } } else { - log::trace!("memory cache hit {:?}", route); + tracing::trace!("memory cache hit {:?}", route); output.write_all(cache_hit).await?; return Ok(Some(RenderFreshness::new_age(age))); } @@ -157,7 +157,7 @@ impl IncrementalRenderer { if let Ok(file) = tokio::fs::File::open(file_path.full_path).await { let mut file = BufReader::new(file); tokio::io::copy_buf(&mut file, output).await?; - log::trace!("file cache hit {:?}", route); + tracing::trace!("file cache hit {:?}", route); self.promote_memory_cache(&route); return Ok(Some(freshness)); } @@ -184,7 +184,7 @@ impl IncrementalRenderer { let freshness = self .render_and_cache(route, component, props, output, rebuild_with, renderer) .await?; - log::trace!("cache miss"); + tracing::trace!("cache miss"); Ok(freshness) } } @@ -206,7 +206,7 @@ impl IncrementalRenderer { } // if the timestamp is invalid or passed, delete the file if let Err(err) = std::fs::remove_file(entry.path()) { - log::error!("Failed to remove file: {}", err); + tracing::error!("Failed to remove file: {}", err); } } } diff --git a/packages/web/Cargo.toml b/packages/web/Cargo.toml index 8de282869..dda54395d 100644 --- a/packages/web/Cargo.toml +++ b/packages/web/Cargo.toml @@ -20,7 +20,7 @@ dioxus-interpreter-js = { workspace = true, features = [ js-sys = "0.3.56" wasm-bindgen = { workspace = true, features = ["enable-interning"] } wasm-bindgen-futures = "0.4.29" -log = { workspace = true } +tracing = { workspace = true } rustc-hash = { workspace = true } console_error_panic_hook = { version = "0.1.7", optional = true } futures-util = { workspace = true, features = ["std", "async-await", "async-await-macro"] } @@ -75,3 +75,4 @@ wasm-logger = "0.2.0" gloo-timers = "0.2.3" gloo-dialogs = "0.1.1" dioxus-web = { path = ".", features = ["hydrate"] } +tracing-wasm = "0.2.1" diff --git a/packages/web/examples/hydrate.rs b/packages/web/examples/hydrate.rs index 3491bba81..08c0f95cd 100644 --- a/packages/web/examples/hydrate.rs +++ b/packages/web/examples/hydrate.rs @@ -43,13 +43,13 @@ fn Bapp(cx: Scope) -> Element { fn main() { console_error_panic_hook::set_once(); - wasm_logger::init(wasm_logger::Config::new(log::Level::Trace)); + tracing_wasm::set_as_global_default(); let mut dom = VirtualDom::new(app); let _ = dom.rebuild(); let pre = dioxus_ssr::pre_render(&dom); - log::trace!("{}", pre); + tracing::trace!("{}", pre); // set the inner content of main to the pre-rendered content window() diff --git a/packages/web/src/dom.rs b/packages/web/src/dom.rs index 52f2ab1a9..4fa5c9444 100644 --- a/packages/web/src/dom.rs +++ b/packages/web/src/dom.rs @@ -249,7 +249,6 @@ impl WebsysDom { for id in to_mount { let node = get_node(id.0 as u32); if let Some(element) = node.dyn_ref::() { - log::info!("mounted event fired: {}", id.0); let data: MountedData = element.into(); let data = Rc::new(data); let _ = self.event_channel.unbounded_send(UiEvent { diff --git a/packages/web/src/eval.rs b/packages/web/src/eval.rs index 954bb1b54..eefece50e 100644 --- a/packages/web/src/eval.rs +++ b/packages/web/src/eval.rs @@ -46,7 +46,7 @@ impl WebEvaluator { Ok(data) => _ = channel_sender.send_blocking(data), Err(e) => { // Can't really do much here. - log::error!("failed to serialize JsValue to serde_json::Value (eval communication) - {}", e); + tracing::error!("failed to serialize JsValue to serde_json::Value (eval communication) - {}", e); } } }); diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 261232607..60f84de37 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -170,7 +170,7 @@ pub fn launch_with_props( /// } /// ``` pub async fn run_with_props(root: fn(Scope) -> Element, root_props: T, cfg: Config) { - log::info!("Starting up"); + tracing::info!("Starting up"); let mut dom = VirtualDom::new_with_props(root, root_props); @@ -205,7 +205,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop let mut websys_dom = dom::WebsysDom::new(cfg, tx); - log::info!("rebuilding app"); + tracing::info!("rebuilding app"); if should_hydrate { #[cfg(feature = "hydrate")] @@ -217,7 +217,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop websys_dom.load_templates(&templates); if let Err(err) = websys_dom.rehydrate(&dom) { - log::error!( + tracing::error!( "Rehydration failed {:?}. Rebuild DOM into element from scratch", &err ); @@ -240,7 +240,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop websys_dom.mount(); loop { - log::trace!("waiting for work"); + tracing::trace!("waiting for work"); // if virtualdom has nothing, wait for it to have something before requesting idle time // if there is work then this future resolves immediately. diff --git a/packages/web/src/rehydrate.rs b/packages/web/src/rehydrate.rs index c7ea6d87d..4415ceb37 100644 --- a/packages/web/src/rehydrate.rs +++ b/packages/web/src/rehydrate.rs @@ -114,9 +114,9 @@ impl WebsysDom { node: &TemplateNode, last_node_was_static_text: &mut bool, ) -> Result<(), RehydrationError> { - log::trace!("rehydrate template node: {:?}", node); + tracing::trace!("rehydrate template node: {:?}", node); if let Ok(current_child) = current_child { - if log::log_enabled!(log::Level::Trace) { + if tracing::event_enabled!(tracing::Level::TRACE) { web_sys::console::log_1(¤t_child.clone().into()); } } @@ -203,9 +203,9 @@ impl WebsysDom { dynamic: &DynamicNode, last_node_was_static_text: &mut bool, ) -> Result<(), RehydrationError> { - log::trace!("rehydrate dynamic node: {:?}", dynamic); + tracing::trace!("rehydrate dynamic node: {:?}", dynamic); if let Ok(current_child) = current_child { - if log::log_enabled!(log::Level::Trace) { + if tracing::event_enabled!(tracing::Level::TRACE) { web_sys::console::log_1(¤t_child.clone().into()); } }