Skip to content

Commit 14884bc

Browse files
authored
Merge pull request #3988 from leptos-rs/wasm-splitting-support
feat: wasm-splitting library support for future cargo-leptos integration
2 parents 5f2d511 + 2c93e1a commit 14884bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2570
-198
lines changed

Cargo.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ server_fn = { path = "./server_fn", version = "0.8.4" }
7171
server_fn_macro = { path = "./server_fn_macro", version = "0.8.4" }
7272
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.8.4" }
7373
tachys = { path = "./tachys", version = "0.2.5" }
74+
wasm_split_helpers = { path = "./wasm_split", version = "0.1.0" }
75+
wasm_split_macros = { path = "./wasm_split_macros", version = "0.1.0" }
7476

7577
# members deps
78+
async-once-cell = { default-features = false, version = "0.5.3" }
7679
itertools = { default-features = false, version = "0.14.0" }
7780
convert_case = { default-features = false, version = "0.8.0" }
7881
serde_json = { default-features = false, version = "1.0.140" }
@@ -165,6 +168,9 @@ rustversion = { default-features = false, version = "1.0.21" }
165168
getrandom = { default-features = false, version = "0.3.3" }
166169
actix-files = { default-features = false, version = "0.6.6" }
167170
async-lock = { default-features = false, version = "3.4.0" }
171+
base16 = { default-features = false, version = "0.2.1" }
172+
digest = { default-features = false, version = "0.10.7" }
173+
sha2 = { default-features = false, version = "0.10.8" }
168174

169175
[profile.release]
170176
codegen-units = 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extend = [
2+
{ path = "./cargo-leptos.toml" },
3+
{ path = "../cargo-make/webdriver.toml" },
4+
]
5+
6+
[tasks.integration-test]
7+
dependencies = [
8+
"install-cargo-leptos",
9+
"start-webdriver",
10+
"cargo-leptos-e2e-split",
11+
]

examples/cargo-make/cargo-leptos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ args = ["--locked"]
1111
command = "cargo"
1212
args = ["leptos", "end-to-end"]
1313

14+
[tasks.cargo-leptos-e2e-split]
15+
command = "cargo"
16+
args = ["leptos", "end-to-end", "--split"]
17+
1418
[tasks.build]
1519
clear = true
1620
command = "cargo"

