mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-28 07:52:34 -05:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ee4444bb4 | ||
|
|
03a1c1e7a6 | ||
|
|
12e49ed996 | ||
|
|
1e281e9e74 | ||
|
|
bd475f89d0 | ||
|
|
3d91b5e90f | ||
|
|
96d8d5218c | ||
|
|
84caa35cef | ||
|
|
fc8b55161c | ||
|
|
657052466b | ||
|
|
efe8336363 | ||
|
|
770881842c | ||
|
|
0d540ef02f | ||
|
|
dc1885ad92 | ||
|
|
61bf87439a | ||
|
|
308568e520 | ||
|
|
1b0f32dc4c | ||
|
|
2e0b3011d9 | ||
|
|
680d4ccd07 | ||
|
|
325f9cbe33 | ||
|
|
26ab392c95 | ||
|
|
3a4e2a19aa | ||
|
|
eed3d21b40 | ||
|
|
7ae386285d | ||
|
|
ebcc51136d | ||
|
|
e10ded4fd0 | ||
|
|
67be872f58 | ||
|
|
e5b21ac0fc |
28
.github/workflows/autofix.yml
vendored
28
.github/workflows/autofix.yml
vendored
@@ -21,33 +21,19 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with: {toolchain: nightly, components: "rustfmt, clippy", target: "wasm32-unknown-unknown", rustflags: ""}
|
||||
with: {toolchain: "nightly-2025-04-16", components: "rustfmt, clippy", target: "wasm32-unknown-unknown", rustflags: ""}
|
||||
- name: Install Glib
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libglib2.0-dev
|
||||
- name: Install cargo-all-features
|
||||
run: cargo install --git https://github.com/sabify/cargo-all-features --branch arbitrary-command-support
|
||||
- name: Install jq
|
||||
run: sudo apt-get install jq
|
||||
- run: |
|
||||
echo "Formatting the workspace"
|
||||
cargo fmt --all
|
||||
|
||||
echo "Running Clippy against each member's features (default features included)"
|
||||
for member in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | .name'); do
|
||||
echo "Working on member $member":
|
||||
echo -e "\tdefault-features/no-features:"
|
||||
# this will also run on members with no features or default features
|
||||
cargo clippy --allow-dirty --fix --lib --package "$member"
|
||||
|
||||
features=$(cargo metadata --no-deps --format-version 1 | jq -r ".packages[] | select(.name == \"$member\") | .features | keys[]")
|
||||
for feature in $features; do
|
||||
if [ "$feature" = "default" ]; then
|
||||
continue
|
||||
fi
|
||||
echo -e "\tfeature $feature"
|
||||
cargo clippy --allow-dirty --fix --lib --package "$member" --features "$feature"
|
||||
done
|
||||
done
|
||||
- name: Format the workspace
|
||||
run: cargo fmt --all
|
||||
- name: Clippy the workspace
|
||||
run: cargo all-features clippy --allow-dirty --fix --lib --no-deps
|
||||
- uses: autofix-ci/action@v1.3.1
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
|
||||
8
.github/workflows/run-cargo-make-task.yml
vendored
8
.github/workflows/run-cargo-make-task.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain: [stable, nightly-2025-03-05]
|
||||
toolchain: [stable, nightly-2025-04-16]
|
||||
erased_mode: [true, false]
|
||||
steps:
|
||||
- name: Free Disk Space
|
||||
@@ -160,6 +160,12 @@ jobs:
|
||||
run: |
|
||||
cd '${{ inputs.directory }}'
|
||||
cargo make --no-workspace --profile=github-actions ci
|
||||
# Check if the counter_isomorphic can be built with leptos_debuginfo cfg flag in release mode
|
||||
- name: ${{ inputs.cargo_make_task }} with --cfg=leptos_debuginfo
|
||||
if: contains(inputs.directory, 'counter_isomorphic')
|
||||
run: |
|
||||
cd '${{ inputs.directory }}'
|
||||
RUSTFLAGS="$RUSTFLAGS --cfg leptos_debuginfo" cargo leptos build --release
|
||||
- name: Clean up ${{ inputs.directory }}
|
||||
if: always()
|
||||
run: |
|
||||
|
||||
43
Cargo.lock
generated
43
Cargo.lock
generated
@@ -1781,7 +1781,7 @@ checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
|
||||
|
||||
[[package]]
|
||||
name = "leptos"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"base64",
|
||||
@@ -1833,7 +1833,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_actix"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-http",
|
||||
@@ -1859,7 +1859,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_axum"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"axum",
|
||||
@@ -1883,7 +1883,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_config"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"config",
|
||||
"regex",
|
||||
@@ -1897,7 +1897,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_dom"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"leptos",
|
||||
@@ -1914,7 +1914,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_hot_reload"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
@@ -1930,7 +1930,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_integration_utils"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"hydration_context",
|
||||
@@ -1943,7 +1943,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_macro"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"attribute-derive",
|
||||
"cfg-if",
|
||||
@@ -1963,7 +1963,7 @@ dependencies = [
|
||||
"rustc_version",
|
||||
"serde",
|
||||
"server_fn",
|
||||
"server_fn_macro 0.8.0",
|
||||
"server_fn_macro 0.8.2",
|
||||
"syn 2.0.100",
|
||||
"tracing",
|
||||
"trybuild",
|
||||
@@ -1973,7 +1973,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_meta"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"indexmap",
|
||||
@@ -1988,7 +1988,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_router"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"either_of",
|
||||
@@ -2013,7 +2013,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_router_macro"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"leptos_macro",
|
||||
"leptos_router",
|
||||
@@ -2025,7 +2025,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "leptos_server"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"base64",
|
||||
@@ -2759,7 +2759,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reactive_graph"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"async-lock",
|
||||
@@ -2782,7 +2782,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reactive_stores"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"dashmap",
|
||||
@@ -2801,7 +2801,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reactive_stores_macro"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"convert_case 0.8.0",
|
||||
"proc-macro-error2",
|
||||
@@ -3298,7 +3298,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "server_fn"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"actix-ws",
|
||||
@@ -3323,6 +3323,7 @@ dependencies = [
|
||||
"reqwest",
|
||||
"rkyv",
|
||||
"rmp-serde",
|
||||
"rustc_version",
|
||||
"rustversion",
|
||||
"send_wrapper",
|
||||
"serde",
|
||||
@@ -3361,7 +3362,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "server_fn_macro"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"convert_case 0.8.0",
|
||||
@@ -3374,9 +3375,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "server_fn_macro_default"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"server_fn_macro 0.8.0",
|
||||
"server_fn_macro 0.8.2",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
@@ -3570,7 +3571,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tachys"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"any_spawner",
|
||||
"async-trait",
|
||||
|
||||
28
Cargo.toml
28
Cargo.toml
@@ -40,7 +40,7 @@ members = [
|
||||
exclude = ["benchmarks", "examples", "projects"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
edition = "2021"
|
||||
rust-version = "1.76"
|
||||
|
||||
@@ -52,16 +52,16 @@ const_str_slice_concat = { path = "./const_str_slice_concat", version = "0.1" }
|
||||
either_of = { path = "./either_of/", version = "0.1.5" }
|
||||
hydration_context = { path = "./hydration_context", version = "0.3.0" }
|
||||
itertools = "0.14.0"
|
||||
leptos = { path = "./leptos", version = "0.8.0" }
|
||||
leptos_config = { path = "./leptos_config", version = "0.8.0" }
|
||||
leptos_dom = { path = "./leptos_dom", version = "0.8.0" }
|
||||
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.8.0" }
|
||||
leptos_integration_utils = { path = "./integrations/utils", version = "0.8.0" }
|
||||
leptos_macro = { path = "./leptos_macro", version = "0.8.0" }
|
||||
leptos_router = { path = "./router", version = "0.8.0" }
|
||||
leptos_router_macro = { path = "./router_macro", version = "0.8.0" }
|
||||
leptos_server = { path = "./leptos_server", version = "0.8.0" }
|
||||
leptos_meta = { path = "./meta", version = "0.8.0" }
|
||||
leptos = { path = "./leptos", version = "0.8.2" }
|
||||
leptos_config = { path = "./leptos_config", version = "0.8.2" }
|
||||
leptos_dom = { path = "./leptos_dom", version = "0.8.2" }
|
||||
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.8.2" }
|
||||
leptos_integration_utils = { path = "./integrations/utils", version = "0.8.2" }
|
||||
leptos_macro = { path = "./leptos_macro", version = "0.8.2" }
|
||||
leptos_router = { path = "./router", version = "0.8.2" }
|
||||
leptos_router_macro = { path = "./router_macro", version = "0.8.2" }
|
||||
leptos_server = { path = "./leptos_server", version = "0.8.2" }
|
||||
leptos_meta = { path = "./meta", version = "0.8.2" }
|
||||
next_tuple = { path = "./next_tuple", version = "0.1.0" }
|
||||
oco_ref = { path = "./oco", version = "0.2.0" }
|
||||
or_poisoned = { path = "./or_poisoned", version = "0.1.0" }
|
||||
@@ -70,9 +70,9 @@ reactive_stores = { path = "./reactive_stores", version = "0.2.0" }
|
||||
reactive_stores_macro = { path = "./reactive_stores_macro", version = "0.2.0" }
|
||||
rustversion = "1"
|
||||
serde_json = "1.0.0"
|
||||
server_fn = { path = "./server_fn", version = "0.8.0" }
|
||||
server_fn_macro = { path = "./server_fn_macro", version = "0.8.0" }
|
||||
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.8.0" }
|
||||
server_fn = { path = "./server_fn", version = "0.8.2" }
|
||||
server_fn_macro = { path = "./server_fn_macro", version = "0.8.2" }
|
||||
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.8.2" }
|
||||
tachys = { path = "./tachys", version = "0.2.0" }
|
||||
trybuild = "1"
|
||||
typed-builder = "0.21.0"
|
||||
|
||||
@@ -6,7 +6,7 @@ use leptos_router::{components::A, hooks::use_params_map};
|
||||
#[component]
|
||||
pub fn Story() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let story = Resource::new(
|
||||
let story = Resource::new_blocking(
|
||||
move || params.read().get("id").unwrap_or_default(),
|
||||
move |id| async move {
|
||||
if id.is_empty() {
|
||||
|
||||
@@ -6,7 +6,7 @@ use leptos_router::{components::A, hooks::use_params_map};
|
||||
#[component]
|
||||
pub fn Story() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let story = Resource::new(
|
||||
let story = Resource::new_blocking(
|
||||
move || params.read().get("id").unwrap_or_default(),
|
||||
move |id| async move {
|
||||
if id.is_empty() {
|
||||
|
||||
@@ -13,7 +13,7 @@ pub async fn fetch_story(
|
||||
#[component]
|
||||
pub fn Story() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let story = Resource::new(
|
||||
let story = Resource::new_blocking(
|
||||
move || params.read().get("id").unwrap_or_default(),
|
||||
move |id| async move {
|
||||
if id.is_empty() {
|
||||
|
||||
@@ -7,7 +7,7 @@ use send_wrapper::SendWrapper;
|
||||
#[component]
|
||||
pub fn Story() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let story = Resource::new(
|
||||
let story = Resource::new_blocking(
|
||||
move || params.read().get("id").unwrap_or_default(),
|
||||
move |id| {
|
||||
SendWrapper::new(async move {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Leptos Counter Example
|
||||
# Stores Example
|
||||
|
||||
This example creates a simple counter in a client side rendered app with Rust and WASM!
|
||||
This example shows how to use reactive stores, by building a client-side rendered TODO application.
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/leptos-rs/leptos"
|
||||
description = "Axum integrations for the Leptos web framework."
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
rust-version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
((root, pkg_path, output_name, wasm_output_name) => {
|
||||
let MOST_RECENT_CHILDREN_CB;
|
||||
let MOST_RECENT_CHILDREN_CB = [];
|
||||
|
||||
function idle(c) {
|
||||
if ("requestIdleCallback" in window) {
|
||||
@@ -22,14 +22,18 @@
|
||||
traverse(child, children);
|
||||
}
|
||||
} else {
|
||||
if(tag === 'leptos-children') {
|
||||
MOST_RECENT_CHILDREN_CB = node.$$on_hydrate;
|
||||
if (tag === 'leptos-children') {
|
||||
MOST_RECENT_CHILDREN_CB.push(node.$$on_hydrate);
|
||||
for(const child of node.children) {
|
||||
traverse(child);
|
||||
};
|
||||
// un-set the "most recent children"
|
||||
MOST_RECENT_CHILDREN_CB.pop();
|
||||
} else {
|
||||
for(const child of node.children) {
|
||||
traverse(child);
|
||||
};
|
||||
}
|
||||
for(const child of node.children) {
|
||||
traverse(child);
|
||||
};
|
||||
// un-set the "most recent children"
|
||||
MOST_RECENT_CHILDREN_CB = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,8 +43,9 @@
|
||||
function hydrateIsland(el, id, mod) {
|
||||
const islandFn = mod[id];
|
||||
if (islandFn) {
|
||||
if (MOST_RECENT_CHILDREN_CB) {
|
||||
MOST_RECENT_CHILDREN_CB();
|
||||
const children_cb = MOST_RECENT_CHILDREN_CB[MOST_RECENT_CHILDREN_CB.length-1];
|
||||
if (children_cb) {
|
||||
children_cb();
|
||||
}
|
||||
islandFn(el);
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,10 @@ window.addEventListener("popstate", async (ev) => {
|
||||
});
|
||||
|
||||
window.addEventListener("submit", async (ev) => {
|
||||
if (ev.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
const req = submitToReq(ev);
|
||||
if(!req) {
|
||||
return;
|
||||
@@ -194,6 +198,15 @@ function diffRange(oldDocument, oldRoot, newDocument, newRoot, oldEnd, newEnd) {
|
||||
else if (oldNode.nodeType === Node.TEXT_NODE) {
|
||||
oldNode.textContent = newNode.textContent;
|
||||
}
|
||||
// islands should not be diffed on the client, because we do not want to overwrite client-side state
|
||||
// but their children should be diffed still, because they could contain new server content
|
||||
else if (oldNode.nodeType === Node.ELEMENT_NODE && oldNode.tagName === "LEPTOS-ISLAND") {
|
||||
// TODO: diff the leptos-children
|
||||
|
||||
// skip over leptos-island otherwise
|
||||
oldDocWalker.nextSibling();
|
||||
newDocWalker.nextSibling();
|
||||
}
|
||||
// if it's an element, replace if it's a different tag, or update attributes
|
||||
else if (oldNode.nodeType === Node.ELEMENT_NODE) {
|
||||
diffElement(oldNode, newNode);
|
||||
|
||||
@@ -7,7 +7,7 @@ ws.onmessage = (ev) => {
|
||||
let found = false;
|
||||
document.querySelectorAll("link").forEach((link) => {
|
||||
if (link.getAttribute('href').includes(msg.css)) {
|
||||
let newHref = '/' + msg.css + '?version=' + new Date().getMilliseconds();
|
||||
let newHref = '/' + msg.css + '?version=' + Date.now();
|
||||
link.setAttribute('href', newHref);
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -357,38 +357,13 @@ impl ToTokens for Model {
|
||||
|
||||
// add island wrapper if island
|
||||
let component = if is_island {
|
||||
let is_server = cfg!(feature = "ssr");
|
||||
let hydrate_fn_name = hydrate_fn_name.as_ref().unwrap();
|
||||
if is_server {
|
||||
quote! {
|
||||
{
|
||||
// if we're on the server, and inside another island already,
|
||||
// *don't* add a <leptos-island> (this will hydrate them both separately)
|
||||
if ::leptos::context::use_context::<::leptos::reactive::owner::IsHydrating>()
|
||||
.map(|h| h.0)
|
||||
.unwrap_or(false) {
|
||||
::leptos::either::Either::Left(
|
||||
#component
|
||||
)
|
||||
} else {
|
||||
::leptos::either::Either::Right(
|
||||
::leptos::tachys::html::islands::Island::new(
|
||||
stringify!(#hydrate_fn_name),
|
||||
#component
|
||||
)
|
||||
#island_serialized_props
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
::leptos::tachys::html::islands::Island::new(
|
||||
stringify!(#hydrate_fn_name),
|
||||
#component
|
||||
)
|
||||
#island_serialized_props
|
||||
}
|
||||
quote! {
|
||||
::leptos::tachys::html::islands::Island::new(
|
||||
stringify!(#hydrate_fn_name),
|
||||
#component
|
||||
)
|
||||
#island_serialized_props
|
||||
}
|
||||
} else {
|
||||
component
|
||||
|
||||
@@ -300,6 +300,34 @@ impl<T> LocalResource<T> {
|
||||
pub fn refetch(&self) {
|
||||
self.refetch.try_update(|n| *n += 1);
|
||||
}
|
||||
|
||||
/// Synchronously, reactively reads the current value of the resource and applies the function
|
||||
/// `f` to its value if it is `Some(_)`.
|
||||
#[track_caller]
|
||||
pub fn map<U>(&self, f: impl FnOnce(&T) -> U) -> Option<U>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.data.try_with(|n| n.as_ref().map(f))?
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> LocalResource<Result<T, E>>
|
||||
where
|
||||
T: 'static,
|
||||
E: Clone + 'static,
|
||||
{
|
||||
/// Applies the given function when a resource that returns `Result<T, E>`
|
||||
/// has resolved and loaded an `Ok(_)`, rather than requiring nested `.map()`
|
||||
/// calls over the `Option<Result<_, _>>` returned by the resource.
|
||||
///
|
||||
/// This is useful when used with features like server functions, in conjunction
|
||||
/// with `<ErrorBoundary/>` and `<Suspense/>`, when these other components are
|
||||
/// left to handle the `None` and `Err(_)` states.
|
||||
#[track_caller]
|
||||
pub fn and_then<U>(&self, f: impl FnOnce(&T) -> U) -> Option<Result<U, E>> {
|
||||
self.map(|data| data.as_ref().map(f).map_err(|e| e.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoFuture for LocalResource<T>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_meta"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/leptos-rs/leptos"
|
||||
|
||||
@@ -242,23 +242,22 @@ impl ServerMetaContextOutput {
|
||||
let head_loc = first_chunk
|
||||
.find("</head>")
|
||||
.expect("you are using leptos_meta without a </head> tag");
|
||||
let marker_loc =
|
||||
first_chunk.find("<!--HEAD-->").unwrap_or_else(|| {
|
||||
let marker_loc = first_chunk
|
||||
.find("<!--HEAD-->")
|
||||
.map(|pos| pos + "<!--HEAD-->".len())
|
||||
.unwrap_or_else(|| {
|
||||
first_chunk.find("</head>").unwrap_or(head_loc)
|
||||
});
|
||||
let (before_marker, after_marker) =
|
||||
first_chunk.split_at_mut(marker_loc);
|
||||
let (before_head_close, after_head) =
|
||||
after_marker.split_at_mut(head_loc - marker_loc);
|
||||
buf.push_str(before_marker);
|
||||
buf.push_str(&meta_buf);
|
||||
if let Some(title) = title {
|
||||
buf.push_str("<title>");
|
||||
buf.push_str(&title);
|
||||
buf.push_str("</title>");
|
||||
}
|
||||
buf.push_str(before_head_close);
|
||||
buf.push_str(&meta_buf);
|
||||
buf.push_str(after_head);
|
||||
buf.push_str(after_marker);
|
||||
buf
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reactive_graph"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -236,11 +236,11 @@ pub fn provide_context<T: Send + Sync + 'static>(value: T) {
|
||||
///
|
||||
/// Effect::new(move |_| {
|
||||
/// // each use_context clones the value
|
||||
/// let value =
|
||||
/// use_context::<String>().expect("could not find i32 in context");
|
||||
/// let value = use_context::<String>()
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value, "foo");
|
||||
/// let value2 =
|
||||
/// use_context::<String>().expect("could not find i32 in context");
|
||||
/// let value2 = use_context::<String>()
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value2, "foo");
|
||||
/// });
|
||||
/// });
|
||||
@@ -284,11 +284,11 @@ pub fn use_context<T: Clone + 'static>() -> Option<T> {
|
||||
///
|
||||
/// Effect::new(move |_| {
|
||||
/// // each use_context clones the value
|
||||
/// let value =
|
||||
/// use_context::<String>().expect("could not find i32 in context");
|
||||
/// let value = use_context::<String>()
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value, "foo");
|
||||
/// let value2 =
|
||||
/// use_context::<String>().expect("could not find i32 in context");
|
||||
/// let value2 = use_context::<String>()
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value2, "foo");
|
||||
/// });
|
||||
/// });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reactive_stores"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -56,12 +56,12 @@
|
||||
//!
|
||||
//! # if false { // don't run effect in doctests
|
||||
//! Effect::new(move |_| {
|
||||
//! // you can access individual store withs field a getter
|
||||
//! // you can access individual store fields with a getter
|
||||
//! println!("todos: {:?}", &*store.todos().read());
|
||||
//! });
|
||||
//! # }
|
||||
//!
|
||||
//! // won't notify the effect that listen to `todos`
|
||||
//! // won't notify the effect that listens to `todos`
|
||||
//! store.todos().write().push(Todo {
|
||||
//! label: "Test".to_string(),
|
||||
//! completed: false,
|
||||
@@ -69,7 +69,7 @@
|
||||
//! ```
|
||||
//! ### Generated traits
|
||||
//! The [`Store`](macro@Store) macro generates traits for each `struct` to which it is applied. When working
|
||||
//! within a single file more module, this is not an issue. However, when working with multiple modules
|
||||
//! within a single file or module, this is not an issue. However, when working with multiple modules
|
||||
//! or files, one needs to `use` the generated traits. The general pattern is that for each `struct`
|
||||
//! named `Foo`, the macro generates a trait named `FooStoreFields`. For example:
|
||||
//! ```rust
|
||||
@@ -608,6 +608,14 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> PartialEq for Store<T, S> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> Eq for Store<T, S> {}
|
||||
|
||||
impl<T> Store<T, LocalStorage>
|
||||
where
|
||||
T: 'static,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reactive_stores_macro"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_router"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
authors = ["Greg Johnston", "Ben Wishovich"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -430,6 +430,9 @@ impl RenderHtml for MatchedRoute {
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(&self.0);
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,6 +458,9 @@ impl RenderHtml for MatchedRoute {
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(&self.0);
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_router_macro"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
authors = ["Greg Johnston", "Ben Wishovich"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -16,7 +16,7 @@ server_fn_macro_default = { workspace = true }
|
||||
const_format = "0.2.33"
|
||||
const-str = "0.6.2"
|
||||
xxhash-rust = { version = "0.8.12", features = ["const_xxh64"] }
|
||||
rustversion = { workspace = true}
|
||||
rustversion = { workspace = true }
|
||||
# used across multiple features
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
send_wrapper = { version = "0.6.0", features = ["futures"], optional = true }
|
||||
@@ -82,6 +82,9 @@ url = "2"
|
||||
pin-project-lite = "0.2.15"
|
||||
tokio = { version = "1.43.0", features = ["rt"], optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.4.1"
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = { workspace = true }
|
||||
|
||||
@@ -238,4 +241,7 @@ skip_feature_sets = [
|
||||
max_combination_size = 2
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
unexpected_cfgs = { level = "warn", check-cfg = [
|
||||
'cfg(leptos_debuginfo)',
|
||||
'cfg(rustc_nightly)',
|
||||
] }
|
||||
|
||||
8
server_fn/build.rs
Normal file
8
server_fn/build.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use rustc_version::{version_meta, Channel};
|
||||
|
||||
fn main() {
|
||||
// Set cfg flags depending on release channel
|
||||
if matches!(version_meta().unwrap().channel, Channel::Nightly) {
|
||||
println!("cargo:rustc-cfg=rustc_nightly");
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ error[E0271]: expected `impl Future<Output = ()>` to be a future that resolves t
|
||||
|
|
||||
= note: expected enum `Result<_, _>`
|
||||
found unit type `()`
|
||||
note: required by a bound in `ServerFn::{synthetic#0}`
|
||||
note: required by a bound in `ServerFn::{anon_assoc#0}`
|
||||
--> src/lib.rs
|
||||
|
|
||||
| ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ServerFn::{synthetic#0}`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ServerFn::{anon_assoc#0}`
|
||||
|
||||
error[E0277]: () is not a `Result` or aliased `Result`. Server functions must return a `Result` or aliased `Result`.
|
||||
--> tests/invalid/empty_return.rs:3:1
|
||||
|
||||
@@ -16,11 +16,11 @@ error[E0271]: expected `impl Future<Output = CustomError>` to be a future that r
|
||||
|
|
||||
= note: expected enum `Result<_, _>`
|
||||
found enum `CustomError`
|
||||
note: required by a bound in `ServerFn::{synthetic#0}`
|
||||
note: required by a bound in `ServerFn::{anon_assoc#0}`
|
||||
--> src/lib.rs
|
||||
|
|
||||
| ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ServerFn::{synthetic#0}`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ServerFn::{anon_assoc#0}`
|
||||
|
||||
error[E0277]: CustomError is not a `Result` or aliased `Result`. Server functions must return a `Result` or aliased `Result`.
|
||||
--> tests/invalid/not_result.rs:25:1
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// multiple combinations of features are tested. This ensures this file is only
|
||||
// run when **only** the browser feature is enabled.
|
||||
#![cfg(all(
|
||||
rustc_nightly,
|
||||
feature = "browser",
|
||||
not(any(
|
||||
feature = "postcard",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tachys"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::{
|
||||
|
||||
/// An island of interactivity in an otherwise-inert HTML document.
|
||||
pub struct Island<View> {
|
||||
has_element_representation: bool,
|
||||
component: &'static str,
|
||||
props_json: String,
|
||||
view: View,
|
||||
@@ -19,6 +20,8 @@ impl<View> Island<View> {
|
||||
/// Creates a new island with the given component name.
|
||||
pub fn new(component: &'static str, view: View) -> Self {
|
||||
Island {
|
||||
has_element_representation:
|
||||
Self::should_have_element_representation(),
|
||||
component,
|
||||
props_json: String::new(),
|
||||
view,
|
||||
@@ -51,6 +54,21 @@ impl<View> Island<View> {
|
||||
buf.push_str(ISLAND_TAG);
|
||||
buf.push('>');
|
||||
}
|
||||
|
||||
/// Whether this island should be represented by an actual HTML element
|
||||
fn should_have_element_representation() -> bool {
|
||||
#[cfg(feature = "reactive_graph")]
|
||||
{
|
||||
use reactive_graph::owner::{use_context, IsHydrating};
|
||||
let already_hydrating =
|
||||
use_context::<IsHydrating>().map(|h| h.0).unwrap_or(false);
|
||||
!already_hydrating
|
||||
}
|
||||
#[cfg(not(feature = "reactive_graph"))]
|
||||
{
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<View> Render for Island<View>
|
||||
@@ -83,11 +101,13 @@ where
|
||||
Self::Output<NewAttr>: RenderHtml,
|
||||
{
|
||||
let Island {
|
||||
has_element_representation,
|
||||
component,
|
||||
props_json,
|
||||
view,
|
||||
} = self;
|
||||
Island {
|
||||
has_element_representation,
|
||||
component,
|
||||
props_json,
|
||||
view: view.add_any_attr(attr),
|
||||
@@ -114,11 +134,13 @@ where
|
||||
|
||||
async fn resolve(self) -> Self::AsyncOutput {
|
||||
let Island {
|
||||
has_element_representation,
|
||||
component,
|
||||
props_json,
|
||||
view,
|
||||
} = self;
|
||||
Island {
|
||||
has_element_representation,
|
||||
component,
|
||||
props_json,
|
||||
view: view.resolve().await,
|
||||
@@ -133,7 +155,10 @@ where
|
||||
mark_branches: bool,
|
||||
extra_attrs: Vec<AnyAttribute>,
|
||||
) {
|
||||
Self::open_tag(self.component, &self.props_json, buf);
|
||||
let has_element = self.has_element_representation;
|
||||
if has_element {
|
||||
Self::open_tag(self.component, &self.props_json, buf);
|
||||
}
|
||||
self.view.to_html_with_buf(
|
||||
buf,
|
||||
position,
|
||||
@@ -141,7 +166,9 @@ where
|
||||
mark_branches,
|
||||
extra_attrs,
|
||||
);
|
||||
Self::close_tag(buf);
|
||||
if has_element {
|
||||
Self::close_tag(buf);
|
||||
}
|
||||
}
|
||||
|
||||
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
|
||||
@@ -154,9 +181,12 @@ where
|
||||
) where
|
||||
Self: Sized,
|
||||
{
|
||||
let has_element = self.has_element_representation;
|
||||
// insert the opening tag synchronously
|
||||
let mut tag = String::new();
|
||||
Self::open_tag(self.component, &self.props_json, &mut tag);
|
||||
if has_element {
|
||||
Self::open_tag(self.component, &self.props_json, &mut tag);
|
||||
}
|
||||
buf.push_sync(&tag);
|
||||
|
||||
// streaming render for the view
|
||||
@@ -170,7 +200,9 @@ where
|
||||
|
||||
// and insert the closing tag synchronously
|
||||
tag.clear();
|
||||
Self::close_tag(&mut tag);
|
||||
if has_element {
|
||||
Self::close_tag(&mut tag);
|
||||
}
|
||||
buf.push_sync(&tag);
|
||||
}
|
||||
|
||||
@@ -179,18 +211,21 @@ where
|
||||
cursor: &Cursor,
|
||||
position: &PositionState,
|
||||
) -> Self::State {
|
||||
if position.get() == Position::FirstChild {
|
||||
cursor.child();
|
||||
} else if position.get() == Position::NextChild {
|
||||
cursor.sibling();
|
||||
if self.has_element_representation {
|
||||
if position.get() == Position::FirstChild {
|
||||
cursor.child();
|
||||
} else if position.get() == Position::NextChild {
|
||||
cursor.sibling();
|
||||
}
|
||||
position.set(Position::FirstChild);
|
||||
}
|
||||
position.set(Position::FirstChild);
|
||||
|
||||
self.view.hydrate::<FROM_SERVER>(cursor, position)
|
||||
}
|
||||
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
Island {
|
||||
has_element_representation: self.has_element_representation,
|
||||
component: self.component,
|
||||
props_json: self.props_json,
|
||||
view: self.view.into_owned(),
|
||||
|
||||
@@ -285,6 +285,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for RenderEffectState<T> {
|
||||
fn drop(&mut self) {
|
||||
if let Some(effect) = self.0.take() {
|
||||
drop(effect.take_value());
|
||||
drop(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, E> Mountable for Result<M, E>
|
||||
where
|
||||
M: Mountable,
|
||||
|
||||
@@ -223,10 +223,20 @@ impl StreamBuilder {
|
||||
);
|
||||
}
|
||||
let chunks = subbuilder.finish().take_chunks();
|
||||
let mut flattened_chunks =
|
||||
VecDeque::with_capacity(chunks.len());
|
||||
for chunk in chunks {
|
||||
// this will wait for any ErrorBoundary async nodes and flatten them out
|
||||
if let StreamChunk::Async { chunks } = chunk {
|
||||
flattened_chunks.extend(chunks.await);
|
||||
} else {
|
||||
flattened_chunks.push_back(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
OooChunk {
|
||||
id,
|
||||
chunks,
|
||||
chunks: flattened_chunks,
|
||||
replace,
|
||||
nonce,
|
||||
}
|
||||
|
||||
@@ -410,6 +410,9 @@ impl RenderHtml for AnyView {
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(&type_id);
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
@@ -456,6 +459,9 @@ impl RenderHtml for AnyView {
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(&type_id);
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let type_id = if mark_branches && escape {
|
||||
@@ -476,6 +482,9 @@ impl RenderHtml for AnyView {
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(&type_id);
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
|
||||
@@ -320,6 +320,9 @@ where
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch("0");
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
Either::Right(right) => {
|
||||
@@ -335,6 +338,9 @@ where
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch("1");
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +370,9 @@ where
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch("0");
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
Either::Right(right) => {
|
||||
@@ -379,6 +388,9 @@ where
|
||||
);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch("1");
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,6 +874,9 @@ macro_rules! tuples {
|
||||
this.to_html_with_buf(buf, position, escape, mark_branches, extra_attrs);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(stringify!($ty));
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
})*
|
||||
}
|
||||
@@ -885,6 +900,9 @@ macro_rules! tuples {
|
||||
this.to_html_async_with_buf::<OUT_OF_ORDER>(buf, position, escape, mark_branches, extra_attrs);
|
||||
if mark_branches && escape {
|
||||
buf.close_branch(stringify!($ty));
|
||||
if *position == Position::NextChildAfterText {
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
})*
|
||||
}
|
||||
|
||||
@@ -33,11 +33,10 @@ where
|
||||
match (&mut state.state, self) {
|
||||
// both errors: throw the new error and replace
|
||||
(Either::Right(_), Err(new)) => {
|
||||
if let Some(old_error) =
|
||||
state.error.replace(throw_error::throw(new.into()))
|
||||
{
|
||||
if let Some(old_error) = state.error.take() {
|
||||
throw_error::clear(&old_error);
|
||||
}
|
||||
state.error = Some(throw_error::throw(new.into()));
|
||||
}
|
||||
// both Ok: need to rebuild child
|
||||
(Either::Left(old), Ok(new)) => {
|
||||
|
||||
@@ -435,7 +435,7 @@ where
|
||||
T: Mountable,
|
||||
{
|
||||
states: Vec<T>,
|
||||
parent: Option<crate::renderer::types::Element>,
|
||||
marker: crate::renderer::types::Placeholder,
|
||||
}
|
||||
|
||||
impl<T> Mountable for StaticVecState<T>
|
||||
@@ -443,7 +443,10 @@ where
|
||||
T: Mountable,
|
||||
{
|
||||
fn unmount(&mut self) {
|
||||
self.states.iter_mut().for_each(Mountable::unmount);
|
||||
for state in self.states.iter_mut() {
|
||||
state.unmount();
|
||||
}
|
||||
self.marker.unmount();
|
||||
}
|
||||
|
||||
fn mount(
|
||||
@@ -454,7 +457,7 @@ where
|
||||
for state in self.states.iter_mut() {
|
||||
state.mount(parent, marker);
|
||||
}
|
||||
self.parent = Some(parent.clone());
|
||||
self.marker.mount(parent, marker);
|
||||
}
|
||||
|
||||
fn insert_before_this(&self, child: &mut dyn Mountable) -> bool {
|
||||
@@ -463,7 +466,7 @@ where
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
self.marker.insert_before_this(child)
|
||||
}
|
||||
|
||||
fn elements(&self) -> Vec<crate::renderer::types::Element> {
|
||||
@@ -481,27 +484,52 @@ where
|
||||
type State = StaticVecState<T::State>;
|
||||
|
||||
fn build(self) -> Self::State {
|
||||
let marker = Rndr::create_placeholder();
|
||||
Self::State {
|
||||
states: self.0.into_iter().map(T::build).collect(),
|
||||
parent: None,
|
||||
marker,
|
||||
}
|
||||
}
|
||||
|
||||
fn rebuild(self, state: &mut Self::State) {
|
||||
let Self::State { states, .. } = state;
|
||||
let StaticVecState { states, marker } = state;
|
||||
let old = states;
|
||||
|
||||
// StaticVec's in general shouldn't need to be reused, but rebuild() will still trigger e.g. if 2 routes have the same tree,
|
||||
// this can cause problems if differing in lengths. Because we don't use marker nodes in StaticVec, we rebuild the entire vec remounting to the parent.
|
||||
|
||||
for state in states {
|
||||
state.unmount();
|
||||
// reuses the Vec impl
|
||||
if old.is_empty() {
|
||||
let mut new = self.build().states;
|
||||
for item in new.iter_mut() {
|
||||
Rndr::mount_before(item, marker.as_ref());
|
||||
}
|
||||
*old = new;
|
||||
} else if self.0.is_empty() {
|
||||
// TODO fast path for clearing
|
||||
for item in old.iter_mut() {
|
||||
item.unmount();
|
||||
}
|
||||
old.clear();
|
||||
} else {
|
||||
let mut adds = vec![];
|
||||
let mut removes_at_end = 0;
|
||||
for item in self.0.into_iter().zip_longest(old.iter_mut()) {
|
||||
match item {
|
||||
itertools::EitherOrBoth::Both(new, old) => {
|
||||
T::rebuild(new, old)
|
||||
}
|
||||
itertools::EitherOrBoth::Left(new) => {
|
||||
let mut new_state = new.build();
|
||||
Rndr::mount_before(&mut new_state, marker.as_ref());
|
||||
adds.push(new_state);
|
||||
}
|
||||
itertools::EitherOrBoth::Right(old) => {
|
||||
removes_at_end += 1;
|
||||
old.unmount()
|
||||
}
|
||||
}
|
||||
}
|
||||
old.truncate(old.len() - removes_at_end);
|
||||
old.append(&mut adds);
|
||||
}
|
||||
let parent = state
|
||||
.parent
|
||||
.take()
|
||||
.expect("parent should always be Some() on a StaticVec rebuild()");
|
||||
*state = self.build();
|
||||
state.mount(&parent, None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,7 +580,7 @@ where
|
||||
}
|
||||
|
||||
fn html_len(&self) -> usize {
|
||||
self.0.iter().map(RenderHtml::html_len).sum::<usize>()
|
||||
self.0.iter().map(RenderHtml::html_len).sum::<usize>() + 3
|
||||
}
|
||||
|
||||
fn to_html_with_buf(
|
||||
@@ -572,6 +600,10 @@ where
|
||||
extra_attrs.clone(),
|
||||
);
|
||||
}
|
||||
if escape {
|
||||
buf.push_str("<!>");
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
|
||||
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
|
||||
@@ -593,6 +625,10 @@ where
|
||||
extra_attrs.clone(),
|
||||
);
|
||||
}
|
||||
if escape {
|
||||
buf.push_sync("<!>");
|
||||
*position = Position::NextChild;
|
||||
}
|
||||
}
|
||||
|
||||
fn hydrate<const FROM_SERVER: bool>(
|
||||
@@ -605,8 +641,11 @@ where
|
||||
.into_iter()
|
||||
.map(|child| child.hydrate::<FROM_SERVER>(cursor, position))
|
||||
.collect();
|
||||
let parent = cursor.current().parent_element();
|
||||
Self::State { states, parent }
|
||||
|
||||
let marker = cursor.next_placeholder(position);
|
||||
position.set(Position::NextChild);
|
||||
|
||||
Self::State { states, marker }
|
||||
}
|
||||
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
|
||||
Reference in New Issue
Block a user