Merge branch 'main' into jk/fix-hotreloading-issues

This commit is contained in:
Jonathan Kelley 2024-03-13 15:11:41 -07:00
commit c532d3ec1a
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
8 changed files with 180 additions and 49 deletions

View file

@ -53,7 +53,6 @@ jobs:
with:
cache-all-crates: "true"
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: ilammy/setup-nasm@v1
- run: cargo check --all --examples --tests --all-features --all-targets
test:
@ -69,7 +68,6 @@ jobs:
with:
cache-all-crates: "true"
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: ilammy/setup-nasm@v1
- uses: davidB/rust-cargo-make@v1
- uses: browser-actions/setup-firefox@latest
- uses: jetli/wasm-pack-action@v0.4.0
@ -87,7 +85,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ilammy/setup-nasm@v1
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
@ -105,7 +102,6 @@ jobs:
- uses: actions/checkout@v4
- run: sudo apt-get update
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
- uses: ilammy/setup-nasm@v1
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
@ -149,7 +145,6 @@ jobs:
steps:
# Do our best to cache the toolchain and node install steps
- uses: actions/checkout@v4
- uses: ilammy/setup-nasm@v1
- uses: actions/setup-node@v4
with:
node-version: 16
@ -235,7 +230,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ilammy/setup-nasm@v1
- name: install stable
uses: dtolnay/rust-toolchain@master
with:

View file

@ -48,7 +48,6 @@ jobs:
with:
cache-all-crates: "true"
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: ilammy/setup-nasm@v1
- name: cargo doc
run: cargo doc --no-deps --workspace --all-features

View file

@ -54,7 +54,6 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: "true"
- uses: ilammy/setup-nasm@v1
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
@ -123,7 +122,6 @@ jobs:
toolchain: "1.70.0"
targets: ${{ matrix.platform.target }}
- uses: ilammy/setup-nasm@v1
- name: Setup cache
uses: Swatinem/rust-cache@v2

57
Cargo.lock generated
View file