examples/hackernews_axum/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod routes;
44
use leptos_meta::{provide_meta_context, Link, Meta, MetaTags, Stylesheet};
55
use leptos_router::{
66
components::{FlatRoutes, Route, Router, RoutingProgress},
7-
OptionalParamSegment, ParamSegment, StaticSegment,
7+
Lazy, OptionalParamSegment, ParamSegment, StaticSegment,
88
};
99
use routes::{nav::*, stories::*, story::*, users::*};
1010
use std::time::Duration;
@@ -44,8 +44,8 @@ pub fn App() -> impl IntoView {
4444
<Nav />
4545
<main>
4646
<FlatRoutes fallback=|| "Not found.">
47-
<Route path=(StaticSegment("users"), ParamSegment("id")) view=User/>
48-
<Route path=(StaticSegment("stories"), ParamSegment("id")) view=Story/>
47+
<Route path=(StaticSegment("users"), ParamSegment("id")) view={Lazy::<UserRoute>::new()}/>
48+
<Route path=(StaticSegment("stories"), ParamSegment("id")) view={Lazy::<StoryRoute>::new()}/>
4949
<Route path=OptionalParamSegment("stories") view=Stories/>
5050
</FlatRoutes>
5151
</main>

examples/hackernews_axum/src/routes/story.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
use crate::api;
1+
use crate::api::{self, Story};
22
use leptos::{either::Either, prelude::*};
33
use leptos_meta::Meta;
4-
use leptos_router::{components::A, hooks::use_params_map};
4+
use leptos_router::{
5+
components::A, hooks::use_params_map, lazy_route, LazyRoute,
6+
};
57

6-
#[component]
7-
pub fn Story() -> impl IntoView {
8-
let params = use_params_map();
9-
let story = Resource::new_blocking(
10-
move || params.read().get("id").unwrap_or_default(),
11-
move |id| async move {
12-
if id.is_empty() {
13-
None
14-
} else {
15-
api::fetch_api::<api::Story>(&api::story(&format!("item/{id}")))
8+
#[derive(Debug)]
9+
pub struct StoryRoute {
10+
story: Resource<Option<Story>>,
11+
}
12+
13+
#[lazy_route]
14+
impl LazyRoute for StoryRoute {
15+
fn data() -> Self {
16+
let params = use_params_map();
17+
let story = Resource::new_blocking(
18+
move || params.read().get("id").unwrap_or_default(),
19+
move |id| async move {
20+
if id.is_empty() {
21+
None
22+
} else {
23+
api::fetch_api::<api::Story>(&api::story(&format!(
24+
"item/{id}"
25+
)))
1626
.await
17-
}
18-
},
19-
);
27+
}
28+
},
29+
);
30+
Self { story }
31+
}
2032

21-
Suspense(SuspenseProps::builder().fallback(|| "Loading...").children(ToChildren::to_children(move || Suspend::new(async move {
33+
fn view(this: Self) -> AnyView {
34+
let StoryRoute { story } = this;
35+
Suspense(SuspenseProps::builder().fallback(|| "Loading...").children(ToChildren::to_children(move || Suspend::new(async move {
2236
match story.await.clone() {
2337
None => Either::Left("Story not found."),
2438
Some(story) => {
@@ -61,7 +75,8 @@ pub fn Story() -> impl IntoView {
6175
})
6276
}
6377
}
64-
}))).build())
78+
}))).build()).into_any()
79+
}
6580
}
6681

6782
#[component]
Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
use crate::api::{self, User};
22
use leptos::{either::Either, prelude::*, server::Resource};
3-
use leptos_router::hooks::use_params_map;
3+
use leptos_router::{hooks::use_params_map, lazy_route, LazyRoute};
44

5-
#[component]
6-
pub fn User() -> impl IntoView {
7-
let params = use_params_map();
8-
let user = Resource::new(
9-
move || params.read().get("id").unwrap_or_default(),
10-
move |id| async move {
11-
if id.is_empty() {
12-
None
13-
} else {
14-
api::fetch_api::<User>(&api::user(&id)).await
15-
}
16-
},
17-
);
18-
view! {
19-
<div class="user-view">
20-
<Suspense fallback=|| view! { "Loading..." }>
21-
{move || Suspend::new(async move { match user.await.clone() {
22-
None => Either::Left(view! { <h1>"User not found."</h1> }),
23-
Some(user) => Either::Right(view! {
24-
<div>
25-
<h1>"User: " {user.id.clone()}</h1>
26-
<ul class="meta">
27-
<li>
28-
<span class="label">"Created: "</span> {user.created}
29-
</li>
30-
<li>
31-
<span class="label">"Karma: "</span> {user.karma}
32-
</li>
33-
<li inner_html={user.about} class="about"></li>
34-
</ul>
35-
<p class="links">
36-
<a href=format!("https://news.ycombinator.com/submitted?id={}", user.id)>"submissions"</a>
37-
" | "
38-
<a href=format!("https://news.ycombinator.com/threads?id={}", user.id)>"comments"</a>
39-
</p>
40-
</div>
41-
})
42-
}})}
43-
</Suspense>
44-
</div>
5+
#[derive(Debug)]
6+
pub struct UserRoute {
7+
user: Resource<Option<User>>,
8+
}
9+
10+
#[lazy_route]
11+
impl LazyRoute for UserRoute {
12+
fn data() -> Self {
13+
let params = use_params_map();
14+
let user = Resource::new(
15+
move || params.read().get("id").unwrap_or_default(),
16+
move |id| async move {
17+
if id.is_empty() {
18+
None
19+
} else {
20+
api::fetch_api::<User>(&api::user(&id)).await
21+
}
22+
},
23+
);
24+
UserRoute { user }
25+
}
26+
27+
fn view(this: Self) -> AnyView {
28+
let UserRoute { user } = this;
29+
view! {
30+
<div class="user-view">
31+
<Suspense fallback=|| view! { "Loading..." }>
32+
{move || Suspend::new(async move { match user.await.clone() {
33+
None => Either::Left(view! { <h1>"User not found."</h1> }),
34+
Some(user) => Either::Right(view! {
35+
<div>
36+
<h1>"User: " {user.id.clone()}</h1>
37+
<ul class="meta">
38+
<li>
39+
<span class="label">"Created: "</span> {user.created}
40+
</li>
41+
<li>
42+
<span class="label">"Karma: "</span> {user.karma}
43+
</li>
44+
<li inner_html={user.about} class="about"></li>
45+
</ul>
46+
<p class="links">
47+
<a href=format!("https://news.ycombinator.com/submitted?id={}", user.id)>"submissions"</a>
48+
" | "
49+
<a href=format!("https://news.ycombinator.com/threads?id={}", user.id)>"comments"</a>
50+
</p>
51+
</div>
52+
})
53+
}})}
54+
</Suspense>
55+
</div>
56+
}.into_any()
4557
}
4658
}

0 commit comments

Comments
 (0)