From 9cef71b6b98ae071291fe8fb026436bcfa0f1776 Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:13:22 -0400 Subject: [PATCH 1/4] fix(cli): improve error message for invalid config (#1200) Previously an invalid `Dioxus.toml` file would yield this error when running e.g. `dx serve`: ``` Error: Failed to load `Dioxus.toml` because: Dioxus.toml parse failed ``` This doesn't give any indication why it failed to parse. This commit updates it to include why the parsing failed, e.g.: ``` Error: Failed to load Dioxus config because: Dioxus.toml missing field `name` for key `application` at line 38 column 1 ``` I initially had it format the message to include `Dioxus.toml:38:1` to be clickable in some terminals, but the location specified didn't always seem particularly relevant to the actual problem so I left it as-is. This also fixes what I believe would be an issue on case-sensitive file systems where if `dioxus.toml` existed it would try to read `Dioxus.toml`. I'm still fairly new to Rust, so the `.as_path()` calls may not be the best way to deal with the fact that the borrow checker wouldn't let me re-use `crate_dir` and `dioxus_conf_file`. I'm open to suggestions! --- packages/cli/src/config.rs | 28 ++++++++++++++++++++-------- packages/cli/src/main.rs | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs index f9117f6e5..79e6c7321 100644 --- a/packages/cli/src/config.rs +++ b/packages/cli/src/config.rs @@ -1,6 +1,9 @@ use crate::error::Result; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, path::PathBuf}; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DioxusConfig { @@ -19,27 +22,36 @@ fn default_plugin() -> toml::Value { impl DioxusConfig { pub fn load() -> crate::error::Result> { let Ok(crate_dir) = crate::cargo::crate_root() else { return Ok(None); }; + let crate_dir = crate_dir.as_path(); - // we support either `Dioxus.toml` or `Cargo.toml` let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else { return Ok(None); }; + let dioxus_conf_file = dioxus_conf_file.as_path(); toml::from_str::(&std::fs::read_to_string(dioxus_conf_file)?) - .map_err(|_| crate::Error::Unique("Dioxus.toml parse failed".into())) + .map_err(|err| { + let error_location = dioxus_conf_file + .strip_prefix(crate_dir) + .unwrap_or(dioxus_conf_file) + .display(); + crate::Error::Unique(format!("{error_location} {err}")) + }) .map(Some) } } -fn acquire_dioxus_toml(dir: PathBuf) -> Option { +fn acquire_dioxus_toml(dir: &Path) -> Option { // prefer uppercase - if dir.join("Dioxus.toml").is_file() { - return Some(dir.join("Dioxus.toml")); + let uppercase_conf = dir.join("Dioxus.toml"); + if uppercase_conf.is_file() { + return Some(uppercase_conf); } // lowercase is fine too - if dir.join("dioxus.toml").is_file() { - return Some(dir.join("Dioxus.toml")); + let lowercase_conf = dir.join("dioxus.toml"); + if lowercase_conf.is_file() { + return Some(lowercase_conf); } None diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index f2007aa43..86e90db96 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> { set_up_logging(); let _dioxus_config = DioxusConfig::load() - .map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))? + .map_err(|e| anyhow!("Failed to load Dioxus config because: {e}"))? .unwrap_or_else(|| { log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config"); DioxusConfig::default() From 947b7b650ee7b577e7e39a95c41982c11c4f780d Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:00:59 -0400 Subject: [PATCH 2/4] chore: rename `playwrite` to `playwright` (#1203) I assume this was a mistake and not intentional. --- .github/workflows/main.yml | 2 +- .gitignore | 4 +-- Cargo.toml | 8 +++--- .../fullstack.spec.js | 0 .../fullstack/.gitignore | 0 .../fullstack/Cargo.toml | 2 +- .../fullstack/src/main.rs | 2 +- .../liveview.spec.js | 0 .../liveview/Cargo.toml | 4 +-- .../liveview/src/main.rs | 2 +- .../web.spec.js | 0 .../web/Cargo.toml | 4 +-- .../web/src/main.rs | 2 +- playwright.config.js | 28 ++++++++++--------- 14 files changed, 30 insertions(+), 28 deletions(-) rename {playwrite-tests => playwright-tests}/fullstack.spec.js (100%) rename {playwrite-tests => playwright-tests}/fullstack/.gitignore (100%) rename {playwrite-tests => playwright-tests}/fullstack/Cargo.toml (93%) rename {playwrite-tests => playwright-tests}/fullstack/src/main.rs (97%) rename {playwrite-tests => playwright-tests}/liveview.spec.js (100%) rename {playwrite-tests => playwright-tests}/liveview/Cargo.toml (77%) rename {playwrite-tests => playwright-tests}/liveview/src/main.rs (96%) rename {playwrite-tests => playwright-tests}/web.spec.js (100%) rename {playwrite-tests => playwright-tests}/web/Cargo.toml (72%) rename {playwrite-tests => playwright-tests}/web/src/main.rs (95%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b44aab843..b37e63aa4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ on: - lib.rs - Cargo.toml - Makefile.toml - - playwrite-tests/** + - playwright-tests/** pull_request: types: [opened, synchronize, reopened, ready_for_review] diff --git a/.gitignore b/.gitignore index bca0fe28f..b8025753e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /target -/playwrite-tests/web/dist -/playwrite-tests/fullstack/dist +/playwright-tests/web/dist +/playwright-tests/fullstack/dist /dist Cargo.lock .DS_Store diff --git a/Cargo.toml b/Cargo.toml index b7a6e96e9..d849a4b5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,10 +35,10 @@ members = [ # Full project examples "examples/tailwind", "examples/PWA-example", - # Playwrite tests - "playwrite-tests/liveview", - "playwrite-tests/web", - "playwrite-tests/fullstack", + # Playwright tests + "playwright-tests/liveview", + "playwright-tests/web", + "playwright-tests/fullstack", ] exclude = ["examples/mobile_demo"] diff --git a/playwrite-tests/fullstack.spec.js b/playwright-tests/fullstack.spec.js similarity index 100% rename from playwrite-tests/fullstack.spec.js rename to playwright-tests/fullstack.spec.js diff --git a/playwrite-tests/fullstack/.gitignore b/playwright-tests/fullstack/.gitignore similarity index 100% rename from playwrite-tests/fullstack/.gitignore rename to playwright-tests/fullstack/.gitignore diff --git a/playwrite-tests/fullstack/Cargo.toml b/playwright-tests/fullstack/Cargo.toml similarity index 93% rename from playwrite-tests/fullstack/Cargo.toml rename to playwright-tests/fullstack/Cargo.toml index a11bfa461..9cca0d2fa 100644 --- a/playwrite-tests/fullstack/Cargo.toml +++ b/playwright-tests/fullstack/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "dioxus-playwrite-fullstack-test" +name = "dioxus-playwright-fullstack-test" version = "0.1.0" edition = "2021" publish = false diff --git a/playwrite-tests/fullstack/src/main.rs b/playwright-tests/fullstack/src/main.rs similarity index 97% rename from playwrite-tests/fullstack/src/main.rs rename to playwright-tests/fullstack/src/main.rs index 98caadbb6..610c7afcb 100644 --- a/playwrite-tests/fullstack/src/main.rs +++ b/playwright-tests/fullstack/src/main.rs @@ -1,4 +1,4 @@ -// This test is used by playwrite configured in the root of the repo +// This test is used by playwright configured in the root of the repo // Tests: // - Server functions // - SSR diff --git a/playwrite-tests/liveview.spec.js b/playwright-tests/liveview.spec.js similarity index 100% rename from playwrite-tests/liveview.spec.js rename to playwright-tests/liveview.spec.js diff --git a/playwrite-tests/liveview/Cargo.toml b/playwright-tests/liveview/Cargo.toml similarity index 77% rename from playwrite-tests/liveview/Cargo.toml rename to playwright-tests/liveview/Cargo.toml index 8c4cad1ef..173ae1d81 100644 --- a/playwrite-tests/liveview/Cargo.toml +++ b/playwright-tests/liveview/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "dioxus-playwrite-liveview-test" +name = "dioxus-playwright-liveview-test" version = "0.0.1" edition = "2021" -description = "Playwrite test for Dioxus Liveview" +description = "Playwright test for Dioxus Liveview" license = "MIT/Apache-2.0" publish = false diff --git a/playwrite-tests/liveview/src/main.rs b/playwright-tests/liveview/src/main.rs similarity index 96% rename from playwrite-tests/liveview/src/main.rs rename to playwright-tests/liveview/src/main.rs index 42bd9a3e3..d28e3b7fd 100644 --- a/playwrite-tests/liveview/src/main.rs +++ b/playwright-tests/liveview/src/main.rs @@ -1,4 +1,4 @@ -// This test is used by playwrite configured in the root of the repo +// This test is used by playwright configured in the root of the repo use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router}; use dioxus::prelude::*; diff --git a/playwrite-tests/web.spec.js b/playwright-tests/web.spec.js similarity index 100% rename from playwrite-tests/web.spec.js rename to playwright-tests/web.spec.js diff --git a/playwrite-tests/web/Cargo.toml b/playwright-tests/web/Cargo.toml similarity index 72% rename from playwrite-tests/web/Cargo.toml rename to playwright-tests/web/Cargo.toml index b1becd86e..22f4f4096 100644 --- a/playwrite-tests/web/Cargo.toml +++ b/playwright-tests/web/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "dioxus-playwrite-web-test" +name = "dioxus-playwright-web-test" version = "0.0.1" edition = "2021" -description = "Playwrite test for Dioxus Web" +description = "Playwright test for Dioxus Web" license = "MIT/Apache-2.0" publish = false diff --git a/playwrite-tests/web/src/main.rs b/playwright-tests/web/src/main.rs similarity index 95% rename from playwrite-tests/web/src/main.rs rename to playwright-tests/web/src/main.rs index d1881539c..c4850e943 100644 --- a/playwrite-tests/web/src/main.rs +++ b/playwright-tests/web/src/main.rs @@ -1,4 +1,4 @@ -// This test is used by playwrite configured in the root of the repo +// This test is used by playwright configured in the root of the repo use dioxus::prelude::*; use dioxus_web::use_eval; diff --git a/playwright.config.js b/playwright.config.js index 5d2c3642f..74f1391d5 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,6 +1,6 @@ // @ts-check -const { defineConfig, devices } = require('@playwright/test'); -const path = require('path'); +const { defineConfig, devices } = require("@playwright/test"); +const path = require("path"); /** * Read environment variables from file. @@ -12,7 +12,7 @@ const path = require('path'); * @see https://playwright.dev/docs/test-configuration */ module.exports = defineConfig({ - testDir: './playwrite-tests', + testDir: "./playwright-tests", /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ @@ -22,21 +22,21 @@ module.exports = defineConfig({ /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', + reporter: "html", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ // baseURL: 'http://127.0.0.1:3000', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', + trace: "on-first-retry", }, /* Configure projects for major browsers */ projects: [ { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + name: "chromium", + use: { ...devices["Desktop Chrome"] }, }, // { @@ -73,27 +73,29 @@ module.exports = defineConfig({ /* Run your local dev server before starting the tests */ webServer: [ { - command: 'cargo run --package dioxus-playwrite-liveview-test --bin dioxus-playwrite-liveview-test', + command: + "cargo run --package dioxus-playwright-liveview-test --bin dioxus-playwright-liveview-test", port: 3030, timeout: 10 * 60 * 1000, reuseExistingServer: !process.env.CI, stdout: "pipe", }, { - cwd: path.join(process.cwd(), 'playwrite-tests', 'web'), - command: 'dioxus serve', + cwd: path.join(process.cwd(), "playwright-tests", "web"), + command: "dioxus serve", port: 8080, timeout: 10 * 60 * 1000, reuseExistingServer: !process.env.CI, stdout: "pipe", }, { - cwd: path.join(process.cwd(), 'playwrite-tests', 'fullstack'), - command: 'dioxus build --features web\ncargo run --release --features ssr --no-default-features', + cwd: path.join(process.cwd(), "playwright-tests", "fullstack"), + command: + "dioxus build --features web\ncargo run --release --features ssr --no-default-features", port: 3333, timeout: 10 * 60 * 1000, reuseExistingServer: !process.env.CI, stdout: "pipe", - } + }, ], }); From 235406b59d3ee3e0f302e1ad80bde21e7eb19e9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:01:13 -0500 Subject: [PATCH 3/4] Bump JamesIves/github-pages-deploy-action from 4.4.2 to 4.4.3 (#1205) Bumps [JamesIves/github-pages-deploy-action](https://github.com/jamesives/github-pages-deploy-action) from 4.4.2 to 4.4.3. - [Release notes](https://github.com/jamesives/github-pages-deploy-action/releases) - [Commits](https://github.com/jamesives/github-pages-deploy-action/compare/v4.4.2...v4.4.3) --- updated-dependencies: - dependency-name: JamesIves/github-pages-deploy-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/docs stable.yml | 2 +- .github/workflows/docs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs stable.yml b/.github/workflows/docs stable.yml index 98245fa89..a2d4e2c07 100644 --- a/.github/workflows/docs stable.yml +++ b/.github/workflows/docs stable.yml @@ -29,7 +29,7 @@ jobs: # cd fermi && mdbook build -d ../nightly/fermi && cd .. - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@v4.4.2 + uses: JamesIves/github-pages-deploy-action@v4.4.3 with: branch: gh-pages # The branch the action should deploy to. folder: docs/nightly # The folder the action should deploy. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d209c0c1a..dafe0384d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -34,7 +34,7 @@ jobs: # cd fermi && mdbook build -d ../nightly/fermi && cd .. - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@v4.4.2 + uses: JamesIves/github-pages-deploy-action@v4.4.3 with: branch: gh-pages # The branch the action should deploy to. folder: docs/nightly # The folder the action should deploy. From 9cbc086aa186e2b12d9fa068173970d18af3ba63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Mon, 17 Jul 2023 18:02:02 +0200 Subject: [PATCH 4/4] fix: Update use_ref docs (#1201) --- packages/hooks/src/useref.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/hooks/src/useref.rs b/packages/hooks/src/useref.rs index 1865dadb3..cf1b0306f 100644 --- a/packages/hooks/src/useref.rs +++ b/packages/hooks/src/useref.rs @@ -16,7 +16,7 @@ use std::{ /// writes through the `write` method. Whenever `write` is called, the component /// that initialized the hook will be marked as "dirty". /// -/// ```rust, ignore +/// ```rust, no_run /// let val = use_ref(|| HashMap::::new()); /// /// // using `write` will give us a `RefMut` to the inner value, which we can call methods on @@ -26,7 +26,7 @@ use std::{ /// /// You can avoid this default behavior with `write_silent` /// -/// ```ignore +/// ```rust, no_run /// // with `write_silent`, the component will not be re-rendered /// val.write_silent().insert(2, "goodbye".to_string()); /// ``` @@ -35,7 +35,7 @@ use std::{ /// /// To read values out of the refcell, you can use the `read` method which will retrun a `Ref`. /// -/// ```rust, ignore +/// ```rust, no_run /// let map: Ref<_> = val.read(); /// /// let item = map.get(&1); @@ -43,7 +43,7 @@ use std::{ /// /// To get an &T out of the RefCell, you need to "reborrow" through the Ref: /// -/// ```rust, ignore +/// ```rust, no_run /// let read = val.read(); /// let map = &*read; /// ``` @@ -54,10 +54,10 @@ use std::{ /// Typically this will be a collection like a HashMap or a Vec. To create new /// elements from the collection, we can use `read()` directly in our rsx!. /// -/// ```rust, ignore +/// ```rust, no_run /// rsx!{ /// val.read().iter().map(|(k, v)| { -/// rsx!{ key: "{k}", value: "{v}" } +/// rsx!{ key: "{k}", "{v}" } /// }) /// } /// ``` @@ -66,9 +66,9 @@ use std::{ /// "render" inside the iterator. For some cases you might need to collect into /// a temporary Vec. /// -/// ```rust, ignore +/// ```rust, no_run /// let items = val.read().iter().map(|(k, v)| { -/// cx.render(rsx!{ key: "{k}", value: "{v}" }) +/// cx.render(rsx!{ key: "{k}", "{v}" }) /// }); /// /// // collect into a Vec @@ -80,9 +80,9 @@ use std::{ /// /// To access values from a `UseRef` in an async context, you need to detach it /// from the current scope's lifetime, making it a `'static` value. This is done -/// by simply calling `ToOnwed` or `Clone`. +/// by simply calling `to_owned` or `clone`. /// -/// ```rust, ignore +/// ```rust, no_run /// let val = use_ref(|| HashMap::::new()); /// /// cx.spawn({ @@ -95,15 +95,15 @@ use std::{ /// ``` /// /// If you're working with lots of values like UseState and UseRef, you can use the -/// `clone!` macro to make it easier to write the above code. +/// `to_owned!` macro to make it easier to write the above code. /// -/// ```rust, ignore +/// ```rust, no_run /// let val1 = use_ref(|| HashMap::::new()); /// let val2 = use_ref(|| HashMap::::new()); /// let val3 = use_ref(|| HashMap::::new()); /// /// cx.spawn({ -/// clone![val1, val2, val3]; +/// to_owned![val1, val2, val3]; /// async move { /// some_work().await; /// val.write().insert(1, "hello".to_string()); @@ -194,7 +194,7 @@ impl UseRef { /// Note: You can always "reborrow" the value through the RefCell. /// This method just does it for you automatically. /// - /// ```rust, ignore + /// ```rust, no_run /// let val = use_ref(|| HashMap::::new()); /// /// @@ -214,7 +214,7 @@ impl UseRef { /// Note: You can always "reborrow" the value through the RefCell. /// This method just does it for you automatically. /// - /// ```rust, ignore + /// ```rust, no_run /// let val = use_ref(|| HashMap::::new()); /// ///