Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ actix-web = { default-features = false, version = "4.11.0" }
tracing = { default-features = false, version = "0.1.41" }
slotmap = { default-features = false, version = "1.0.7" }
futures = { default-features = false, version = "0.3.31" }
dashmap = { default-features = false, version = "6.1.0" }
pin-project-lite = { default-features = false, version = "0.2.16" }
send_wrapper = { default-features = false, version = "0.6.0" }
tokio-test = { default-features = false, version = "0.4.4" }
Expand All @@ -105,7 +104,6 @@ wasm-bindgen-futures = { default-features = false, version = "0.4.50" }
tower = { default-features = false, version = "0.5.2" }
proc-macro2 = { default-features = false, version = "1.0.101" }
serde = { default-features = false, version = "1.0.219" }
parking_lot = { default-features = false, version = "0.12.5" }
axum = { default-features = false, version = "0.8.6" }
serde_qs = { default-features = false, version = "0.15.0" }
syn = { default-features = false, version = "2.0.106" }
Expand Down
2 changes: 0 additions & 2 deletions examples/server_fns_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ web-sys = { version = "0.3.70", features = ["FileList", "File"] }
strum = { version = "0.27.1", features = ["strum_macros", "derive"] }
notify = { version = "8.0", optional = true }
pin-project-lite = "0.2.14"
dashmap = { version = "6.0", optional = true }
async-broadcast = { version = "0.7.1", optional = true }
bytecheck = "0.8.0"
rkyv = { version = "0.8.8" }
Expand All @@ -52,7 +51,6 @@ ssr = [
"leptos/ssr",
"dep:leptos_axum",
"dep:notify",
"dep:dashmap",
"dep:async-broadcast",
]

Expand Down
13 changes: 8 additions & 5 deletions examples/server_fns_axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ pub fn FileUploadWithProgress() -> impl IntoView {
#[cfg(feature = "ssr")]
mod progress {
use async_broadcast::{broadcast, Receiver, Sender};
use dashmap::DashMap;
use std::collections::HashMap;
use std::sync::Mutex;
use futures::Stream;
use std::sync::LazyLock;

Expand All @@ -432,13 +433,14 @@ pub fn FileUploadWithProgress() -> impl IntoView {
rx: Receiver<usize>,
}

static FILES: LazyLock<DashMap<String, File>> =
LazyLock::new(DashMap::new);
static FILES: LazyLock<Mutex<Hashmap<String, File>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));

