From dc6ea152eebf6910139e0e6218a081a262976ab7 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 20 Sep 2023 14:34:47 -0500 Subject: [PATCH 01/53] fix playwright tests on windows --- playwright-tests/playwright.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright-tests/playwright.config.js b/playwright-tests/playwright.config.js index 54fe810a7..b4b0c4041 100644 --- a/playwright-tests/playwright.config.js +++ b/playwright-tests/playwright.config.js @@ -90,7 +90,7 @@ module.exports = defineConfig({ }, { cwd: path.join(process.cwd(), 'fullstack'), - command: 'cargo run --package dioxus-cli -- build --features web --release\ncargo run --release --features ssr', + command: 'cargo run --package dioxus-cli -- build --features web --release && cargo run --release --features ssr', port: 3333, timeout: 10 * 60 * 1000, reuseExistingServer: !process.env.CI, From 517a43d7659680a05c1705426f9d5da55579458e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Esp=C3=ADn?= Date: Mon, 25 Sep 2023 15:31:35 +0200 Subject: [PATCH 02/53] fix: Update server function docs link (#1489) --- packages/server-macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server-macro/src/lib.rs b/packages/server-macro/src/lib.rs index d00c009d0..7cdc470d9 100644 --- a/packages/server-macro/src/lib.rs +++ b/packages/server-macro/src/lib.rs @@ -8,7 +8,7 @@ use syn::{ Ident, ItemFn, Token, }; -/// Declares that a function is a [server function](dioxus_fullstack). This means that +/// Declares that a function is a [server function](https://dioxuslabs.com/learn/0.4/reference/fullstack/server_functions). This means that /// its body will only run on the server, i.e., when the `ssr` feature is enabled. /// /// If you call a server function from the client (i.e., when the `csr` or `hydrate` features From 31780b3ede85b2fe198aeec178d6277686b04f2f Mon Sep 17 00:00:00 2001 From: Seungwoo Kang Date: Wed, 27 Sep 2023 06:35:17 +0900 Subject: [PATCH 03/53] liveview: Add `interpreter_glue_relative_uri (#1481) * liveview: Add `interpreter_glue_relative_uri` By utilizing `window.location.host` in the client-side JavaScript, we can easily derive the WebSocket URI from a relative path URI. This approach obviates the need for host address retrieval on the server side, unlike the method of serving glue code in liveview using `interpreter_glue`. * liveview: Merge `.._relative_url` functionality - Merged `.._relative_url` to current API `interpreter_glue`. - Edit axum example to work with new feature. * liveview: Fix clippy warning --- packages/liveview/examples/axum.rs | 61 ++++++++++++++++++------------ packages/liveview/src/lib.rs | 41 ++++++++++++++++++-- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/packages/liveview/examples/axum.rs b/packages/liveview/examples/axum.rs index 2e7f10ee7..6584d5e9b 100644 --- a/packages/liveview/examples/axum.rs +++ b/packages/liveview/examples/axum.rs @@ -19,32 +19,43 @@ async fn main() { let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into(); let view = dioxus_liveview::LiveViewPool::new(); + let index_page_with_glue = |glue: &str| { + Html(format!( + r#" + + + Dioxus LiveView with axum +
+ {glue} + + "#, + )) + }; - let app = Router::new() - .route( - "/", - get(move || async move { - Html(format!( - r#" - - - Dioxus LiveView with axum -
- {glue} - - "#, - glue = dioxus_liveview::interpreter_glue(&format!("ws://{addr}/ws")) - )) - }), - ) - .route( - "/ws", - get(move |ws: WebSocketUpgrade| async move { - ws.on_upgrade(move |socket| async move { - _ = view.launch(dioxus_liveview::axum_socket(socket), app).await; - }) - }), - ); + let app = + Router::new() + .route( + "/", + get(move || async move { + index_page_with_glue(&dioxus_liveview::interpreter_glue(&format!( + "ws://{addr}/ws" + ))) + }), + ) + .route( + "/as-path", + get(move || async move { + index_page_with_glue(&dioxus_liveview::interpreter_glue("/ws")) + }), + ) + .route( + "/ws", + get(move |ws: WebSocketUpgrade| async move { + ws.on_upgrade(move |socket| async move { + _ = view.launch(dioxus_liveview::axum_socket(socket), app).await; + }) + }), + ); println!("Listening on http://{addr}"); diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs index 92cce63e6..a7370e91c 100644 --- a/packages/liveview/src/lib.rs +++ b/packages/liveview/src/lib.rs @@ -93,14 +93,49 @@ static MAIN_JS: &str = include_str!("./main.js"); /// This script that gets injected into your app connects this page to the websocket endpoint /// /// Once the endpoint is connected, it will send the initial state of the app, and then start -/// processing user events and returning edits to the liveview instance -pub fn interpreter_glue(url: &str) -> String { +/// processing user events and returning edits to the liveview instance. +/// +/// You can pass a relative path prefixed with "/", or enter a full URL including the protocol +/// (`ws:` or `wss:`) as an argument. +/// +/// If you enter a relative path, the web client automatically prefixes the host address in +/// `window.location` when creating a web socket to LiveView. +/// +/// ``` +/// // Creates websocket connection to same host as current page +/// interpreter_glue("/api/liveview"); +/// +/// // Creates websocket connection to specified url +/// interpreter_glue("ws://localhost:8080/api/liveview"); +/// ``` +pub fn interpreter_glue(url_or_path: &str) -> String { + // If the url starts with a `/`, generate glue which reuses current host + let get_ws_url = if url_or_path.starts_with('/') { + r#" + let loc = window.location; + let new_url = ""; + if (loc.protocol === "https:") {{ + new_url = "wss:"; + }} else {{ + new_url = "ws:"; + }} + new_url += "//" + loc.host + path; + return new_url; + "# + } else { + "return path;" + }; + let js = &*INTERPRETER_JS; let common = &*COMMON_JS; format!( r#"