Skip to content

Commit 4a82da2

Browse files
fix(cli): use local ip address for reload (#6285)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 2dc71a4 commit 4a82da2

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

.changes/local-dev-path-mobile.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Fixes HMR on mobile when devPath is configured to load a filesystem path.

tooling/cli/src/helpers/auto-reload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// taken from https://github.com/thedodd/trunk/blob/5c799dc35f1f1d8f8d3d30c8723cbb761a9b6a08/src/autoreload.js
22

33
;(function () {
4-
var url = 'ws:' + '//' + window.location.host + '/_tauri-cli/ws'
4+
var url = '{{reload_url}}'
55
var poll_interval = 5000
66
var reload_upon_connect = () => {
77
window.setTimeout(() => {

tooling/cli/src/helpers/web_dev_server.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const AUTO_RELOAD_SCRIPT: &str = include_str!("./auto-reload.js");
2323

2424
struct State {
2525
serve_dir: PathBuf,
26+
address: SocketAddr,
2627
tx: Sender<()>,
2728
}
2829

@@ -60,8 +61,12 @@ pub fn start_dev_server<P: AsRef<Path>>(address: SocketAddr, path: P) {
6061
}
6162
});
6263

63-
let state = Arc::new(State { serve_dir, tx });
64-
let router = Router::new()
64+
let state = Arc::new(State {
65+
serve_dir,
66+
tx,
67+
address,
68+
});
69+
let server_router = Router::new()
6570
.fallback(
6671
Router::new().nest(
6772
"/",
@@ -73,13 +78,14 @@ pub fn start_dev_server<P: AsRef<Path>>(address: SocketAddr, path: P) {
7378
),
7479
)
7580
.route(
76-
"/_tauri-cli/ws",
81+
"/__tauri_cli",
7782
get(move |ws: WebSocketUpgrade| async move {
7883
ws.on_upgrade(|socket| async move { ws_handler(socket, state).await })
7984
}),
8085
);
86+
8187
Server::bind(&address)
82-
.serve(router.into_make_service())
88+
.serve(server_router.into_make_service())
8389
.await
8490
.unwrap();
8591
})
@@ -120,7 +126,10 @@ async fn handler<T>(req: Request<T>, state: Arc<State>) -> impl IntoResponse {
120126
with_html_head(&mut document, |head| {
121127
let script_el =
122128
NodeRef::new_element(QualName::new(None, ns!(html), "script".into()), None);
123-
script_el.append(NodeRef::new_text(AUTO_RELOAD_SCRIPT));
129+
script_el.append(NodeRef::new_text(AUTO_RELOAD_SCRIPT.replace(
130+
"{{reload_url}}",
131+
&format!("ws://{}/__tauri_cli", state.address),
132+
)));
124133
head.prepend(script_el);
125134
});
126135

0 commit comments

Comments
 (0)