Merge branch 'master' into jk/breaking-merged
This commit is contained in:
211 files changed
+21135
-3770
No files matched your search
@@ -16,18 +16,14 @@ dioxus_server_macro = { workspace = true }
|
||||
|
||||
# warp
|
||||
warp = { version = "0.3.5", features = ["compression-gzip"], optional = true }
|
||||
http-body = { version = "0.4.5", optional = true }
|
||||
http-body-util = "0.1.0-rc.2"
|
||||
|
||||
# axum
|
||||
axum = { version = "0.6.1", features = ["ws", "macros"], optional = true }
|
||||
axum = { version = "0.6.1", features = ["ws", "macros"], default-features = false, optional = true }
|
||||
tower-http = { version = "0.4.0", optional = true, features = ["fs", "compression-gzip"] }
|
||||
tower = { version = "0.4.13", features = ["util"], optional = true }
|
||||
axum-macros = "0.3.7"
|
||||
|
||||
# salvo
|
||||
salvo = { version = "0.63.0", optional = true, features = ["serve-static", "websocket", "compression"] }
|
||||
serde = "1.0.159"
|
||||
http-body-util = { version = "0.1.0-rc.2", optional = true }
|
||||
|
||||
# Dioxus + SSR
|
||||
dioxus = { workspace = true }
|
||||
@@ -45,24 +41,25 @@ dioxus-desktop = { workspace = true, optional = true }
|
||||
dioxus-router = { workspace = true, optional = true }
|
||||
|
||||
tracing = { workspace = true }
|
||||
tracing-futures = { workspace = true }
|
||||
tracing-futures = { workspace = true, optional = true }
|
||||
once_cell = "1.17.1"
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"], optional = true }
|
||||
tokio = { workspace = true, features = ["rt", "sync", "rt-multi-thread"], optional = true }
|
||||
tokio-util = { version = "0.7.8", features = ["rt"], optional = true }
|
||||
object-pool = "0.5.4"
|
||||
anymap = "0.12.1"
|
||||
anymap = { version = "0.12.1", optional = true }
|
||||
|
||||
serde = "1.0.159"
|
||||
serde_json = { version = "1.0.95", optional = true }
|
||||
tokio-stream = { version = "0.1.12", features = ["sync"], optional = true }
|
||||
futures-util = { workspace = true, optional = true }
|
||||
postcard = { version = "1.0.4", features = ["use-std"] }
|
||||
futures-util = { workspace = true, default-features = false, optional = true }
|
||||
ciborium = "0.2.1"
|
||||
base64 = "0.21.0"
|
||||
|
||||
pin-project = "1.1.2"
|
||||
pin-project = { version = "1.1.2", optional = true }
|
||||
thiserror = { workspace = true, optional = true }
|
||||
async-trait = "0.1.71"
|
||||
bytes = "1.4.0"
|
||||
tower-layer = "0.3.2"
|
||||
tower = { version = "0.4.13", features = ["util"], optional = true }
|
||||
tower-layer = { version = "0.3.2", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
dioxus-hot-reload = { workspace = true }
|
||||
@@ -70,22 +67,16 @@ dioxus-hot-reload = { workspace = true }
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
|
||||
|
||||
[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
|
||||
# This is only for debug mode, and it appears mobile does not support some packages this uses
|
||||
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
|
||||
|
||||
[features]
|
||||
default = ["hot-reload", "default-tls"]
|
||||
default = ["hot-reload"]
|
||||
router = ["dioxus-router"]
|
||||
hot-reload = ["serde_json", "futures-util"]
|
||||
web = ["dioxus-web"]
|
||||
desktop = ["dioxus-desktop"]
|
||||
warp = ["dep:warp", "ssr"]
|
||||
axum = ["dep:axum", "tower-http", "ssr"]
|
||||
salvo = ["dep:salvo", "ssr"]
|
||||
ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "dioxus-ssr", "tower", "hyper", "http", "http-body", "dioxus-router/ssr", "tokio-stream"]
|
||||
salvo = ["dep:salvo", "ssr", "http-body-util"]
|
||||
ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "tokio-stream", "dioxus-ssr", "tower", "hyper", "http", "dioxus-router?/ssr", "tower-layer", "anymap", "tracing-futures", "pin-project", "thiserror"]
|
||||
default-tls = ["server_fn/default-tls"]
|
||||
rustls = ["server_fn/rustls"]
|
||||
|
||||
[dev-dependencies]
|
||||
dioxus-fullstack = { path = ".", features = ["router"] }
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>dioxus | ⛺</title>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="UTF-8" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="main"></div>
|
||||
<script type="module">
|
||||
import init from "/./assets/dioxus/name.js";
|
||||
init("/./assets/dioxus/name_bg.wasm").then(wasm => {
|
||||
if (wasm.__wbindgen_start == undefined) {
|
||||
wasm.main();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html><script>// Dioxus-CLI
|
||||
// https://github.com/DioxusLabs/dioxus/tree/master/packages/cli
|
||||
|
||||
(function () {
|
||||
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
var url = protocol + '//' + window.location.host + '/_dioxus/ws';
|
||||
var poll_interval = 8080;
|
||||
var reload_upon_connect = () => {
|
||||
window.setTimeout(
|
||||
() => {
|
||||
var ws = new WebSocket(url);
|
||||
ws.onopen = () => window.location.reload();
|
||||
ws.onclose = reload_upon_connect;
|
||||
},
|
||||
poll_interval);
|
||||
};
|
||||
|
||||
var ws = new WebSocket(url);
|
||||
ws.onmessage = (ev) => {
|
||||
if (ev.data == "reload") {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
ws.onclose = reload_upon_connect;
|
||||
})()
|
||||
</script>
|
||||
@@ -9,7 +9,6 @@ publish = false
|
||||
[dependencies]
|
||||
dioxus = { workspace = true }
|
||||
dioxus-fullstack = { workspace = true }
|
||||
axum = { version = "0.6.12", optional = true }
|
||||
serde = "1.0.159"
|
||||
simple_logger = "4.2.0"
|
||||
tracing-wasm = "0.2.1"
|
||||
@@ -19,5 +18,5 @@ reqwest = "0.11.18"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ssr = ["axum", "dioxus-fullstack/axum"]
|
||||
ssr = ["dioxus-fullstack/axum"]
|
||||
web = ["dioxus-fullstack/web"]
|
||||
@@ -10,7 +10,6 @@ publish = false
|
||||
dioxus-web = { workspace = true, features=["hydrate"], optional = true }
|
||||
dioxus = { workspace = true }
|
||||
dioxus-fullstack = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"], optional = true }
|
||||
serde = "1.0.159"
|
||||
salvo = { version = "0.63.0", optional = true }
|
||||
execute = "0.2.12"
|
||||
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ssr = ["salvo", "tokio", "dioxus-fullstack/salvo"]
|
||||
ssr = ["salvo", "dioxus-fullstack/salvo"]
|
||||
web = ["dioxus-web"]
|
||||
@@ -10,7 +10,6 @@ publish = false
|
||||
dioxus-web = { workspace = true, features=["hydrate"], optional = true }
|
||||
dioxus = { workspace = true }
|
||||
dioxus-fullstack = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"], optional = true }
|
||||
serde = "1.0.159"
|
||||
warp = { version = "0.3.3", optional = true }
|
||||
execute = "0.2.12"
|
||||
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ssr = ["warp", "tokio", "dioxus-fullstack/warp"]
|
||||
ssr = ["warp", "dioxus-fullstack/warp"]
|
||||
web = ["dioxus-web"]
|
||||
@@ -276,9 +276,6 @@ where
|
||||
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
||||
use tower_http::services::{ServeDir, ServeFile};
|
||||
|
||||
// Copy over any assets we find
|
||||
crate::collect_assets::copy_assets();
|
||||
|
||||
let assets_path = assets_path.into();
|
||||
|
||||
// Serve all files in dist folder except index.html
|
||||
|
||||
@@ -241,9 +241,6 @@ impl DioxusRouterExt for Router {
|
||||
}
|
||||
|
||||
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
||||
// Copy over any assets we find
|
||||
crate::collect_assets::copy_assets();
|
||||
|
||||
let assets_path = assets_path.into();
|
||||
|
||||
// Serve all files in dist folder except index.html
|
||||
|
||||
@@ -187,9 +187,6 @@ pub fn serve_dioxus_application<P: Clone + serde::Serialize + Send + Sync + 'sta
|
||||
// Serve the dist folder and the index.html file
|
||||
let serve_dir = warp::fs::dir(cfg.assets_path);
|
||||
|
||||
// Copy over any assets we find
|
||||
crate::collect_assets::copy_assets();
|
||||
|
||||
connect_hot_reload()
|
||||
// First register the server functions
|
||||
.or(register_server_fns(server_fn_route))
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
#[cfg(any(feature = "axum", feature = "warp", feature = "salvo"))]
|
||||
pub fn copy_assets() {
|
||||
#[cfg(all(
|
||||
debug_assertions,
|
||||
any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
{
|
||||
// The CLI will copy assets to the current working directory
|
||||
if std::env::var_os("DIOXUS_ACTIVE").is_some() {
|
||||
return;
|
||||
}
|
||||
use manganis_cli_support::AssetManifest;
|
||||
use manganis_cli_support::AssetManifestExt;
|
||||
use manganis_cli_support::Config;
|
||||
use std::path::PathBuf;
|
||||
let config = Config::current();
|
||||
let asset_location = config.assets_serve_location();
|
||||
let asset_location = PathBuf::from(asset_location);
|
||||
let _ = std::fs::remove_dir_all(&asset_location);
|
||||
|
||||
println!("Finding assets... (Note: if you run a dioxus desktop application with the CLI. This process will be significantly faster.)");
|
||||
let manifest = AssetManifest::load();
|
||||
let has_assets = manifest
|
||||
.packages()
|
||||
.iter()
|
||||
.any(|package| !package.assets().is_empty());
|
||||
|
||||
if has_assets {
|
||||
println!("Copying and optimizing assets...");
|
||||
manifest.copy_static_assets_to(&asset_location).unwrap();
|
||||
println!("Copied assets to {}", asset_location.display());
|
||||
} else {
|
||||
println!("No assets found");
|
||||
}
|
||||
}
|
||||
#[cfg(not(all(
|
||||
debug_assertions,
|
||||
any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
)))]
|
||||
{
|
||||
println!(
|
||||
"Skipping assets in release mode. You compile assets with the dioxus-cli in release mode"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ pub(crate) fn serde_from_bytes<T: DeserializeOwned>(string: &[u8]) -> Option<T>
|
||||
}
|
||||
};
|
||||
|
||||
match postcard::from_bytes(&decompressed) {
|
||||
match ciborium::from_reader(std::io::Cursor::new(decompressed)) {
|
||||
Ok(data) => Some(data),
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to deserialize: {}", err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::{io::Cursor, sync::atomic::AtomicUsize};
|
||||
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
@@ -15,7 +15,8 @@ pub(crate) struct HTMLData {
|
||||
|
||||
impl HTMLData {
|
||||
pub(crate) fn push<T: Serialize>(&mut self, value: &T) {
|
||||
let serialized = postcard::to_allocvec(value).unwrap();
|
||||
let mut serialized = Vec::new();
|
||||
serialize::serde_to_writable(value, &mut serialized).unwrap();
|
||||
self.data.push(serialized);
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ impl HTMLDataCursor {
|
||||
}
|
||||
let mut cursor = &self.data[current];
|
||||
self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
match postcard::from_bytes(cursor) {
|
||||
match ciborium::from_reader(Cursor::new(cursor)) {
|
||||
Ok(x) => Some(x),
|
||||
Err(e) => {
|
||||
tracing::error!("Error deserializing data: {:?}", e);
|
||||
@@ -57,7 +58,7 @@ impl HTMLDataCursor {
|
||||
|
||||
#[test]
|
||||
fn serialized_and_deserializes() {
|
||||
use postcard::to_allocvec;
|
||||
use ciborium::{from_reader, into_writer};
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
||||
struct Data {
|
||||
@@ -97,7 +98,9 @@ fn serialized_and_deserializes() {
|
||||
"original size: {}",
|
||||
std::mem::size_of::<Data>() * data.len()
|
||||
);
|
||||
println!("serialized size: {}", to_allocvec(&data).unwrap().len());
|
||||
let mut bytes = Vec::new();
|
||||
into_writer(&data, &mut bytes).unwrap();
|
||||
println!("serialized size: {}", bytes.len());
|
||||
println!("compressed size: {}", as_string.len());
|
||||
|
||||
let decoded: Vec<Data> = deserialize::serde_from_bytes(&as_string).unwrap();
|
||||
|
||||
@@ -7,8 +7,9 @@ use base64::Engine;
|
||||
pub(crate) fn serde_to_writable<T: Serialize>(
|
||||
value: &T,
|
||||
write_to: &mut impl std::io::Write,
|
||||
) -> std::io::Result<()> {
|
||||
let serialized = postcard::to_allocvec(value).unwrap();
|
||||
) -> Result<(), ciborium::ser::Error<std::io::Error>> {
|
||||
let mut serialized = Vec::new();
|
||||
ciborium::into_writer(value, &mut serialized)?;
|
||||
write_to.write_all(STANDARD.encode(serialized).as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -18,12 +19,12 @@ pub(crate) fn serde_to_writable<T: Serialize>(
|
||||
pub(crate) fn encode_props_in_element<T: Serialize>(
|
||||
data: &T,
|
||||
write_to: &mut impl std::io::Write,
|
||||
) -> std::io::Result<()> {
|
||||
) -> Result<(), ciborium::ser::Error<std::io::Error>> {
|
||||
write_to.write_all(
|
||||
r#"<meta hidden="true" id="dioxus-storage-props" data-serialized=""#.as_bytes(),
|
||||
)?;
|
||||
serde_to_writable(data, write_to)?;
|
||||
write_to.write_all(r#"" />"#.as_bytes())
|
||||
Ok(write_to.write_all(r#"" />"#.as_bytes())?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
@@ -31,10 +32,10 @@ pub(crate) fn encode_props_in_element<T: Serialize>(
|
||||
pub(crate) fn encode_in_element(
|
||||
data: &super::HTMLData,
|
||||
write_to: &mut impl std::io::Write,
|
||||
) -> std::io::Result<()> {
|
||||
) -> Result<(), ciborium::ser::Error<std::io::Error>> {
|
||||
write_to.write_all(
|
||||
r#"<meta hidden="true" id="dioxus-storage-data" data-serialized=""#.as_bytes(),
|
||||
)?;
|
||||
serde_to_writable(&data, write_to)?;
|
||||
write_to.write_all(r#"" />"#.as_bytes())
|
||||
Ok(write_to.write_all(r#"" />"#.as_bytes())?)
|
||||
}
|
||||
@@ -14,7 +14,6 @@ pub mod router;
|
||||
mod adapters;
|
||||
#[cfg(feature = "ssr")]
|
||||
pub use adapters::*;
|
||||
mod collect_assets;
|
||||
mod hooks;
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
mod hot_reload;
|
||||
|
||||
@@ -65,7 +65,7 @@ impl SsrRendererPool {
|
||||
}
|
||||
if let Err(err) = renderer.render_to(&mut to, &vdom) {
|
||||
let _ = tx.send(Err(
|
||||
dioxus_router::prelude::IncrementalRendererError::RenderError(
|
||||
dioxus_ssr::incremental::IncrementalRendererError::RenderError(
|
||||
err,
|
||||
),
|
||||
));
|
||||
@@ -236,7 +236,9 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
|
||||
to: &mut R,
|
||||
) -> Result<(), dioxus_ssr::incremental::IncrementalRendererError> {
|
||||
// serialize the props
|
||||
crate::html_storage::serialize::encode_props_in_element(&self.cfg.props, to)?;
|
||||
crate::html_storage::serialize::encode_props_in_element(&self.cfg.props, to).map_err(
|
||||
|err| dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err)),
|
||||
)?;
|
||||
// serialize the server state
|
||||
crate::html_storage::serialize::encode_in_element(
|
||||
&*self.server_context.html_data().map_err(|_| {
|
||||
@@ -258,7 +260,8 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
|
||||
}))
|
||||
})?,
|
||||
to,
|
||||
)?;
|
||||
)
|
||||
.map_err(|err| dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err)))?;
|
||||
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload"))]
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user