More fullstack fixes (#4737)
* allow `--server` only builds! * rollback example * capture `/:route` routes * fix: properly implement file uploads in forms * implement desktop form uploads * Performant serialization of form bytes * finish up file stuff * cleanups * add request headers to streaming context * remove some unwraps
This commit is contained in:
1 parent
fc01a002fd
commit
92792aded9
47 files changed
+1241
-703
No files matched your search
@@ -13,7 +13,7 @@ use axum::{
|
||||
};
|
||||
use dioxus_core::{Element, VirtualDom};
|
||||
use futures::Stream;
|
||||
use http::header::*;
|
||||
use http::{header::*, request::Parts};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use tower::util::MapResponse;
|
||||
@@ -297,13 +297,8 @@ impl RenderHandleState {
|
||||
};
|
||||
|
||||
let (parts, _) = request.into_parts();
|
||||
let url = parts
|
||||
.uri
|
||||
.path_and_query()
|
||||
.ok_or(StatusCode::BAD_REQUEST)?
|
||||
.to_string();
|
||||
|
||||
match state.render(url, cfg, build_virtual_dom).await {
|
||||
match state.render(parts, cfg, build_virtual_dom).await {
|
||||
Ok((freshness, rx)) => {
|
||||
let mut response =
|
||||
axum::response::Html::from(Body::from_stream(rx)).into_response();
|
||||
@@ -338,7 +333,7 @@ impl RenderHandleState {
|
||||
/// Render the application to HTML.
|
||||
pub async fn render<'a>(
|
||||
&'a self,
|
||||
route: String,
|
||||
parts: Parts,
|
||||
cfg: &'a ServeConfig,
|
||||
virtual_dom_factory: impl FnOnce() -> VirtualDom + Send + Sync + 'static,
|
||||
) -> Result<
|
||||
@@ -350,7 +345,7 @@ impl RenderHandleState {
|
||||
> {
|
||||
self.renderers
|
||||
.clone()
|
||||
.render_to(cfg, route, virtual_dom_factory)
|
||||
.render_to(parts, cfg, virtual_dom_factory)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use dioxus_router::ParseRouteError;
|
||||
use dioxus_ssr::Renderer;
|
||||
use futures_channel::mpsc::Sender;
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use http::StatusCode;
|
||||
use http::{request::Parts, StatusCode};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Write,
|
||||
@@ -98,8 +98,8 @@ impl SsrRendererPool {
|
||||
/// The streaming is canceled when the stream the function returns is dropped
|
||||
pub(crate) async fn render_to(
|
||||
self: Arc<Self>,
|
||||
parts: Parts,
|
||||
cfg: &ServeConfig,
|
||||
route: String,
|
||||
virtual_dom_factory: impl FnOnce() -> VirtualDom + Send + Sync + 'static,
|
||||
) -> Result<
|
||||
(
|
||||
@@ -133,6 +133,15 @@ impl SsrRendererPool {
|
||||
}
|
||||
}
|
||||
|
||||
let route = parts
|
||||
.uri
|
||||
.path_and_query()
|
||||
.ok_or_else(|| SSRError::HttpError {
|
||||
status: StatusCode::BAD_REQUEST,
|
||||
message: None,
|
||||
})?
|
||||
.to_string();
|
||||
|
||||
let (mut into, rx) =
|
||||
futures_channel::mpsc::channel::<Result<String, IncrementalRendererError>>(1000);
|
||||
|
||||
@@ -177,9 +186,10 @@ impl SsrRendererPool {
|
||||
};
|
||||
|
||||
// Provide the document and streaming context to the root of the app
|
||||
let streaming_context = virtual_dom.in_scope(ScopeId::ROOT, StreamingContext::new);
|
||||
let streaming_context =
|
||||
virtual_dom.in_scope(ScopeId::ROOT, || StreamingContext::new(parts));
|
||||
virtual_dom.provide_root_context(document.clone() as Rc<dyn dioxus_document::Document>);
|
||||
virtual_dom.provide_root_context(streaming_context);
|
||||
virtual_dom.provide_root_context(streaming_context.clone());
|
||||
|
||||
virtual_dom.in_scope(ScopeId::ROOT, || {
|
||||
// Wrap the memory history in a fullstack history provider to provide the initial route for hydration
|
||||
|
||||
Reference in new issue
Block a user