From fa8bb15a67b0172975884f39d5c84021b7f9aec3 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 14 Jun 2024 14:16:59 -0400 Subject: [PATCH] initial work updating suspense tests --- examples/suspense_tests/Cargo.toml | 6 +- examples/suspense_tests/src/app.rs | 94 +++++++++++++++-------------- examples/suspense_tests/src/lib.rs | 5 +- examples/suspense_tests/src/main.rs | 30 +++++++-- 4 files changed, 78 insertions(+), 57 deletions(-) diff --git a/examples/suspense_tests/Cargo.toml b/examples/suspense_tests/Cargo.toml index 8df88e77d..09dfa75bc 100644 --- a/examples/suspense_tests/Cargo.toml +++ b/examples/suspense_tests/Cargo.toml @@ -10,18 +10,16 @@ crate-type = ["cdylib", "rlib"] actix-files = { version = "0.6", optional = true } actix-web = { version = "4", optional = true, features = ["macros"] } console_error_panic_hook = "0.1" -console_log = "1" -leptos = { path = "../../leptos", features = ["serde"] } +leptos = { path = "../../leptos" } leptos_actix = { path = "../../integrations/actix", optional = true } leptos_router = { path = "../../router" } log = "0.4" -simple_logger = "4" wasm-bindgen = "0.2" serde = "1.0.159" tokio = { version = "1.29", features = ["time", "rt"], optional = true } [features] -hydrate = ["leptos/hydrate", "leptos_router/hydrate"] +hydrate = ["leptos/hydrate"] ssr = [ "dep:actix-files", "dep:actix-web", diff --git a/examples/suspense_tests/src/app.rs b/examples/suspense_tests/src/app.rs index 6bc3542d1..8832f37b0 100644 --- a/examples/suspense_tests/src/app.rs +++ b/examples/suspense_tests/src/app.rs @@ -1,5 +1,8 @@ -use leptos::prelude::*; -use leptos_router::*; +use leptos::{logging, prelude::*}; +use leptos_router::{ + components::{Outlet, ParentRoute, Redirect, Route, Router, Routes, A}, + SsrMode, StaticSegment, +}; const WAIT_ONE_SECOND: u64 = 1; const WAIT_TWO_SECONDS: u64 = 2; @@ -32,7 +35,6 @@ pub fn App() -> impl IntoView { } "; view! { -
- + } /> // out-of-order -

"Out-of-Order"

} > - - - - - - - + + + + + + + // in-order - @@ -72,16 +74,16 @@ pub fn App() -> impl IntoView { } > - - - - - - - + + + + + + + // async - @@ -89,13 +91,13 @@ pub fn App() -> impl IntoView { } > - - - - - - - + + + + + + +
@@ -118,9 +120,9 @@ fn SecondaryNav() -> impl IntoView { #[component] fn Nested() -> impl IntoView { - let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn); - let two_second = create_resource(|| WAIT_TWO_SECONDS, second_wait_fn); - let (count, set_count) = create_signal(0); + let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn); + let two_second = Resource::new_serde(|| WAIT_TWO_SECONDS, second_wait_fn); + let (count, set_count) = signal(0); view! {
@@ -147,15 +149,15 @@ fn Nested() -> impl IntoView { #[component] fn NestedResourceInside() -> impl IntoView { - let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn); - let (count, set_count) = create_signal(0); + let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn); + let (count, set_count) = signal(0); view! {
{move || { one_second.get().map(|_| { - let two_second = create_resource(|| (), move |_| async move { + let two_second = Resource::new_serde(|| (), move |_| async move { logging::log!("creating two_second resource"); second_wait_fn(WAIT_TWO_SECONDS).await }); @@ -185,9 +187,9 @@ fn NestedResourceInside() -> impl IntoView { #[component] fn Parallel() -> impl IntoView { - let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn); - let two_second = create_resource(|| WAIT_TWO_SECONDS, second_wait_fn); - let (count, set_count) = create_signal(0); + let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn); + let two_second = Resource::new_serde(|| WAIT_TWO_SECONDS, second_wait_fn); + let (count, set_count) = signal(0); view! {
@@ -217,8 +219,8 @@ fn Parallel() -> impl IntoView { #[component] fn Single() -> impl IntoView { - let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn); - let (count, set_count) = create_signal(0); + let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn); + let (count, set_count) = signal(0); view! {
@@ -241,7 +243,7 @@ fn Single() -> impl IntoView { #[component] fn InsideComponent() -> impl IntoView { - let (count, set_count) = create_signal(0); + let (count, set_count) = signal(0); view! {
@@ -259,7 +261,7 @@ fn InsideComponent() -> impl IntoView { #[component] fn InsideComponentChild() -> impl IntoView { - let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn); + let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn); view! { {move || { @@ -273,7 +275,7 @@ fn InsideComponentChild() -> impl IntoView { #[component] fn None() -> impl IntoView { - let (count, set_count) = create_signal(0); + let (count, set_count) = signal(0); view! {
diff --git a/examples/suspense_tests/src/lib.rs b/examples/suspense_tests/src/lib.rs index a296f173a..f2f0be2fa 100644 --- a/examples/suspense_tests/src/lib.rs +++ b/examples/suspense_tests/src/lib.rs @@ -1,12 +1,11 @@ pub mod app; +#[cfg(feature = "hydrate")] #[wasm_bindgen::prelude::wasm_bindgen] pub fn hydrate() { use app::*; - // initializes logging using the `log` crate - _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - leptos::mount_to_body(App); + leptos::mount::hydrate_body(App); } diff --git a/examples/suspense_tests/src/main.rs b/examples/suspense_tests/src/main.rs index c39e219b4..881794844 100644 --- a/examples/suspense_tests/src/main.rs +++ b/examples/suspense_tests/src/main.rs @@ -9,17 +9,39 @@ async fn main() -> std::io::Result<()> { let conf = get_configuration(None).await.unwrap(); let addr = conf.leptos_options.site_addr; - // Generate the list of routes in your Leptos App - let routes = generate_route_list(App); + println!("listening on http://{}", &addr); HttpServer::new(move || { + // Generate the list of routes in your Leptos App + let routes = generate_route_list(App); let leptos_options = &conf.leptos_options; let site_root = &leptos_options.site_root; App::new() - .leptos_routes(leptos_options.to_owned(), routes.to_owned(), App) + .leptos_routes(routes, { + let leptos_options = leptos_options.clone(); + move || { + use leptos::prelude::*; + + view! { + + + + + + + + + + + + + } + }}) .service(Files::new("/", site_root)) - //.wrap(middleware::Compress::default()) }) .bind(addr)? .workers(1)