@ -2178,7 +2178,7 @@ version = "0.5.0-alpha.0"
dependencies = [
"criterion 0.3.6",
"dioxus-config-macro",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-core-macro",
"dioxus-desktop",
"dioxus-fullstack",
@ -2245,7 +2245,7 @@ dependencies = [
"dioxus-autofmt",
"dioxus-check",
"dioxus-cli-config",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-hot-reload",
"dioxus-html",
"dioxus-rsx",
@ -2335,6 +2335,20 @@ dependencies = [
"tracing-subscriber",
]
[[package]]
name = "dioxus-core"
version = "0.5.0-alpha.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f39bef0484998f724622964f04468ddfde7fd550f5f0f1aef9394306e9caba44"
dependencies = [
"futures-channel",
"futures-util",
"longest-increasing-subsequence",
"rustc-hash",
"slab",
"tracing",
]
[[package]]
name = "dioxus-core-macro"
version = "0.5.0-alpha.0"
@ -2365,7 +2379,7 @@ dependencies = [
"core-foundation",
"dioxus",
"dioxus-cli-config",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-hooks",
"dioxus-hot-reload",
"dioxus-html",
@ -2466,7 +2480,7 @@ name = "dioxus-hooks"
version = "0.5.0-alpha.0"
dependencies = [
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-debug-cell",
"dioxus-signals",
"futures-channel",
@ -2484,7 +2498,7 @@ name = "dioxus-hot-reload"
version = "0.5.0-alpha.0"
dependencies = [
"chrono",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-html",
"dioxus-rsx",
"execute",
@ -2501,7 +2515,7 @@ name = "dioxus-html"
version = "0.5.0-alpha.0"
dependencies = [
"async-trait",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-html-internal-macro",
"dioxus-rsx",
"enumset",
@ -2534,7 +2548,7 @@ dependencies = [
name = "dioxus-interpreter-js"
version = "0.5.0-alpha.0"
dependencies = [
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-html",
"js-sys",
"md5",
@ -2550,7 +2564,7 @@ name = "dioxus-lib"
version = "0.5.0-alpha.0"
dependencies = [
"dioxus-config-macro",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-core-macro",
"dioxus-hooks",
"dioxus-html",
@ -2565,7 +2579,7 @@ dependencies = [
"axum",
"dioxus",
"dioxus-cli-config",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-hot-reload",
"dioxus-html",
"dioxus-interpreter-js",
@ -2599,7 +2613,7 @@ dependencies = [
"anymap 1.0.0-beta.2",
"dashmap",
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-native-core",
"dioxus-native-core-macro",
"keyboard-types",
@ -2708,7 +2722,7 @@ dependencies = [
name = "dioxus-rsx"
version = "0.5.0-alpha.0"
dependencies = [
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"internment",
"krates",
"proc-macro2",
@ -2723,7 +2737,7 @@ name = "dioxus-signals"
version = "0.5.0-alpha.0"
dependencies = [
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"futures-channel",
"futures-util",
"generational-box",
@ -2747,7 +2761,7 @@ dependencies = [
"async-trait",
"chrono",
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-html",
"dioxus-signals",
"fern",
@ -2778,7 +2792,7 @@ dependencies = [
"criterion 0.3.6",
"crossterm 0.26.1",
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-hot-reload",
"dioxus-html",
"dioxus-native-core",
@ -2796,7 +2810,7 @@ dependencies = [
"async-trait",
"console_error_panic_hook",
"dioxus",
"dioxus-core",
"dioxus-core 0.5.0-alpha.0",
"dioxus-html",
"dioxus-interpreter-js",
"dioxus-ssr",
@ -5702,10 +5716,11 @@ dependencies = [
[[package]]
name = "manganis"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c10916db4ed51967d92545eb5629ce1e1cc05c74da2cd2aab6ab6c57c2e838b6"
checksum = "a42db80aa639f70d6bf1d2ef93612d2ffbb33f6ea17d473b91bfeb3f67bc24bc"
dependencies = [
"dioxus-core 0.5.0-alpha.0 (registry+https://github.com/rust-lang/crates.io-index)",
"manganis-macro",
]
@ -5738,9 +5753,9 @@ dependencies = [
[[package]]
name = "manganis-common"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82ee0f9002a9f5d7e3b662e55562996c60401bae16da23f3790c52e0823216ea"
checksum = "176dfb4bb5592b0d130176add9893af527ab565fc1bcf58ece88acd6276688d1"
dependencies = [
"anyhow",
"base64",
@ -5754,9 +5769,9 @@ dependencies = [
[[package]]
name = "manganis-macro"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da50cc6074480dc6c255a09c9d48dd4a379e6162feb5d308ec33d5ba9da4e579"
checksum = "ab2c2e11190c2f3d6133cffda5c955b463a7e90b7ba866e71e7dfa65fa97ddfc"
dependencies = [
"manganis-common",
"proc-macro2",

View file

@ -100,8 +100,10 @@ thiserror = "1.0.40"
prettyplease = { package = "prettier-please", version = "0.2", features = [
"verbatim",
] }
manganis-cli-support = { version = "0.2.0", features = ["webp", "html"] }
manganis = { version = "0.2.0" }
manganis-cli-support = { version = "0.2.1", features = [
"html",
] }
manganis = { version = "0.2.1" }
interprocess = { version = "1.2.1" }
# interprocess = { git = "https://github.com/kotauskas/interprocess" }

View file

@ -41,8 +41,9 @@ tower = { workspace = true }
dioxus = { workspace = true }
[features]
default = ["hot-reload"]
default = ["hot-reload", "multi-thread"]
axum = ["dep:axum"]
multi-thread = ["tokio/rt-multi-thread"]
hot-reload = ["dioxus-hot-reload"]
[[example]]

View file

@ -9,22 +9,23 @@ pub fn launch(
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_config: Config,
) {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async move {
platform_config
.with_virtual_dom(move || {
let mut virtual_dom = VirtualDom::new(root);
#[cfg(feature = "multi-threaded")]
let mut builder = tokio::runtime::Builder::new_multi_thread();
#[cfg(not(feature = "multi-threaded"))]
let mut builder = tokio::runtime::Builder::new_current_thread();
for context in &contexts {
virtual_dom.insert_any_root_context(context());
}
builder.enable_all().build().unwrap().block_on(async move {
platform_config
.with_virtual_dom(move || {
let mut virtual_dom = VirtualDom::new(root);
virtual_dom
})
.launch()
.await;
});
for context in &contexts {
virtual_dom.insert_any_root_context(context());
}
virtual_dom
})
.launch()
.await;
});
}

View file

@ -162,6 +162,127 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
pub fn id(&self) -> generational_box::GenerationalBoxId {
self.inner.id()
}
/// **This pattern is no longer recommended. Prefer [`peek`](Signal::peek) or creating new signals instead.**
///
/// This function is the equivalent of the [write_silent](https://docs.rs/dioxus/latest/dioxus/prelude/struct.UseRef.html#method.write_silent) method on use_ref.
///
/// ## What you should use instead
///
/// ### Reading and Writing to data in the same scope
///
/// Reading and writing to the same signal in the same scope will cause that scope to rerun forever:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// let mut signal = use_signal(|| 0);
/// // This makes the scope rerun whenever we write to the signal
/// println!("{}", *signal.read());
/// // This will rerun the scope because we read the signal earlier in the same scope
/// *signal.write() += 1;
/// ```
///
/// You may have used the write_silent method to avoid this infinite loop with use_ref like this:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// let signal = use_signal(|| 0);
/// // This makes the scope rerun whenever we write to the signal
/// println!("{}", *signal.read());
/// // Write silent will not rerun any subscribers
/// *signal.write_silent() += 1;
/// ```
///
/// Instead you can use the [`peek`](Signal::peek) and [`write`](Signal::write) methods instead. The peek method will not subscribe to the current scope which will avoid an infinite loop if you are reading and writing to the same signal in the same scope.
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// let mut signal = use_signal(|| 0);
/// // Peek will read the value but not subscribe to the current scope
/// println!("{}", *signal.peek());
/// // Write will update any subscribers which does not include the current scope
/// *signal.write() += 1;
/// ```
///
/// ### Reading and Writing to different data
///
///
///
/// ## Why is this pattern no longer recommended?
///
/// This pattern is no longer recommended because it is very easy to allow your state and UI to grow out of sync. `write_silent` globally opts out of automatic state updates which can be difficult to reason about.
///
///
/// Lets take a look at an example:
/// main.rs:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # fn Child() -> Element { todo!() }
/// fn app() -> Element {
/// let signal = use_context_provider(|| Signal::new(0));
///
/// // We want to log the value of the signal whenever the app component reruns
/// println!("{}", *signal.read());
///
/// rsx! {
/// button {
/// // If we don't want to rerun the app component when the button is clicked, we can use write_silent
/// onclick: move |_| *signal.write_silent() += 1,
/// "Increment"
/// }
/// Child {}
/// }
/// }
/// ```
/// child.rs:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// fn Child() -> Element {
/// let signal: Signal<i32> = use_context();
///
/// // It is difficult to tell that changing the button to use write_silent in the main.rs file will cause UI to be out of sync in a completely different file
/// rsx! {
/// "{signal}"
/// }
/// }
/// ```
///
/// Instead [`peek`](Signal::peek) locally opts out of automatic state updates explicitly for a specific read which is easier to reason about.
///
/// Here is the same example using peek:
/// main.rs:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # fn Child() -> Element { todo!() }
/// fn app() -> Element {
/// let mut signal = use_context_provider(|| Signal::new(0));
///
/// // We want to log the value of the signal whenever the app component reruns, but we don't want to rerun the app component when the signal is updated so we use peek instead of read
/// println!("{}", *signal.peek());
///
/// rsx! {
/// button {
/// // We can use write like normal and update the child component automatically
/// onclick: move |_| *signal.write() += 1,
/// "Increment"
/// }
/// Child {}
/// }
/// }
/// ```
/// child.rs:
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// fn Child() -> Element {
/// let signal: Signal<i32> = use_context();
///
/// rsx! {
/// "{signal}"
/// }
/// }
/// ```
#[track_caller]
#[deprecated = "This pattern is no longer recommended. Prefer `peek` or creating new signals instead."]
pub fn write_silent(&self) -> S::Mut<'static, T> {
S::map_mut(self.inner.write_unchecked(), |inner| &mut inner.value)
}
}
impl<T, S: Storage<SignalData<T>>> Readable for Signal<T, S> {