pub async fn add_chunk(filename: &str, len: usize) {
println!("[{filename}]\tadding {len}");
let files = FILES.lock().unwrap();
let mut entry =
FILES.entry(filename.to_string()).or_insert_with(|| {
files.entry(filename.to_string()).or_insert_with(|| {
println!("[{filename}]\tinserting channel");
let (tx, rx) = broadcast(128);
File { total: 0, tx, rx }
Expand All @@ -457,8 +459,9 @@ pub fn FileUploadWithProgress() -> impl IntoView {
}

pub fn for_file(filename: &str) -> impl Stream<Item = usize> {
let files = FILES.lock().unwrap();
let entry =
FILES.entry(filename.to_string()).or_insert_with(|| {
files.entry(filename.to_string()).or_insert_with(|| {
println!("[{filename}]\tinserting channel");
let (tx, rx) = broadcast(128);
File { total: 0, tx, rx }
Expand Down
2 changes: 0 additions & 2 deletions integrations/actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ leptos_router = { workspace = true, features = ["ssr"] }
server_fn = { workspace = true, features = ["actix-no-default"] }
tachys = { workspace = true }
serde_json = { workspace = true, default-features = true }
parking_lot = { workspace = true, default-features = true }
tracing = { optional = true, workspace = true, default-features = true }
tokio = { features = ["rt", "fs"], workspace = true, default-features = true }
send_wrapper = { workspace = true, default-features = true }
dashmap = { workspace = true, default-features = true }

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]
Expand Down
36 changes: 20 additions & 16 deletions integrations/actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use actix_web::{
web::{Data, Payload, ServiceConfig},
*,
};
use dashmap::DashMap;
use futures::{stream::once, Stream, StreamExt};
use http::StatusCode;
use hydration_context::SsrSharedContext;
Expand All @@ -38,19 +37,18 @@ use leptos_router::{
static_routes::{RegenerationFn, ResolvedStaticPath},
ExpandOptionals, Method, PathSegment, RouteList, RouteListing, SsrMode,
};
use parking_lot::RwLock;
use send_wrapper::SendWrapper;
use server_fn::{
error::ServerFnErrorErr, redirect::REDIRECT_HEADER,
request::actix::ActixRequest,
};
use std::{
collections::HashSet,
collections::{HashMap, HashSet},
fmt::{Debug, Display},
future::Future,
ops::{Deref, DerefMut},
path::Path,
sync::{Arc, LazyLock},
sync::{Arc, LazyLock, RwLock},
};

/// This struct lets you define headers and override the status of the Response from an Element or a Server Function
Expand Down Expand Up @@ -121,12 +119,12 @@ pub struct ResponseOptions(pub Arc<RwLock<ResponseParts>>);
impl ResponseOptions {
/// A simpler way to overwrite the contents of `ResponseOptions` with a new `ResponseParts`.
pub fn overwrite(&self, parts: ResponseParts) {
let mut writable = self.0.write();
let mut writable = self.0.write().unwrap();
*writable = parts
}
/// Set the status of the returned Response.
pub fn set_status(&self, status: StatusCode) {
let mut writeable = self.0.write();
let mut writeable = self.0.write().unwrap();
let res_parts = &mut *writeable;
res_parts.status = Some(status);
}
Expand All @@ -136,7 +134,7 @@ impl ResponseOptions {
key: header::HeaderName,
value: header::HeaderValue,
) {
let mut writeable = self.0.write();
let mut writeable = self.0.write().unwrap();
let res_parts = &mut *writeable;
res_parts.headers.insert(key, value);
}
Expand All @@ -146,7 +144,7 @@ impl ResponseOptions {
key: header::HeaderName,
value: header::HeaderValue,
) {
let mut writeable = self.0.write();
let mut writeable = self.0.write().unwrap();
let res_parts = &mut *writeable;
res_parts.headers.append(key, value);
}
Expand All @@ -170,7 +168,7 @@ impl ExtendResponse for ActixResponse {
}

fn extend_response(&mut self, res_options: &Self::ResponseOptions) {
let mut res_options = res_options.0.write();
let mut res_options = res_options.0.write().unwrap();

let headers = self.0.headers_mut();
for (key, value) in std::mem::take(&mut res_options.headers) {
Expand Down Expand Up @@ -394,7 +392,8 @@ pub fn handle_server_fns_with_context(
// the Location header may have been set to Referer, so any redirection by the
// user must overwrite it
{
let mut res_options = res_options.0.write();
let mut res_options =
res_options.0.write().unwrap();
let headers = res.0.headers_mut();

for location in
Expand Down Expand Up @@ -1222,12 +1221,12 @@ impl StaticRouteGenerator {
}
}

static STATIC_HEADERS: LazyLock<DashMap<String, ResponseOptions>> =
LazyLock::new(DashMap::new);
static STATIC_HEADERS: LazyLock<RwLock<HashMap<String, ResponseOptions>>> =
LazyLock::new(|| RwLock::new(HashMap::new()));

fn was_404(owner: &Owner) -> bool {
let resp = owner.with(|| expect_context::<ResponseOptions>());
let status = resp.0.read().status;
let status = resp.0.read().unwrap().status;

if let Some(status) = status {
return status == StatusCode::NOT_FOUND;
Expand Down Expand Up @@ -1255,7 +1254,10 @@ async fn write_static_route(
html: &str,
) -> Result<(), std::io::Error> {
if let Some(options) = response_options {
STATIC_HEADERS.insert(path.to_string(), options);
STATIC_HEADERS
.write()
.unwrap()
.insert(path.to_string(), options);
}

let path = static_path(options, path);
Expand Down Expand Up @@ -1322,8 +1324,10 @@ where
.await;
(owner.with(use_context::<ResponseOptions>), html)
} else {
let headers =
STATIC_HEADERS.get(orig_path).map(|v| v.clone());
let headers = STATIC_HEADERS
.read()
.unwrap()
.get(orig_path).cloned();
(headers, None)
};

Expand Down
2 changes: 0 additions & 2 deletions integrations/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ hydration_context = { workspace = true }
axum = { default-features = false, features = [
"matched-path",
], workspace = true }
dashmap = { workspace = true, default-features = true }
futures = { workspace = true, default-features = true }
leptos = { workspace = true, features = ["nonce", "ssr"] }
server_fn = { workspace = true, features = ["axum-no-default"] }
Expand All @@ -23,7 +22,6 @@ leptos_meta = { workspace = true, features = ["ssr", "nonce"] }
leptos_router = { workspace = true, features = ["ssr"] }
leptos_integration_utils = { workspace = true }
tachys = { workspace = true }
parking_lot = { workspace = true, default-features = true }
tokio = { default-features = false, workspace = true }
tower = { features = ["util"], workspace = true, default-features = true }
tower-http = { workspace = true, default-features = true }
Expand Down
Loading