From 4045351e732f82b9dde6b9f24d7f9796428c80ba Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 30 May 2024 15:27:25 -0500 Subject: [PATCH 1/8] fix sdk storage with hydration --- Cargo.toml | 9 +- examples/storage/.gitignore | 1 + examples/storage/Cargo.toml | 13 ++- examples/storage/README.md | 6 ++ examples/storage/src/main.rs | 15 ++-- sdk/Cargo.toml | 2 +- sdk/src/storage/mod.rs | 147 ++++++++++++++++++++++----------- sdk/src/storage/persistence.rs | 15 ++-- 8 files changed, 139 insertions(+), 69 deletions(-) create mode 100644 examples/storage/.gitignore diff --git a/Cargo.toml b/Cargo.toml index 492bc04..6f18770 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,13 @@ [workspace] resolver = "2" members = ["sdk", "examples/*"] +# We exclude the storage example from the workspace so that the dioxus features for other renderers are not enabled +exclude = ["examples/storage"] [workspace.dependencies] dioxus-sdk = { path = "./sdk" } -dioxus = { version = "0.5" } -dioxus-web = { version = "0.5" } -dioxus-desktop = { version = "0.5" } +# dioxus = { version = "0.5" } +# dioxus-desktop = { version = "0.5" } +dioxus = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5" } +dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5" } \ No newline at end of file diff --git a/examples/storage/.gitignore b/examples/storage/.gitignore new file mode 100644 index 0000000..b9b3041 --- /dev/null +++ b/examples/storage/.gitignore @@ -0,0 +1 @@ +/.dioxus \ No newline at end of file diff --git a/examples/storage/Cargo.toml b/examples/storage/Cargo.toml index e427ee0..58724b5 100644 --- a/examples/storage/Cargo.toml +++ b/examples/storage/Cargo.toml @@ -4,9 +4,18 @@ version = "0.1.0" edition = "2021" [dependencies] -dioxus-sdk = { workspace = true, features = ["storage"] } -dioxus = { workspace = true, features = ["router"] } +dioxus-sdk = { path = "../../sdk", features = ["storage"] } +dioxus = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5", features = ["router"] } [features] web = ["dioxus/web"] desktop = ["dioxus/desktop"] +fullstack = ["dioxus/fullstack"] +server = ["dioxus/axum"] + +# # Fullstack support requires a patch from 0.5.2 +# [patch.crates-io] +# dioxus = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +# dioxus-core = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +# dioxus-hooks = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +# dioxus-signals = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } diff --git a/examples/storage/README.md b/examples/storage/README.md index c4fcc03..76f71a9 100644 --- a/examples/storage/README.md +++ b/examples/storage/README.md @@ -14,3 +14,9 @@ Web: ```sh dioxus serve --features web ``` + +Fullstack: + +```sh +dioxus serve --platform fullstack --features fullstack +``` diff --git a/examples/storage/src/main.rs b/examples/storage/src/main.rs index 7e93d63..45d9dbe 100644 --- a/examples/storage/src/main.rs +++ b/examples/storage/src/main.rs @@ -1,5 +1,4 @@ use dioxus::prelude::*; -use dioxus_router::prelude::*; use dioxus_sdk::storage::*; fn main() { @@ -18,9 +17,9 @@ fn app() -> Element { enum Route { #[layout(Footer)] #[route("/")] - Page1 {}, - #[route("/page2")] - Page2 {}, + Home {}, + #[route("/storage")] + Storage {}, } #[component] @@ -61,8 +60,8 @@ fn Footer() -> Element { nav { ul { - li { Link { to: Route::Page1 {}, "Page1" } } - li { Link { to: Route::Page2 {}, "Page2" } } + li { Link { to: Route::Home {}, "Home" } } + li { Link { to: Route::Storage {}, "Storage" } } } } } @@ -70,12 +69,12 @@ fn Footer() -> Element { } #[component] -fn Page1() -> Element { +fn Home() -> Element { rsx!("Home") } #[component] -fn Page2() -> Element { +fn Storage() -> Element { let mut count_session = use_singleton_persistent(|| 0); let mut count_local = use_synced_storage::("synced".to_string(), || 0); diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index cac84b2..49ebbaf 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -144,7 +144,7 @@ unic-langid = { version = "0.9.1", features = ["serde"], optional = true } rustc-hash = { version = "1.1.0", optional = true } postcard = { version = "1.0.2", features = ["use-std"], optional = true } once_cell = { version = "1.17.0", optional = true } -dioxus-signals = { version = "0.5.0-alpha.2", features = [ +dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5", features = [ "serialize", ], optional = true } diff --git a/sdk/src/storage/mod.rs b/sdk/src/storage/mod.rs index 9635020..9d31b7a 100644 --- a/sdk/src/storage/mod.rs +++ b/sdk/src/storage/mod.rs @@ -31,6 +31,8 @@ use futures_util::stream::StreamExt; pub use persistence::{ new_persistent, new_singleton_persistent, use_persistent, use_singleton_persistent, }; +use std::cell::RefCell; +use std::rc::Rc; use dioxus::prelude::*; use postcard::to_allocvec; @@ -68,7 +70,32 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - use_hook(|| new_storage::(key, init)) + let mut init = Some(init); + let storage = use_hook(|| new_storage::(key, || init.take().unwrap()())); + use_hydrate_storage_hook::(storage, init); + storage +} + +#[allow(unused)] +enum StorageMode { + Client, + HydrateClient, + Server, +} + +impl StorageMode { + // Get the active mode + const fn current() -> Self { + server_only! { + return StorageMode::Server; + } + + fullstack! { + return StorageMode::HydrateClient; + } + + StorageMode::Client + } } /// Creates a Signal that can be used to store data that will persist across application reloads. @@ -93,30 +120,18 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - let mut init = Some(init); + let mode = StorageMode::current(); - if cfg!(feature = "ssr") { + match mode { // SSR does not support storage on the backend. We will just use a normal Signal to represent the initial state. // The client will hydrate this with a correct StorageEntry and maintain state. - Signal::new(init.take().unwrap()()) - } else if cfg!(feature = "hydrate") { - let key_clone = key.clone(); - let mut storage_entry = new_storage_entry::(key, init.take().unwrap()); - if generation() == 0 { - // The first generation is rendered on the server side and so must be hydrated. - needs_update(); - } - if generation() == 1 { - // The first time the vdom is hydrated, we set the correct value from storage and set up the subscription to storage events. - storage_entry.set(get_from_storage::(key_clone, init.take().unwrap())); + StorageMode::Server => Signal::new(init()), + _ => { + // Otherwise the client is rendered normally, so we can just use the storage entry. + let storage_entry = new_storage_entry::(key, init); storage_entry.save_to_storage_on_change(); + storage_entry.data } - storage_entry.data - } else { - // The client is rendered normally, so we can just use the storage entry. - let storage_entry = new_storage_entry::(key, init.take().unwrap()); - storage_entry.save_to_storage_on_change(); - storage_entry.data } } @@ -130,7 +145,10 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - use_hook(|| new_synced_storage::(key, init)) + let mut init = Some(init); + let storage = use_hook(|| new_synced_storage::(key, || init.take().unwrap()())); + use_hydrate_storage_hook::(storage, init); + storage } /// Create a signal that can be used to store data that will persist across application reloads and be synced across all app sessions for a given installation or browser. @@ -143,34 +161,20 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - let mut init = Some(init); let signal = { - if cfg!(feature = "ssr") { + let mode = StorageMode::current(); + + match mode { // SSR does not support synced storage on the backend. We will just use a normal Signal to represent the initial state. // The client will hydrate this with a correct SyncedStorageEntry and maintain state. - Signal::new(init.take().unwrap()()) - } else if cfg!(feature = "hydrate") { - let key_clone = key.clone(); - let mut storage_entry = new_synced_storage_entry::(key, init.take().unwrap()); - if generation() == 0 { - // The first generation is rendered on the server side and so must be hydrated. - needs_update(); - } - if generation() == 1 { - // The first time the vdom is hydrated, we set the correct value from storage and set up the subscription to storage events. - storage_entry - .entry - .set(get_from_storage::(key_clone, init.take().unwrap())); + StorageMode::Server => Signal::new(init()), + _ => { + // The client is rendered normally, so we can just use the synced storage entry. + let storage_entry = new_synced_storage_entry::(key, init); storage_entry.save_to_storage_on_change(); storage_entry.subscribe_to_storage(); + *storage_entry.data() } - *storage_entry.data() - } else { - // The client is rendered normally, so we can just use the synced storage entry. - let storage_entry = new_synced_storage_entry::(key, init.take().unwrap()); - storage_entry.save_to_storage_on_change(); - storage_entry.subscribe_to_storage(); - *storage_entry.data() } }; signal @@ -183,7 +187,10 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - use_hook(|| new_storage_entry::(key, init)) + let mut init = Some(init); + let signal = use_hook(|| new_storage_entry::(key, || init.take().unwrap()())); + use_hydrate_storage_hook::(*signal.data(), init); + signal } /// A hook that creates a StorageEntry with the latest value from storage or the init value if it doesn't exist, and provides a channel to subscribe to updates to the underlying storage. @@ -196,7 +203,10 @@ where T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, S::Key: Clone, { - use_hook(|| new_synced_storage_entry::(key, init)) + let mut init = Some(init); + let signal = use_hook(|| new_synced_storage_entry::(key, || init.take().unwrap()())); + use_hydrate_storage_hook::(*signal.data(), init); + signal } /// Returns a StorageEntry with the latest value from storage or the init value if it doesn't exist. @@ -264,15 +274,16 @@ pub trait StorageEntryTrait: T: Serialize + DeserializeOwned + Clone + PartialEq + 'static, { let entry_clone = self.clone(); - let old = Signal::new(self.data().cloned()); + let old = RefCell::new(None); let data = *self.data(); spawn(async move { loop { let (rc, mut reactive_context) = ReactiveContext::new(); rc.run_in(|| { - if *old.read() != *data.read() { + if old.borrow().as_ref() != Some(&*data.read()) { tracing::trace!("Saving to storage"); entry_clone.save(); + old.replace(Some(data())); } }); if reactive_context.next().await.is_none() { @@ -574,8 +585,46 @@ pub(crate) fn try_serde_from_string(value: &str) -> Option< match yazi::decompress(&bytes, yazi::Format::Zlib) { Ok((decompressed, _)) => match postcard::from_bytes(&decompressed) { Ok(v) => Some(v), - Err(err) => None, + Err(_) => None, }, - Err(err) => None, + Err(_) => None, } } + +// Take a signal and a storage key and hydrate the value if we are hydrating the client. +pub(crate) fn use_hydrate_storage_hook( + mut signal: Signal, + init: Option T>, +) -> Signal +where + S: StorageBacking, + T: Serialize + DeserializeOwned + Clone + Send + Sync + PartialEq + 'static, + S::Key: Clone, +{ + let mode = StorageMode::current(); + // We read the value from storage and store it here if we are hydrating the client. + let original_storage_value: Rc>> = use_hook(|| Rc::new(RefCell::new(None))); + + // If we are not hydrating the client + if let StorageMode::HydrateClient = mode { + if generation() == 0 { + // We always use the default value for the first render. + if let Some(default_value) = init { + // Read the value from storage before we reset it for hydration + original_storage_value + .borrow_mut() + .replace(signal.peek().clone()); + signal.set(default_value()); + } + // And we trigger a new render for after hydration + needs_update(); + } + if generation() == 1 { + // After we hydrate, set the original value from storage + if let Some(original_storage_value) = original_storage_value.borrow_mut().take() { + signal.set(original_storage_value); + } + } + } + signal +} diff --git a/sdk/src/storage/persistence.rs b/sdk/src/storage/persistence.rs index e7eb76e..dc2dab4 100644 --- a/sdk/src/storage/persistence.rs +++ b/sdk/src/storage/persistence.rs @@ -1,5 +1,5 @@ -use crate::storage::new_storage_entry; use crate::storage::SessionStorage; +use crate::storage::{new_storage_entry, use_hydrate_storage_hook}; use dioxus::prelude::*; use dioxus_signals::Signal; use serde::de::DeserializeOwned; @@ -10,20 +10,21 @@ use super::StorageEntryTrait; /// A persistent storage hook that can be used to store data across application reloads. /// /// Depending on the platform this uses either local storage or a file storage -#[allow(clippy::needless_return)] pub fn use_persistent< T: Serialize + DeserializeOwned + Default + Clone + Send + Sync + PartialEq + 'static, >( key: impl ToString, init: impl FnOnce() -> T, ) -> Signal { - use_hook(|| new_persistent(key, init)) + let mut init = Some(init); + let storage = use_hook(|| new_persistent(key.to_string(), || init.take().unwrap()())); + use_hydrate_storage_hook::(storage, init); + storage } /// Creates a persistent storage signal that can be used to store data across application reloads. /// /// Depending on the platform this uses either local storage or a file storage -#[allow(clippy::needless_return)] pub fn new_persistent< T: Serialize + DeserializeOwned + Default + Clone + Send + Sync + PartialEq + 'static, >( @@ -39,14 +40,16 @@ pub fn new_persistent< /// The state will be the same for every call to this hook from the same line of code. /// /// Depending on the platform this uses either local storage or a file storage -#[allow(clippy::needless_return)] #[track_caller] pub fn use_singleton_persistent< T: Serialize + DeserializeOwned + Default + Clone + Send + Sync + PartialEq + 'static, >( init: impl FnOnce() -> T, ) -> Signal { - use_hook(|| new_singleton_persistent(init)) + let mut init = Some(init); + let signal = use_hook(|| new_singleton_persistent(|| init.take().unwrap()())); + use_hydrate_storage_hook::(signal, init); + signal } /// Create a persistent storage signal that can be used to store data across application reloads. From 8dd85a6a2c1b727f25646874652ba8d16123785a Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 30 May 2024 15:30:24 -0500 Subject: [PATCH 2/8] use dioxus 0.5 everywhere except the fullstack storage example --- Cargo.toml | 6 ++---- examples/storage/Cargo.toml | 14 +++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6f18770..7bf931e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,5 @@ exclude = ["examples/storage"] [workspace.dependencies] dioxus-sdk = { path = "./sdk" } -# dioxus = { version = "0.5" } -# dioxus-desktop = { version = "0.5" } -dioxus = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5" } -dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5" } \ No newline at end of file +dioxus = { version = "0.5" } +dioxus-desktop = { version = "0.5" } diff --git a/examples/storage/Cargo.toml b/examples/storage/Cargo.toml index 58724b5..d6fcdb6 100644 --- a/examples/storage/Cargo.toml +++ b/examples/storage/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] dioxus-sdk = { path = "../../sdk", features = ["storage"] } -dioxus = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5", features = ["router"] } +dioxus = { version = "0.5", features = ["router"] } [features] web = ["dioxus/web"] @@ -13,9 +13,9 @@ desktop = ["dioxus/desktop"] fullstack = ["dioxus/fullstack"] server = ["dioxus/axum"] -# # Fullstack support requires a patch from 0.5.2 -# [patch.crates-io] -# dioxus = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -# dioxus-core = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -# dioxus-hooks = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -# dioxus-signals = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +# Fullstack support requires a patch from 0.5.2 +[patch.crates-io] +dioxus = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +dioxus-core = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +dioxus-hooks = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } +dioxus-signals = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } From aae3774fe9afe0a69336193a164566eb948b3958 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 3 Jun 2024 14:22:30 -0500 Subject: [PATCH 3/8] restore dioxus version for the main package --- sdk/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 49ebbaf..1df1d1f 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -144,7 +144,7 @@ unic-langid = { version = "0.9.1", features = ["serde"], optional = true } rustc-hash = { version = "1.1.0", optional = true } postcard = { version = "1.0.2", features = ["use-std"], optional = true } once_cell = { version = "1.17.0", optional = true } -dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus", branch = "v0.5", features = [ +dioxus-signals = { version = "0.5.0", features = [ "serialize", ], optional = true } From 4c7871f64c491e5e5e730750d402badd374477a1 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 21 Jun 2024 15:32:25 -0700 Subject: [PATCH 4/8] use the stable version of dioxus --- Cargo.toml | 2 -- examples/storage/Cargo.toml | 7 ------- 2 files changed, 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7bf931e..26047db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] resolver = "2" members = ["sdk", "examples/*"] -# We exclude the storage example from the workspace so that the dioxus features for other renderers are not enabled -exclude = ["examples/storage"] [workspace.dependencies] diff --git a/examples/storage/Cargo.toml b/examples/storage/Cargo.toml index d6fcdb6..f9df771 100644 --- a/examples/storage/Cargo.toml +++ b/examples/storage/Cargo.toml @@ -12,10 +12,3 @@ web = ["dioxus/web"] desktop = ["dioxus/desktop"] fullstack = ["dioxus/fullstack"] server = ["dioxus/axum"] - -# Fullstack support requires a patch from 0.5.2 -[patch.crates-io] -dioxus = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -dioxus-core = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -dioxus-hooks = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } -dioxus-signals = { git = "https://github.com/dioxuslabs/dioxus", branch = "v0.5" } From 9664934af2304bab2368e22ccbfdaa85afbddebc Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 22 Jun 2024 11:49:13 -0500 Subject: [PATCH 5/8] Update examples/storage/Cargo.toml Co-authored-by: Marc Espin --- examples/storage/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/storage/Cargo.toml b/examples/storage/Cargo.toml index f9df771..1139774 100644 --- a/examples/storage/Cargo.toml +++ b/examples/storage/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -dioxus-sdk = { path = "../../sdk", features = ["storage"] } -dioxus = { version = "0.5", features = ["router"] } +dioxus-sdk = { workspace = true, features = ["storage"] } +dioxus = { workspace = true, features = ["router"] } [features] web = ["dioxus/web"] From 4a5843e92f42d9418d3cad116aa97fd8f4f3f1b3 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 22 Jun 2024 11:49:18 -0500 Subject: [PATCH 6/8] Update examples/storage/README.md Co-authored-by: Marc Espin --- examples/storage/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/storage/README.md b/examples/storage/README.md index 76f71a9..e09cca4 100644 --- a/examples/storage/README.md +++ b/examples/storage/README.md @@ -12,7 +12,7 @@ dioxus serve --platform desktop --features desktop Web: ```sh -dioxus serve --features web +dx serve --features web ``` Fullstack: From a3f9594a030d64bbe9c69a52154a08efe365b949 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 22 Jun 2024 11:49:23 -0500 Subject: [PATCH 7/8] Update examples/storage/README.md Co-authored-by: Marc Espin --- examples/storage/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/storage/README.md b/examples/storage/README.md index e09cca4..90b6631 100644 --- a/examples/storage/README.md +++ b/examples/storage/README.md @@ -18,5 +18,5 @@ dx serve --features web Fullstack: ```sh -dioxus serve --platform fullstack --features fullstack +dx serve --platform fullstack --features fullstack ``` From 33b2046ac31bd97c7fa62531cff66db195e84b4d Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 22 Jun 2024 09:50:35 -0700 Subject: [PATCH 8/8] use_hydrate_storage_hook -> use_hydrate_storage --- sdk/src/storage/mod.rs | 10 +++++----- sdk/src/storage/persistence.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/src/storage/mod.rs b/sdk/src/storage/mod.rs index 196813a..2558967 100644 --- a/sdk/src/storage/mod.rs +++ b/sdk/src/storage/mod.rs @@ -74,7 +74,7 @@ where { let mut init = Some(init); let storage = use_hook(|| new_storage::(key, || init.take().unwrap()())); - use_hydrate_storage_hook::(storage, init); + use_hydrate_storage::(storage, init); storage } @@ -149,7 +149,7 @@ where { let mut init = Some(init); let storage = use_hook(|| new_synced_storage::(key, || init.take().unwrap()())); - use_hydrate_storage_hook::(storage, init); + use_hydrate_storage::(storage, init); storage } @@ -191,7 +191,7 @@ where { let mut init = Some(init); let signal = use_hook(|| new_storage_entry::(key, || init.take().unwrap()())); - use_hydrate_storage_hook::(*signal.data(), init); + use_hydrate_storage::(*signal.data(), init); signal } @@ -207,7 +207,7 @@ where { let mut init = Some(init); let signal = use_hook(|| new_synced_storage_entry::(key, || init.take().unwrap()())); - use_hydrate_storage_hook::(*signal.data(), init); + use_hydrate_storage::(*signal.data(), init); signal } @@ -594,7 +594,7 @@ pub(crate) fn try_serde_from_string(value: &str) -> Option< } // Take a signal and a storage key and hydrate the value if we are hydrating the client. -pub(crate) fn use_hydrate_storage_hook( +pub(crate) fn use_hydrate_storage( mut signal: Signal, init: Option T>, ) -> Signal diff --git a/sdk/src/storage/persistence.rs b/sdk/src/storage/persistence.rs index dc2dab4..9e7d947 100644 --- a/sdk/src/storage/persistence.rs +++ b/sdk/src/storage/persistence.rs @@ -1,5 +1,5 @@ use crate::storage::SessionStorage; -use crate::storage::{new_storage_entry, use_hydrate_storage_hook}; +use crate::storage::{new_storage_entry, use_hydrate_storage}; use dioxus::prelude::*; use dioxus_signals::Signal; use serde::de::DeserializeOwned; @@ -18,7 +18,7 @@ pub fn use_persistent< ) -> Signal { let mut init = Some(init); let storage = use_hook(|| new_persistent(key.to_string(), || init.take().unwrap()())); - use_hydrate_storage_hook::(storage, init); + use_hydrate_storage::(storage, init); storage } @@ -48,7 +48,7 @@ pub fn use_singleton_persistent< ) -> Signal { let mut init = Some(init); let signal = use_hook(|| new_singleton_persistent(|| init.take().unwrap()())); - use_hydrate_storage_hook::(signal, init); + use_hydrate_storage::(signal, init); signal }