fix(build): isolate hydrate feature to wasm32 target and prevent SSR spawn_local panic
This commit is contained in:
1 parent
b43b060c8a
commit
6a157a2eca
4 files changed
+74
-4
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ COPY style ./style
|
|||||||
COPY public ./public
|
COPY public ./public
|
||||||
|
|
||||||
# 1. Build Axum SSR server binary
|
# 1. Build Axum SSR server binary
|
||||||
RUN cargo build --release --locked --bin server
|
RUN cargo build --release --locked -p server --bin server
|
||||||
|
|
||||||
# 2. Build Leptos WASM hydrate bundle and assemble /src/target/site
|
# 2. Build Leptos WASM hydrate bundle and assemble /src/target/site
|
||||||
RUN cargo build --profile wasm-release --locked --target wasm32-unknown-unknown -p frontend \
|
RUN cargo build --profile wasm-release --locked --target wasm32-unknown-unknown -p frontend \
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ version.workspace = true
|
|||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
app = { workspace = true, features = ["hydrate"] }
|
app = { workspace = true, features = ["hydrate"] }
|
||||||
leptos = { workspace = true, features = ["hydrate"] }
|
leptos = { workspace = true, features = ["hydrate"] }
|
||||||
console_error_panic_hook = { workspace = true }
|
console_error_panic_hook = { workspace = true }
|
||||||
|
|||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
#![recursion_limit = "256"]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
#[wasm_bindgen::prelude::wasm_bindgen]
|
||||||
pub fn hydrate() {
|
pub fn hydrate() {
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|||||||
@@ -185,6 +185,77 @@ async fn serve_photo(State(pipeline): State<Pipeline>, Path(photo_id): Path<Stri
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod job_events_tests {
|
mod job_events_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use axum::body::Body;
|
||||||
|
use axum::http::Request;
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn ssr_routes_render_without_spawn_local_panic() {
|
||||||
|
std::env::set_var("LEPTOS_OUTPUT_NAME", "make-space");
|
||||||
|
let store = storage::Store::connect(&storage::StorageConfig {
|
||||||
|
mongodb_uri: "mongodb://127.0.0.1:1".into(),
|
||||||
|
mongodb_db: "test".into(),
|
||||||
|
minio_endpoint: "http://127.0.0.1:1".into(),
|
||||||
|
minio_access_key: String::new(),
|
||||||
|
minio_secret_key: String::new(),
|
||||||
|
minio_bucket: "test".into(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("in-memory store fallback");
|
||||||
|
let llm = llm::LlmClient::new("http://127.0.0.1:1", "", "test-model");
|
||||||
|
let pipeline = Pipeline::new(
|
||||||
|
store,
|
||||||
|
llm,
|
||||||
|
pipeline::PipelineConfig {
|
||||||
|
kakao_api_key: String::new(),
|
||||||
|
ncp_client_id: String::new(),
|
||||||
|
ncp_client_secret: String::new(),
|
||||||
|
browser_scraper_url: None,
|
||||||
|
max_photos_per_source: 5,
|
||||||
|
max_photos_total: 10,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let conf = get_configuration(None).expect("leptos config");
|
||||||
|
let leptos_options = conf.leptos_options;
|
||||||
|
let routes = generate_route_list(app::App);
|
||||||
|
let pipe_for_ctx = pipeline.clone();
|
||||||
|
let _app_router: Router<()> = Router::new()
|
||||||
|
.route("/health/live", get(health_live))
|
||||||
|
.with_state(pipeline.clone())
|
||||||
|
.leptos_routes_with_context(
|
||||||
|
&leptos_options,
|
||||||
|
routes,
|
||||||
|
move || {
|
||||||
|
provide_context(pipe_for_ctx.clone());
|
||||||
|
},
|
||||||
|
{
|
||||||
|
let opts = leptos_options.clone();
|
||||||
|
move || app::shell(opts.clone())
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.fallback(leptos_axum::file_and_error_handler(app::shell))
|
||||||
|
.with_state(leptos_options.clone());
|
||||||
|
|
||||||
|
for uri in ["/", "/?q=test", "/recent", "/place/kakao%3A1", "/nonexistent-404-path"] {
|
||||||
|
use axum::body::to_bytes;
|
||||||
|
let pipe = pipeline.clone();
|
||||||
|
let opts = leptos_options.clone();
|
||||||
|
let handler = leptos_axum::render_app_to_stream_with_context(
|
||||||
|
move || {
|
||||||
|
provide_context(pipe.clone());
|
||||||
|
},
|
||||||
|
move || app::shell(opts.clone()),
|
||||||
|
);
|
||||||
|
let req = Request::builder()
|
||||||
|
.uri(uri)
|
||||||
|
.header("Accept", "text/html")
|
||||||
|
.body(Body::empty())
|
||||||
|
.unwrap();
|
||||||
|
let resp = handler(req).await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
let bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
|
||||||
|
assert!(!bytes.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_job_returns_a_terminal_error() {
|
fn missing_job_returns_a_terminal_error() {
|
||||||
|
|||||||
Reference in new issue
Block a user