From 6c9f991f0b4f25aba8b90d12029986a690c0131d Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 20 Mar 2024 09:54:57 -0700 Subject: [PATCH] hotfix: finding hotreload path fails when not running under cargo --- packages/cli/src/server/web/hot_reload.rs | 9 ++++++++- packages/fullstack/src/axum_adapter.rs | 3 +++ packages/hot-reload/src/lib.rs | 13 +++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/server/web/hot_reload.rs b/packages/cli/src/server/web/hot_reload.rs index d57bfb330..4c645ff2e 100644 --- a/packages/cli/src/server/web/hot_reload.rs +++ b/packages/cli/src/server/web/hot_reload.rs @@ -49,7 +49,14 @@ async fn hotreload_loop(mut socket: WebSocket, state: HotReloadState) -> anyhow: let msg = futures_util::select! { msg = _rx => msg, - _ = _socket => break, + e = _socket => { + if let Some(Err(e)) = e { + log::info!("🔥 Hot Reload WebSocket disconnected: {}", e); + break; + } else { + continue; + } + }, }; let Ok(msg) = msg else { break }; diff --git a/packages/fullstack/src/axum_adapter.rs b/packages/fullstack/src/axum_adapter.rs index df1485372..cc23d5345 100644 --- a/packages/fullstack/src/axum_adapter.rs +++ b/packages/fullstack/src/axum_adapter.rs @@ -441,6 +441,7 @@ pub async fn hot_reload_handler(ws: axum::extract::WebSocketUpgrade) -> impl Int let mut rx = tokio_stream::wrappers::WatchStream::from_changes(state.message_receiver.clone()); + while let Some(change) = rx.next().await { if let Some(template) = change { let template = { serde_json::to_string(&template).unwrap() }; @@ -449,6 +450,8 @@ pub async fn hot_reload_handler(ws: axum::extract::WebSocketUpgrade) -> impl Int }; } } + + println!("😳 Hot Reload WebSocket disconnected"); }) } diff --git a/packages/hot-reload/src/lib.rs b/packages/hot-reload/src/lib.rs index 3f5c9abf9..021843b66 100644 --- a/packages/hot-reload/src/lib.rs +++ b/packages/hot-reload/src/lib.rs @@ -30,12 +30,15 @@ pub enum HotReloadMsg { /// Connect to the hot reloading listener. The callback provided will be called every time a template change is detected pub fn connect(callback: impl FnMut(HotReloadMsg) + Send + 'static) { - let Ok(_manifest_dir) = std::env::var("CARGO_MANIFEST_DIR") else { - return; - }; + // FIXME: this is falling back onto the current directory when not running under cargo, which is how the CLI runs this. + // This needs to be fixed. + let _manifest_dir = std::env::var("CARGO_MANIFEST_DIR"); // get the cargo manifest directory, where the target dir lives - let mut path = PathBuf::from(_manifest_dir); + let mut path = match _manifest_dir { + Ok(manifest_dir) => PathBuf::from(manifest_dir), + Err(_) => std::env::current_dir().unwrap(), + }; // walk the path until we a find a socket named `dioxusin` inside that folder's target directory loop { @@ -53,6 +56,8 @@ pub fn connect(callback: impl FnMut(HotReloadMsg) + Send + 'static) { }; } + println!("connecting to {:?}", path); + connect_at(path, callback); }