Skip to content

Commit

Permalink
feat: playground hot-reload support
Browse files Browse the repository at this point in the history
  • Loading branch information
DogeDark committed Oct 25, 2024
1 parent 64a2e45 commit 6cd46e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/web/src/devtools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! This sets up a websocket connection to the devserver and handles messages from it.
//! We also set up a little recursive timer that will attempt to reconnect if the connection is lost.
#![allow(unused)]

use std::fmt::Display;
use std::time::Duration;
Expand All @@ -27,7 +28,8 @@ pub(crate) fn init() -> UnboundedReceiver<HotReloadMsg> {
let (tx, rx) = unbounded();

// Wire up the websocket to the devserver
make_ws(tx.clone(), POLL_INTERVAL_MIN, false);
#[cfg(not(feature = "devtools-playground"))]
make_ws(tx, POLL_INTERVAL_MIN, false);

#[cfg(feature = "devtools-playground")]
playground(tx);
Expand Down
15 changes: 12 additions & 3 deletions packages/web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ pub async fn run(mut virtual_dom: VirtualDom, web_config: Config) -> ! {
loop {
// if virtual dom has nothing, wait for it to have something before requesting idle time
// if there is work then this future resolves immediately.
#[cfg(all(feature = "devtools", debug_assertions))]
#[cfg(any(
all(feature = "devtools", debug_assertions),
feature = "devtools-playground"
))]
let template;
#[allow(unused)]
let mut hydration_work: Option<SuspenseMessage> = None;
Expand All @@ -147,7 +150,10 @@ pub async fn run(mut virtual_dom: VirtualDom, web_config: Config) -> ! {
.flatten();
let mut rx_hydration = hydration_receiver_iter.select_next_some();

#[cfg(all(feature = "devtools", debug_assertions))]
#[cfg(any(
all(feature = "devtools", debug_assertions),
feature = "devtools-playground"
))]
#[allow(unused)]
{
let mut devtools_next = hotreload_rx.select_next_some();
Expand Down Expand Up @@ -183,7 +189,10 @@ pub async fn run(mut virtual_dom: VirtualDom, web_config: Config) -> ! {
}
}

#[cfg(all(feature = "devtools", debug_assertions))]
#[cfg(any(
all(feature = "devtools", debug_assertions),
feature = "devtools-playground"
))]
if let Some(hr_msg) = template {
// Replace all templates
dioxus_devtools::apply_changes(&virtual_dom, &hr_msg);
Expand Down

0 comments on commit 6cd46e0

Please sign in to comment.