Compare commits

..

2 Commits

Author SHA1 Message Date
Greg Johnston
0aafcc3947 chore: warning 2025-12-28 21:45:03 -05:00
Greg Johnston
5c2482fadc fix: preserve existing attributes when rebuilding AnyViewWithAttrs
(closes #4512)
2025-12-28 20:26:08 -05:00
35 changed files with 441 additions and 482 deletions

132
Cargo.lock generated
View File

@@ -296,9 +296,9 @@ dependencies = [
[[package]]
name = "async-lock"
version = "3.4.2"
version = "3.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311"
checksum = "5fd03604047cee9b6ce9de9f70c6cd540a0520c813cbd49bae61f33ab80ed1dc"
dependencies = [
"event-listener",
"event-listener-strategy",
@@ -403,9 +403,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "axum"
version = "0.8.8"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425"
dependencies = [
"axum-core",
"base64",
@@ -440,9 +440,9 @@ dependencies = [
[[package]]
name = "axum-core"
version = "0.5.6"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1"
checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22"
dependencies = [
"bytes",
"futures-core",
@@ -599,9 +599,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.2.51"
version = "1.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203"
checksum = "9f50d563227a1c37cc0a263f64eca3334388c01c5e4c4861a9def205c614383c"
dependencies = [
"find-msvc-tools",
"jobserver",
@@ -887,18 +887,18 @@ dependencies = [
[[package]]
name = "derive_more"
version = "2.1.1"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134"
checksum = "10b768e943bed7bf2cab53df09f4bc34bfd217cdb57d971e769874c9a6710618"
dependencies = [
"derive_more-impl",
]
[[package]]
name = "derive_more-impl"
version = "2.1.1"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
checksum = "6d286bfdaf75e988b4a78e013ecd79c581e06399ab53fbacd2d916c2f904f30b"
dependencies = [
"convert_case 0.10.0",
"proc-macro2",
@@ -1074,7 +1074,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
@@ -1106,9 +1106,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "find-msvc-tools"
version = "0.1.6"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff"
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
[[package]]
name = "flate2"
@@ -1316,7 +1316,7 @@ dependencies = [
"gobject-sys",
"libc",
"system-deps",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -1672,7 +1672,7 @@ dependencies = [
"libc",
"percent-encoding",
"pin-project-lite",
"socket2 0.5.10",
"socket2 0.6.1",
"tokio",
"tower-service",
"tracing",
@@ -1798,9 +1798,9 @@ dependencies = [
[[package]]
name = "insta"
version = "1.45.1"
version = "1.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "983e3b24350c84ab8a65151f537d67afbbf7153bb9f1110e03e9fa9b07f67a5c"
checksum = "b76866be74d68b1595eb8060cb9191dca9c021db2316558e52ddc5d55d41b66c"
dependencies = [
"console",
"once_cell",
@@ -1831,9 +1831,9 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
[[package]]
name = "iri-string"
version = "0.7.10"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a"
checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397"
dependencies = [
"memchr",
"serde",
@@ -1850,9 +1850,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.17"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jobserver"
@@ -2304,9 +2304,9 @@ dependencies = [
[[package]]
name = "mini-internal"
version = "0.1.45"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a8df435db5df1dd82a74f77e3c3addf6ab7665079c31e222a64f34f7475d87e"
checksum = "560f32b6891d8d9bade8942c45a27694f16d789d3b4b8e6b7135a5240de0a8af"
dependencies = [
"proc-macro2",
"quote",
@@ -2325,13 +2325,13 @@ dependencies = [
[[package]]
name = "miniserde"
version = "0.1.45"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c48e83ec09ab8a51d4e6be46608bf2a1293a79e2f7ea60246a2ce50eaef44ba"
checksum = "ac79f4123c070de643a7a93b9339abf18c30005c622bf4b1c29c2c0960f52d39"
dependencies = [
"itoa",
"mini-internal",
"zmij",
"ryu",
]
[[package]]
@@ -2420,7 +2420,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -2718,9 +2718,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.104"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
@@ -2810,7 +2810,7 @@ dependencies = [
"once_cell",
"socket2 0.6.1",
"tracing",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
]
[[package]]
@@ -3000,9 +3000,9 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.12.28"
version = "0.12.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
checksum = "3b4c14b2d9afca6a60277086b0cc6a6ae0b568f6f7916c943a8cdc79f8be240f"
dependencies = [
"base64",
"bytes",
@@ -3089,19 +3089,22 @@ dependencies = [
[[package]]
name = "rmp"
version = "0.8.15"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c"
checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4"
dependencies = [
"byteorder",
"num-traits",
"paste",
]
[[package]]
name = "rmp-serde"
version = "1.3.1"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155"
checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db"
dependencies = [
"byteorder",
"rmp",
"serde",
]
@@ -3144,15 +3147,15 @@ dependencies = [
[[package]]
name = "rustix"
version = "1.1.3"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
@@ -3198,9 +3201,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "ryu"
version = "1.0.22"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "same-file"
@@ -3343,15 +3346,15 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.148"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da"
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
"serde_core",
"zmij",
]
[[package]]
@@ -3367,22 +3370,20 @@ dependencies = [
[[package]]
name = "serde_qs"
version = "1.0.0-rc.3"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cb0b9062a400c31442e67d1f2b1e7746bebd691110ebee1b7d0c7293b04fab1"
checksum = "f3faaf9e727533a19351a43cc5a8de957372163c7d35cc48c90b75cdda13c352"
dependencies = [
"itoa",
"percent-encoding",
"ryu",
"serde",
"thiserror 2.0.17",
]
[[package]]
name = "serde_spanned"
version = "1.0.4"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392"
dependencies = [
"serde_core",
]
@@ -3539,11 +3540,10 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.8"
version = "1.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
checksum = "7664a098b8e616bdfcc2dc0e9ac44eb231eedf41db4e9fe95d8d32ec728dedad"
dependencies = [
"errno",
"libc",
]
@@ -3814,15 +3814,15 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.24.0"
version = "3.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c"
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
dependencies = [
"fastrand",
"getrandom 0.3.4",
"once_cell",
"rustix",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -4053,18 +4053,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.7.5+spec-1.1.0"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_edit"
version = "0.23.10+spec-1.0.0"
version = "0.23.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269"
checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d"
dependencies = [
"indexmap",
"toml_datetime",
@@ -4567,7 +4567,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -4877,12 +4877,6 @@ dependencies = [
"syn 2.0.111",
]
[[package]]
name = "zmij"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f4a4e8e9dc5c62d159f04fcdbe07f4c3fb710415aab4754bf11505501e3251d"
[[package]]
name = "zstd"
version = "0.13.3"

View File

@@ -74,7 +74,7 @@ tachys = { path = "./tachys", version = "0.2.11" }
async-once-cell = { default-features = false, version = "0.5.4" }
itertools = { default-features = false, version = "0.14.0" }
convert_case = { default-features = false, version = "0.10.0" }
serde_json = { default-features = false, version = "1.0.148" }
serde_json = { default-features = false, version = "1.0.145" }
trybuild = { default-features = false, version = "1.0.114" }
typed-builder = { default-features = false, version = "0.23.2" }
typed-builder-macro = { default-features = false, version = "0.23.2" }
@@ -103,12 +103,12 @@ base64 = { default-features = false, version = "0.22.1" }
cfg-if = { default-features = false, version = "1.0.4" }
wasm-bindgen-futures = { default-features = false, version = "0.4.56" }
tower = { default-features = false, version = "0.5.2" }
proc-macro2 = { default-features = false, version = "1.0.96" }
serde = { default-features = false, version = "1.0.219" }
parking_lot = { default-features = false, version = "0.12.4" }
axum = { default-features = false, version = "0.8.4" }
serde_qs = { default-features = false, version = "1.0.0-rc.3" }
syn = { default-features = false, version = "2.0.104" }
proc-macro2 = { default-features = false, version = "1.0.103" }
serde = { default-features = false, version = "1.0.228" }
parking_lot = { default-features = false, version = "0.12.5" }
axum = { default-features = false, version = "0.8.7" }
serde_qs = { default-features = false, version = "0.15.0" }
syn = { default-features = false, version = "2.0.111" }
xxhash-rust = { default-features = false, version = "0.8.15" }
paste = { default-features = false, version = "1.0.15" }
quote = { default-features = false, version = "1.0.42" }
@@ -144,7 +144,7 @@ bytes = { default-features = false, version = "1.11.0" }
http = { default-features = false, version = "1.4.0" }
regex = { default-features = false, version = "1.12.2" }
drain_filter_polyfill = { default-features = false, version = "0.1.3" }
tempfile = { default-features = false, version = "3.24.0" }
tempfile = { default-features = false, version = "3.23.0" }
futures-lite = { default-features = false, version = "2.6.1" }
log = { default-features = false, version = "0.4.29" }
percent-encoding = { default-features = false, version = "2.3.2" }
@@ -153,18 +153,18 @@ const-str = { default-features = false, version = "0.7.1" }
http-body-util = { default-features = false, version = "0.1.3" }
hyper = { default-features = false, version = "1.8.1" }
postcard = { default-features = false, version = "1.1.3" }
rmp-serde = { default-features = false, version = "1.3.1" }
reqwest = { default-features = false, version = "0.12.28" }
rmp-serde = { default-features = false, version = "1.3.0" }
reqwest = { default-features = false, version = "0.12.26" }
tower-layer = { default-features = false, version = "0.3.3" }
attribute-derive = { default-features = false, version = "0.10.5" }
insta = { default-features = false, version = "1.45.1" }
insta = { default-features = false, version = "1.45.0" }
codee = { default-features = false, version = "0.3.5" }
actix-http = { default-features = false, version = "3.11.2" }
wasm-bindgen-test = { default-features = false, version = "0.3.56" }
rustversion = { default-features = false, version = "1.0.22" }
getrandom = { default-features = false, version = "0.3.4" }
actix-files = { default-features = false, version = "0.6.9" }
async-lock = { default-features = false, version = "3.4.2" }
async-lock = { default-features = false, version = "3.4.1" }
base16 = { default-features = false, version = "0.2.1" }
digest = { default-features = false, version = "0.10.7" }
sha2 = { default-features = false, version = "0.10.9" }

View File

@@ -74,8 +74,8 @@ Leptos is a full-stack, isomorphic Rust web framework leveraging fine-grained re
## What does that mean?
- **Full-stack**: Leptos can be used to build apps that run in the browser (client-side rendering), on the server (server-side rendering), or by rendering HTML on the server and then adding interactivity in the browser (server-side rendering with hydration). This includes support for HTTP streaming of both data ([`Resource`s](https://docs.rs/leptos/latest/leptos/prelude/struct.Resource.html)) and HTML (out-of-order or in-order streaming of [`<Suspense/>`](https://docs.rs/leptos/latest/leptos/suspense/fn.Suspense.html) components.)
- **Isomorphic**: Leptos provides primitives to write isomorphic [server functions](https://docs.rs/server_fn/latest/server_fn/), i.e., functions that can be called with the “same shape” on the client or server, but only run on the server. This means you can write your server-only logic (database requests, authentication etc.) alongside the client-side components that will consume it, and call server functions as if they were running in the browser, without needing to create and maintain a separate REST or other API.
- **Full-stack**: Leptos can be used to build apps that run in the browser (client-side rendering), on the server (server-side rendering), or by rendering HTML on the server and then adding interactivity in the browser (server-side rendering with hydration). This includes support for HTTP streaming of both data ([`Resource`s](https://docs.rs/leptos/latest/leptos/struct.Resource.html)) and HTML (out-of-order or in-order streaming of [`<Suspense/>`](https://docs.rs/leptos/latest/leptos/fn.Suspense.html) components.)
- **Isomorphic**: Leptos provides primitives to write isomorphic [server functions](https://docs.rs/leptos_server/0.2.5/leptos_server/index.html), i.e., functions that can be called with the “same shape” on the client or server, but only run on the server. This means you can write your server-only logic (database requests, authentication etc.) alongside the client-side components that will consume it, and call server functions as if they were running in the browser, without needing to create and maintain a separate REST or other API.
- **Web**: Leptos is built on the Web platform and Web standards. The [router](https://docs.rs/leptos_router/latest/leptos_router/) is designed to use Web fundamentals (like links and forms) and build on top of them rather than trying to replace them.
- **Framework**: Leptos provides most of what you need to build a modern web app: a reactive system, templating library, and a router that works on both the server and client side.
- **Fine-grained reactivity**: The entire framework is built from reactive primitives. This allows for extremely performant code with minimal overhead: when a reactive signals value changes, it can update a single text node, toggle a single class, or remove an element from the DOM without any other code running. (So, no virtual DOM overhead!)

View File

@@ -9,12 +9,12 @@ This document is intended as a running list of common issues, with example code
**Issue**: Sometimes you want to update a reactive signal in a way that depends on another signal.
```rust
let (a, set_a) = signal(0);
let (b, set_b) = signal(false);
let (a, set_a) = create_signal(0);
let (b, set_b) = create_signal(false);
Effect::new(move |_| {
if a.get() > 5 {
set_b.set(true);
create_effect(move |_| {
if a() > 5 {
set_b(true);
}
});
```
@@ -24,10 +24,56 @@ This creates an inefficient chain of updates, and can easily lead to infinite lo
**Solution**: Follow the rule, _What can be derived, should be derived._ In this case, this has the benefit of massively reducing the code size, too!
```rust
let (a, set_a) = signal(0);
let b = move || a.get() > 5;
let (a, set_a) = create_signal(0);
let b = move || a () > 5;
```
### Nested signal updates/reads triggering panic
Sometimes you have nested signals: for example, hash-map that can change over time, each of whose values can also change over time:
```rust
#[component]
pub fn App() -> impl IntoView {
let resources = create_rw_signal(HashMap::new());
let update = move |id: usize| {
resources.update(|resources| {
resources
.entry(id)
.or_insert_with(|| create_rw_signal(0))
.update(|amount| *amount += 1)
})
};
view! {
<div>
<pre>{move || format!("{:#?}", resources.get().into_iter().map(|(id, resource)| (id, resource.get())).collect::<Vec<_>>())}</pre>
<button on:click=move |_| update(1)>"+"</button>
</div>
}
}
```
Clicking the button twice will cause a panic, because of the nested signal _read_. Calling the `update` function on `resources` immediately takes out a mutable borrow on `resources`, then updates the `resource` signal—which re-runs the effect that reads from the signals, which tries to immutably access `resources` and panics. It's the nested update here which causes a problem, because the inner update triggers and effect that tries to read both signals while the outer is still updating.
You can fix this fairly easily by using the [`batch()`](https://docs.rs/leptos/latest/leptos/fn.batch.html) method:
```rust
let update = move |id: usize| {
batch(move || {
resources.update(|resources| {
resources
.entry(id)
.or_insert_with(|| create_rw_signal(0))
.update(|amount| *amount += 1)
})
});
};
```
This delays running any effects until after both updates are made, preventing the conflict entirely without requiring any other restructuring.
## Templates and the DOM
### `<input value=...>` doesn't update or stops updating
@@ -37,8 +83,8 @@ Many DOM attributes can be updated either by setting an attribute on the DOM nod
This means that in practice, attributes like `value` or `checked` on an `<input/>` element only update the _default_ value for the `<input/>`. If you want to reactively update the value, you should use `prop:value` instead to set the `value` property.
```rust
let (a, set_a) = signal("Starting value".to_string());
let on_input = move |ev| set_a.set(event_target_value(&ev));
let (a, set_a) = create_signal("Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {
@@ -51,8 +97,8 @@ view! {
```
```rust
let (a, set_a) = signal("Starting value".to_string());
let on_input = move |ev| set_a.set(event_target_value(&ev));
let (a, set_a) = create_signal("Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {

View File

@@ -670,7 +670,7 @@ fn CodeDemoWasm(mode: WasmDemo) -> impl IntoView {
leptos::logging::log!("wasm csr_listener listener added");
// Dispatch the event when this view is finally mounted onto the DOM.
_ = request_animation_frame(move || {
request_animation_frame(move || {
let event = web_sys::Event::new("hljs_hook")
.expect("error creating hljs_hook event");
document.dispatch_event(&event)
@@ -689,7 +689,7 @@ fn CodeDemoWasm(mode: WasmDemo) -> impl IntoView {
<Suspense fallback=move || view! { <p>"Loading code example..."</p> }>{
move || Suspend::new(async move {
Effect::new(move |_| {
_ = request_animation_frame(move || {
request_animation_frame(move || {
leptos::logging::log!("request_animation_frame invoking hljs::highlight_all");
// under SSR this is an noop, but it wouldn't be called under there anyway because
// it isn't the isomorphic version, i.e. Effect::new_isomorphic(...).
@@ -815,7 +815,7 @@ fn WasmBindgenJSHookReadyEvent() -> impl IntoView {
leptos::logging::log!("wasm csr_listener listener added");
// Dispatch the event when this view is finally mounted onto the DOM.
_ = request_animation_frame(move || {
request_animation_frame(move || {
let event = web_sys::Event::new("hljs_hook")
.expect("error creating hljs_hook event");
document.dispatch_event(&event)
@@ -866,7 +866,7 @@ fn WasmBindgenEffect() -> impl IntoView {
let example = r#"<Suspense fallback=move || view! { <p>"Loading code example..."</p> }>{
move || Suspend::new(async move {
Effect::new(move |_| {
_ = request_animation_frame(move || {
request_animation_frame(move || {
leptos::logging::log!("request_animation_frame invoking hljs::highlight_all");
// under SSR this is an noop.
crate::hljs::highlight_all();

View File

@@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
axum = { version = "0.8.1", optional = true }
console_error_panic_hook = "0.1.7"
console_log = "1.0"
leptos = { path = "../../leptos", features = ["tracing", "lazy"] }
leptos = { path = "../../leptos", features = ["tracing"] }
leptos_meta = { path = "../../meta" }
leptos_axum = { path = "../../integrations/axum", optional = true }
leptos_router = { path = "../../router" }

View File

@@ -97,7 +97,7 @@ fn delay(
duration: Duration,
) -> impl Future<Output = Result<(), Canceled>> + Send {
let (tx, rx) = oneshot::channel();
_ = set_timeout(
set_timeout(
move || {
_ = tx.send(());
},

View File

@@ -50,7 +50,7 @@ where
};
// here, we return the handle
set_interval(
set_interval_with_handle(
f.clone(),
// this is the only reactive access, so this effect will only
// re-run when the interval changes

View File

@@ -684,7 +684,7 @@ where
additional_context.clone(),
app_fn.clone(),
);
let asyn = render_app_async_with_context(
let asyn = render_app_async_stream_with_context(
additional_context.clone(),
app_fn.clone(),
);
@@ -1019,6 +1019,73 @@ where
render_app_async_with_context(|| {}, app_fn)
}
/// Returns an Axum [Handler](axum::handler::Handler) that listens for a `GET` request and tries
/// to route it using [leptos_router], asynchronously rendering an HTML page after all
/// `async` resources have loaded.
///
/// This version allows us to pass Axum State/Extension/Extractor or other info from Axum or network
/// layers above Leptos itself. To use it, you'll need to write your own handler function that provides
/// the data to leptos in a closure. An example is below
/// ```
/// use axum::{
/// body::Body,
/// extract::Path,
/// http::Request,
/// response::{IntoResponse, Response},
/// };
/// use leptos::context::provide_context;
///
/// async fn custom_handler(
/// Path(id): Path<String>,
/// req: Request<Body>,
/// ) -> Response {
/// let handler = leptos_axum::render_app_async_with_context(
/// move || {
/// provide_context(id.clone());
/// },
/// || { /* your application here */ },
/// );
/// handler(req).await.into_response()
/// }
/// ```
/// Otherwise, this function is identical to [render_app_to_stream].
///
/// ## Provided Context Types
/// This function always provides context values including the following types:
/// - [`Parts`]
/// - [`ResponseOptions`]
/// - [`ServerMetaContext`]
#[cfg_attr(
feature = "tracing",
tracing::instrument(level = "trace", fields(error), skip_all)
)]
pub fn render_app_async_stream_with_context<IV>(
additional_context: impl Fn() + 'static + Clone + Send + Sync,
app_fn: impl Fn() -> IV + Clone + Send + Sync + 'static,
) -> impl Fn(
Request<Body>,
) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'static>>
+ Clone
+ Send
+ 'static
where
IV: IntoView + 'static,
{
handle_response(additional_context, app_fn, |app, chunks, _supports_ooo| {
Box::pin(async move {
let app = if cfg!(feature = "islands-router") {
app.to_html_stream_in_order_branching()
} else {
app.to_html_stream_in_order()
};
let app = app.collect::<String>().await;
let chunks = chunks();
Box::pin(once(async move { app }).chain(chunks))
as PinnedStream<String>
})
})
}
/// Returns an Axum [Handler](axum::handler::Handler) that listens for a `GET` request and tries
/// to route it using [leptos_router], asynchronously rendering an HTML page after all
/// `async` resources have loaded.
@@ -2005,7 +2072,19 @@ where
},
move || shell(options),
req,
async_stream_builder,
|app, chunks, _supports_ooo| {
Box::pin(async move {
let app = if cfg!(feature = "islands-router") {
app.to_html_stream_in_order_branching()
} else {
app.to_html_stream_in_order()
};
let app = app.collect::<String>().await;
let chunks = chunks();
Box::pin(once(async move { app }).chain(chunks))
as PinnedStream<String>
})
},
)
.await;

View File

@@ -122,7 +122,6 @@ subsecond = [
"web-sys/WebSocket",
"web-sys/Window",
]
lazy = ["tachys/lazy"]
[dev-dependencies]
tokio = { features = [

View File

@@ -83,7 +83,7 @@ pub fn AnimatedShow(
} else {
cls.set(hide_class);
let h = leptos_dom::helpers::set_timeout(
let h = leptos_dom::helpers::set_timeout_with_handle(
move || show.set(false),
hide_delay,
)

View File

@@ -287,9 +287,7 @@ where
web_sys::UrlSearchParams::new_with_str_sequence_sequence(form_data)
.unwrap_throw();
let data = data.to_string().as_string().unwrap_or_default();
serde_qs::Config::new()
.use_form_encoding(true)
.deserialize_str::<Self>(&data)
serde_qs::Config::new(5, false).deserialize_str::<Self>(&data)
}
}

View File

@@ -1,42 +1,25 @@
if (window.location.protocol === "https:") {
protocol = "wss://";
if (window.location.protocol === 'https:') {
protocol = 'wss://';
}
let host = window.location.hostname;
function connect() {
let ws = new WebSocket(`${protocol}${host}:${reload_port}/live_reload`);
ws.onmessage = (ev) => {
let msg = JSON.parse(ev.data);
if (msg.all) window.location.reload();
if (msg.css) {
let found = false;
document.querySelectorAll("link").forEach((link) => {
if (link.getAttribute("href").includes(msg.css)) {
let newHref = "/" + msg.css + "?version=" + Date.now();
link.setAttribute("href", newHref);
found = true;
}
});
if (!found)
console.warn(
`CSS hot-reload: Could not find a <link href=/\"${msg.css}\"> element`,
);
}
if (msg.view) {
patch(msg.view);
}
let ws = new WebSocket(`${protocol}${host}:${reload_port}/live_reload`);
ws.onmessage = (ev) => {
let msg = JSON.parse(ev.data);
if (msg.all) window.location.reload();
if (msg.css) {
let found = false;
document.querySelectorAll("link").forEach((link) => {
if (link.getAttribute('href').includes(msg.css)) {
let newHref = '/' + msg.css + '?version=' + Date.now();
link.setAttribute('href', newHref);
found = true;
}
});
if (!found) console.warn(`CSS hot-reload: Could not find a <link href=/\"${msg.css}\"> element`);
};
ws.onclose = () => {
console.warn("Live-reload disconnected. Reconnecting...");
setTimeout(connect, 1000);
};
ws.onerror = () => {
ws.close();
};
}
connect();
if(msg.view) {
patch(msg.view);
}
};
ws.onclose = () => console.warn('Live-reload stopped. Manual reload necessary.');

View File

@@ -73,14 +73,14 @@ where
let to = to.into_iter().collect::<Vec<_>>();
let (list, set_list) = create_signal(from.clone());
_ = request_animation_frame({
request_animation_frame({
let to = to.clone();
let then = then.clone();
move || {
set_list(to);
if let Some(then) = then {
_ = request_animation_frame({
request_animation_frame({
move || {
set_list(then);
}

View File

@@ -116,7 +116,7 @@ pub fn event_target_checked(ev: &web_sys::Event) -> bool {
.checked()
}
/// Handle that is generated by [request_animation_frame] and can
/// Handle that is generated by [request_animation_frame_with_handle] and can
/// be used to cancel the animation frame request.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct AnimationFrameRequestHandle(i32);
@@ -129,6 +129,18 @@ impl AnimationFrameRequestHandle {
}
}
/// Runs the given function between the next repaint using
/// [`Window.requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame).
///
/// ### Note about Context
///
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))]
#[inline(always)]
pub fn request_animation_frame(cb: impl FnOnce() + 'static) {
_ = request_animation_frame_with_handle(cb);
}
// Closure::once_into_js only frees the callback when it's actually
// called, so this instead uses into_js_value, which can be freed by
// the host JS engine's GC if it supports weak references (which all
@@ -157,7 +169,7 @@ fn closure_once(cb: impl FnOnce() + 'static) -> JsValue {
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))]
#[inline(always)]
pub fn request_animation_frame(
pub fn request_animation_frame_with_handle(
cb: impl FnOnce() + 'static,
) -> Result<AnimationFrameRequestHandle, JsValue> {
#[cfg(feature = "tracing")]
@@ -178,7 +190,7 @@ pub fn request_animation_frame(
raf(closure_once(cb))
}
/// Handle that is generated by [request_idle_callback] and can be
/// Handle that is generated by [request_idle_callback_with_handle] and can be
/// used to cancel the idle callback.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct IdleCallbackHandle(u32);
@@ -191,6 +203,18 @@ impl IdleCallbackHandle {
}
}
/// Queues the given function during an idle period using
/// [`Window.requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestIdleCallback).
///
/// ### Note about Context
///
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))]
#[inline(always)]
pub fn request_idle_callback(cb: impl Fn() + 'static) {
_ = request_idle_callback_with_handle(cb);
}
/// Queues the given function during an idle period using
/// [`Window.requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestIdleCallback),
/// returning a cancelable handle.
@@ -200,7 +224,7 @@ impl IdleCallbackHandle {
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))]
#[inline(always)]
pub fn request_idle_callback(
pub fn request_idle_callback_with_handle(
cb: impl Fn() + 'static,
) -> Result<IdleCallbackHandle, JsValue> {
#[cfg(feature = "tracing")]
@@ -237,7 +261,7 @@ pub fn queue_microtask(task: impl FnOnce() + 'static) {
tachys::renderer::dom::queue_microtask(task);
}
/// Handle that is generated by [set_timeout] and can be used to clear the timeout.
/// Handle that is generated by [set_timeout_with_handle] and can be used to clear the timeout.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct TimeoutHandle(i32);
@@ -249,6 +273,20 @@ impl TimeoutHandle {
}
}
/// Executes the given function after the given duration of time has passed.
/// [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout).
///
/// ### Note about Context
///
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(
feature = "tracing",
instrument(level = "trace", skip_all, fields(duration = ?duration))
)]
pub fn set_timeout(cb: impl FnOnce() + 'static, duration: Duration) {
_ = set_timeout_with_handle(cb, duration);
}
/// Executes the given function after the given duration of time has passed, returning a cancelable handle.
/// [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout).
///
@@ -260,7 +298,7 @@ impl TimeoutHandle {
instrument(level = "trace", skip_all, fields(duration = ?duration))
)]
#[inline(always)]
pub fn set_timeout(
pub fn set_timeout_with_handle(
cb: impl FnOnce() + 'static,
duration: Duration,
) -> Result<TimeoutHandle, JsValue> {
@@ -353,7 +391,7 @@ pub fn debounce<T: 'static>(
if let Some(timer) = timer.write().unwrap().take() {
timer.clear();
}
let handle = set_timeout(
let handle = set_timeout_with_handle(
{
let cb = Arc::clone(&cb);
move || {
@@ -380,6 +418,20 @@ impl IntervalHandle {
}
}
/// Repeatedly calls the given function, with a delay of the given duration between calls.
/// See [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval).
///
/// ### Note about Context
///
/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with).
#[cfg_attr(
feature = "tracing",
instrument(level = "trace", skip_all, fields(duration = ?duration))
)]
pub fn set_interval(cb: impl Fn() + 'static, duration: Duration) {
_ = set_interval_with_handle(cb, duration);
}
/// Repeatedly calls the given function, with a delay of the given duration between calls,
/// returning a cancelable handle.
/// See [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval).
@@ -392,7 +444,7 @@ impl IntervalHandle {
instrument(level = "trace", skip_all, fields(duration = ?duration))
)]
#[inline(always)]
pub fn set_interval(
pub fn set_interval_with_handle(
cb: impl Fn() + 'static,
duration: Duration,
) -> Result<IntervalHandle, JsValue> {

View File

@@ -199,7 +199,7 @@ mod slot;
/// ```
///
/// 9. You can use the `node_ref` or `_ref` attribute to store a reference to its DOM element in a
/// [NodeRef](https://docs.rs/leptos/latest/leptos/prelude/struct.NodeRef.html) to use later.
/// [NodeRef](https://docs.rs/leptos/latest/leptos/struct.NodeRef.html) to use later.
/// ```rust
/// # use leptos::prelude::*;
///
@@ -505,9 +505,9 @@ pub fn include_view(tokens: TokenStream) -> TokenStream {
///
/// * `#[prop(into)]`: This will call `.into()` on any value passed into the component prop. (For example,
/// you could apply `#[prop(into)]` to a prop that takes
/// [Signal](https://docs.rs/leptos/latest/leptos/prelude/struct.Signal.html), which would
/// allow users to pass a [ReadSignal](https://docs.rs/leptos/latest/leptos/prelude/struct.ReadSignal.html) or
/// [RwSignal](https://docs.rs/leptos/latest/leptos/prelude/struct.RwSignal.html)
/// [Signal](https://docs.rs/leptos/latest/leptos/struct.Signal.html), which would
/// allow users to pass a [ReadSignal](https://docs.rs/leptos/latest/leptos/struct.ReadSignal.html) or
/// [RwSignal](https://docs.rs/leptos/latest/leptos/struct.RwSignal.html)
/// and automatically convert it.)
/// * `#[prop(optional)]`: If the user does not specify this property when they use the component,
/// it will be set to its default value. If the property type is `Option<T>`, values should be passed

View File

@@ -25,7 +25,7 @@ pub fn params_impl(ast: &syn::DeriveInput) -> proc_macro::TokenStream {
let span = field.span();
quote_spanned! {
span=> #ident: ::leptos_router::params::macro_helpers::Wrapper::<#ty>::__into_param(
span=> #ident: <#ty as ::leptos_router::params::IntoParam>::into_param(
map.get_str(#field_name_string),
#field_name_string
)?
@@ -39,8 +39,6 @@ pub fn params_impl(ast: &syn::DeriveInput) -> proc_macro::TokenStream {
let gen = quote! {
impl Params for #name {
fn from_map(map: &::leptos_router::params::ParamsMap) -> ::core::result::Result<Self, ::leptos_router::params::ParamsError> {
use ::leptos_router::params::macro_helpers::Fallback as _;
Ok(Self {
#(#fields,)*
})

View File

@@ -20,7 +20,7 @@ pub fn Demo1() -> impl IntoView {
// We need to add the 3D view onto the canvas post render.
Effect::new(move |_| {
_ = request_animation_frame(move || {
request_animation_frame(move || {
scene_sig.get_untracked().setup();
});
});

View File

@@ -95,7 +95,7 @@ pub fn App() -> impl IntoView {
// if expires_in isn't 0, then set a timeout that rerfresh a minute short of the refresh.
let expires_in = rw_expires_in.get();
if expires_in != 0 && email.get_untracked().is_some() {
let handle = set_timeout(
let handle = set_timeout_with_handle(
move || {
refresh_token.dispatch(RefreshToken {
email: email.get_untracked().unwrap(),

View File

@@ -23,11 +23,10 @@ pin_project! {
#[derive(Clone)]
#[allow(missing_docs)]
pub struct ScopedFuture<Fut> {
owner: Owner,
observer: Option<AnySubscriber>,
diagnostics: bool,
pub owner: Owner,
pub observer: Option<AnySubscriber>,
#[pin]
fut: Fut,
pub fut: Fut,
}
}
@@ -40,7 +39,6 @@ impl<Fut> ScopedFuture<Fut> {
Self {
owner,
observer,
diagnostics: true,
fut,
}
}
@@ -53,19 +51,19 @@ impl<Fut> ScopedFuture<Fut> {
Self {
owner,
observer: None,
diagnostics: false,
fut,
}
}
#[doc(hidden)]
#[track_caller]
pub fn new_untracked_with_diagnostics(fut: Fut) -> Self {
pub fn new_untracked_with_diagnostics(
fut: Fut,
) -> ScopedFutureUntrackedWithDiagnostics<Fut> {
let owner = Owner::current().unwrap_or_default();
Self {
ScopedFutureUntrackedWithDiagnostics {
owner,
observer: None,
diagnostics: true,
fut,
}
}
@@ -77,19 +75,41 @@ impl<Fut: Future> Future for ScopedFuture<Fut> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.owner.with(|| {
this.observer.with_observer(|| {
#[cfg(debug_assertions)]
let _maybe_guard = if *this.diagnostics {
None
} else {
Some(crate::diagnostics::SpecialNonReactiveZone::enter())
};
this.fut.poll(cx)
})
#[cfg(debug_assertions)]
let _maybe_guard = if this.observer.is_none() {
Some(crate::diagnostics::SpecialNonReactiveZone::enter())
} else {
None
};
this.observer.with_observer(|| this.fut.poll(cx))
})
}
}
pin_project! {
/// A [`Future`] wrapper that sets the [`Owner`] and [`Observer`] before polling the inner
/// `Future`, output of [`ScopedFuture::new_untracked_with_diagnostics`].
///
/// In leptos 0.9 this will be replaced with `ScopedFuture` itself.
#[derive(Clone)]
pub struct ScopedFutureUntrackedWithDiagnostics<Fut> {
owner: Owner,
observer: Option<AnySubscriber>,
#[pin]
fut: Fut,
}
}
impl<Fut: Future> Future for ScopedFutureUntrackedWithDiagnostics<Fut> {
type Output = Fut::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.owner
.with(|| this.observer.with_observer(|| this.fut.poll(cx)))
}
}
/// Utilities used to track whether asynchronous computeds are currently loading.
pub mod suspense {
use crate::{

View File

@@ -34,28 +34,14 @@ mod tests {
let owner = Owner::new();
owner.set();
#[cfg(not(feature = "nightly"))]
let _: Signal<usize> = (|| 2).into_reactive_value();
let _: Signal<usize, LocalStorage> = 2.into_reactive_value();
#[cfg(not(feature = "nightly"))]
let _: Signal<usize, LocalStorage> = (|| 2).into_reactive_value();
let _: Signal<String> = "str".into_reactive_value();
let _: Signal<String, LocalStorage> = "str".into_reactive_value();
// Confirm doesn't affect nightly function syntax:
#[cfg(all(rustc_nightly, feature = "nightly"))]
{
let sig: Signal<usize> = Signal::stored(2).into_reactive_value();
assert_eq!(sig(), 2);
}
// Confirm can be used in more complex expressions:
{
use crate::traits::Get;
let a: Signal<usize> = (|| 2).into_reactive_value();
let b: Signal<usize> = Signal::stored(2).into_reactive_value();
let _: Signal<usize> =
(move || a.get() + b.get()).into_reactive_value();
}
#[derive(TypedBuilder)]
struct Foo {
#[builder(setter(
@@ -67,6 +53,7 @@ mod tests {
}
assert_eq!(Foo::builder().sig(2).build().sig.get_untracked(), 2);
#[cfg(not(feature = "nightly"))]
assert_eq!(Foo::builder().sig(|| 2).build().sig.get_untracked(), 2);
assert_eq!(
Foo::builder()

View File

@@ -145,90 +145,16 @@ macro_rules! impl_get_fn_traits_get_arena {
};
}
macro_rules! impl_get_fn_traits_get_arena_with_readable_deref_impl {
($($ty:ident),*) => {
$(
/// Allow calling $ty() syntax
impl<T: Clone + 'static, S: Storage<T> + 'static> std::ops::Deref
for $ty<T, S>
where
$ty<T, S>: crate::traits::Get<Value = T>,
$ty<T, S>: Get, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>>
{
type Target = dyn Fn() -> T;
fn deref(&self) -> &Self::Target {
unsafe { readable_deref_impl::ReadableDerefImpl::deref_impl(self) }
}
}
impl<T: Clone + 'static, S: Storage<T> + 'static> readable_deref_impl::ReadableDerefImpl for $ty<T, S>
where
$ty<T, S>: crate::traits::Get<Value = T>,
$ty<T, S>: Get, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>>
{
}
)*
};
}
impl_get_fn_traits_get![ArcReadSignal, ArcRwSignal];
impl_get_fn_traits_get_arena![
ReadSignal,
RwSignal,
ArcMemo,
ArcSignal,
Signal,
MaybeSignal,
Memo,
MaybeProp
];
impl_get_fn_traits_get_arena_with_readable_deref_impl![ArcSignal, Signal];
impl_set_fn_traits![ArcRwSignal, ArcWriteSignal];
impl_set_fn_traits_arena![RwSignal, WriteSignal, SignalSetter];
mod readable_deref_impl {
/// Derived from the implementation and original creaters at dioxus
/// https://docs.rs/dioxus-signals/0.6.3/src/dioxus_signals/signal.rs.html#485-494
pub trait ReadableDerefImpl: crate::traits::Get {
/// SAFETY: You must call this function directly with `self` as the argument.
/// This function relies on the size of the object you return from the deref
/// being the same as the object you pass in
#[doc(hidden)]
unsafe fn deref_impl<'a>(&self) -> &'a dyn Fn() -> Self::Value
where
Self: Sized + 'a,
Self::Value: Clone + 'static,
{
// https://github.com/dtolnay/case-studies/tree/master/callable-types
// First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit<Self>).
let uninit_callable = std::mem::MaybeUninit::<Self>::uninit();
// Then move that value into the closure. We assume that the closure now has a in memory layout of Self.
let uninit_closure =
move || Self::get(unsafe { &*uninit_callable.as_ptr() });
// Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure.
let size_of_closure = std::mem::size_of_val(&uninit_closure);
assert_eq!(size_of_closure, std::mem::size_of::<Self>());
// Then cast the lifetime of the closure to the lifetime of &self.
fn cast_lifetime<'a, T>(_a: &T, b: &'a T) -> &'a T {
b
}
let reference_to_closure = cast_lifetime(
{
// The real closure that we will never use.
&uninit_closure
},
#[allow(clippy::missing_transmute_annotations)]
// We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self.
unsafe {
std::mem::transmute(self)
},
);
// Cast the closure to a trait object.
reference_to_closure as &_
}
}
}

View File

@@ -1118,13 +1118,17 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
#[doc(hidden)]
pub struct __IntoReactiveValueMarkerSignalFromReactiveClosure;
#[cfg(not(feature = "nightly"))]
#[doc(hidden)]
pub struct __IntoReactiveValueMarkerSignalStrOutputToString;
#[cfg(not(feature = "nightly"))]
#[doc(hidden)]
pub struct __IntoReactiveValueMarkerOptionalSignalFromReactiveClosureAlways;
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
Signal<T, SyncStorage>,
@@ -1139,6 +1143,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
ArcSignal<T, SyncStorage>,
@@ -1153,6 +1158,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
Signal<T, LocalStorage>,
@@ -1167,6 +1173,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
ArcSignal<T, LocalStorage>,
@@ -1181,6 +1188,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<F>
crate::IntoReactiveValue<
Signal<String, SyncStorage>,
@@ -1194,6 +1202,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<F>
crate::IntoReactiveValue<
ArcSignal<String, SyncStorage>,
@@ -1207,6 +1216,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<F>
crate::IntoReactiveValue<
Signal<String, LocalStorage>,
@@ -1220,6 +1230,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<F>
crate::IntoReactiveValue<
ArcSignal<String, LocalStorage>,
@@ -1233,6 +1244,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
Signal<Option<T>, SyncStorage>,
@@ -1247,6 +1259,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
ArcSignal<Option<T>, SyncStorage>,
@@ -1261,6 +1274,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
Signal<Option<T>, LocalStorage>,
@@ -1275,6 +1289,7 @@ pub mod read {
}
}
#[cfg(not(feature = "nightly"))]
impl<T, F>
crate::IntoReactiveValue<
ArcSignal<Option<T>, LocalStorage>,

View File

@@ -140,20 +140,13 @@ where
}
fn track_field(&self) {
let mut full_path = self.path().into_iter().collect::<StorePath>();
let inner = self
.inner
.get_trigger(self.inner.path().into_iter().collect());
inner.this.track();
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
// tracks `this` for all ancestors: i.e., it will track any change that is made
// directly to one of its ancestors, but not a change made to a *child* of an ancestor
// (which would end up with every subfield tracking its own siblings, because they are
// children of its parent)
while !full_path.is_empty() {
full_path.pop();
let inner = self.get_trigger(full_path.clone());
inner.this.track();
}
}
}

View File

@@ -57,11 +57,11 @@
//! # if false { // don't run effect in doctests
//! Effect::new(move |_| {
//! // you can access individual store fields with a getter
//! println!("user: {:?}", &*store.user().read());
//! println!("todos: {:?}", &*store.todos().read());
//! });
//! # }
//!
//! // won't notify the effect that listens to `user`
//! // won't notify the effect that listens to `todos`
//! store.todos().write().push(Todo {
//! label: "Test".to_string(),
//! completed: false,

View File

@@ -658,7 +658,7 @@ pub fn RoutingProgress(
move |prev: Option<Option<IntervalHandle>>| {
if is_routing.get() && !is_showing.get() {
set_is_showing.set(true);
set_interval(
set_interval_with_handle(
move || {
set_progress.update(|n| *n += percent_per_increment);
},
@@ -670,7 +670,7 @@ pub fn RoutingProgress(
prev?
} else {
set_progress.set(100.0);
_ = set_timeout(
set_timeout(
move || {
set_progress.set(0.0);
set_is_showing.set(false);

View File

@@ -131,14 +131,14 @@ where
if !IS_NAVIGATING.load(Ordering::Relaxed) {
IS_NAVIGATING.store(true, Ordering::Relaxed);
_ = request_animation_frame({
request_animation_frame({
let navigate = navigate.clone();
let nav_options = nav_options.clone();
move || {
navigate(&new_url, nav_options.clone());
IS_NAVIGATING.store(false, Ordering::Relaxed)
}
});
})
}
});

View File

@@ -259,7 +259,7 @@ impl LocationProvider for BrowserUrl {
if url.origin() == current_origin {
let navigate = navigate.clone();
// delay by a tick here, so that the Action updates *before* the redirect
_ = request_animation_frame(move || {
request_animation_frame(move || {
navigate(&url.href(), Default::default());
});
// Use set_href() if the conditions for client-side navigation were not satisfied

View File

@@ -199,56 +199,31 @@ where
}
}
/// Helpers for the `Params` derive macro to allow specialization without nightly.
pub mod macro_helpers {
use crate::params::{IntoParam, ParamsError};
// TODO can we support Option<T> and T in a non-nightly way?
#[cfg(all(feature = "nightly", rustc_nightly))]
mod option_param {
use super::{IntoParam, ParamsError};
use std::{str::FromStr, sync::Arc};
/// This struct is never actually created; it just exists so that we can impl associated
/// functions on it.
pub struct Wrapper<T>(T);
auto trait NotOption {}
impl<T> !NotOption for Option<T> {}
impl<T: IntoParam> Wrapper<T> {
/// This is the 'preferred' impl to be used for all `T` that implement `IntoParam`.
/// Because it is directly on the struct, the compiler will pick this over the impl from
/// the `Fallback` trait.
#[inline]
pub fn __into_param(
value: Option<&str>,
name: &str,
) -> Result<T, ParamsError> {
T::into_param(value, name)
}
}
/// If the Fallback trait is in scope, then the compiler has two possible implementations for
/// `__into_params`. It will pick the one from this trait if the inherent one doesn't exist.
/// (which it won't if `T` does not implement `IntoParam`)
pub trait Fallback<T>: Sized
impl<T> IntoParam for T
where
T: FromStr,
T: FromStr + NotOption,
<T as FromStr>::Err: std::error::Error + Send + Sync + 'static,
{
/// Fallback function in case the inherent impl on the Wrapper struct does not exist for
/// `T`
#[inline]
fn __into_param(
fn into_param(
value: Option<&str>,
name: &str,
) -> Result<T, ParamsError> {
) -> Result<Self, ParamsError> {
let value = value
.ok_or_else(|| ParamsError::MissingParam(name.to_string()))?;
T::from_str(value).map_err(|e| ParamsError::Params(Arc::new(e)))
Self::from_str(value).map_err(|e| ParamsError::Params(Arc::new(e)))
}
}
impl<T> Fallback<T> for Wrapper<T>
where
T: FromStr,
<T as FromStr>::Err: std::error::Error + Send + Sync + 'static,
{
}
}
/// Errors that can occur while parsing params using [`Params`].
#[derive(Error, Debug, Clone)]
pub enum ParamsError {

View File

@@ -58,8 +58,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, E> {
let string_data = req.as_query().unwrap_or_default();
let args = serde_qs::Config::new()
.use_form_encoding(true)
let args = serde_qs::Config::new(5, false)
.deserialize_str::<Self>(string_data)
.map_err(|e| {
ServerFnErrorErr::Args(e.to_string()).into_app_error()
@@ -98,8 +97,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, E> {
let string_data = req.try_into_string().await?;
let args = serde_qs::Config::new()
.use_form_encoding(true)
let args = serde_qs::Config::new(5, false)
.deserialize_str::<Self>(&string_data)
.map_err(|e| {
ServerFnErrorErr::Args(e.to_string()).into_app_error()
@@ -138,8 +136,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, E> {
let string_data = req.as_query().unwrap_or_default();
let args = serde_qs::Config::new()
.use_form_encoding(true)
let args = serde_qs::Config::new(5, false)
.deserialize_str::<Self>(string_data)
.map_err(|e| {
ServerFnErrorErr::Args(e.to_string()).into_app_error()
@@ -178,8 +175,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, E> {
let string_data = req.try_into_string().await?;
let args = serde_qs::Config::new()
.use_form_encoding(true)
let args = serde_qs::Config::new(5, false)
.deserialize_str::<Self>(&string_data)
.map_err(|e| {
ServerFnErrorErr::Args(e.to_string()).into_app_error()
@@ -218,8 +214,7 @@ where
{
async fn from_req(req: Request) -> Result<Self, E> {
let string_data = req.try_into_string().await?;
let args = serde_qs::Config::new()
.use_form_encoding(true)
let args = serde_qs::Config::new(5, false)
.deserialize_str::<Self>(&string_data)
.map_err(|e| {
ServerFnErrorErr::Args(e.to_string()).into_app_error()

View File

@@ -309,16 +309,6 @@ impl ServerFnCall {
.collect::<TokenStream2>()
}
/// Get the lint attributes for the server function.
pub fn lint_attrs(&self) -> TokenStream2 {
// pass through lint attributes from the function body
self.body
.lint_attrs
.iter()
.map(|lint_attr| quote!(#lint_attr))
.collect::<TokenStream2>()
}
fn fn_name_as_str(&self) -> String {
self.body.ident.to_string()
}
@@ -398,8 +388,6 @@ impl ServerFnCall {
PathInfo::None => quote! {},
};
let lint_attrs = self.lint_attrs();
let vis = &self.body.vis;
let struct_name = self.struct_name();
let fields = self
@@ -422,7 +410,6 @@ impl ServerFnCall {
#docs
#[derive(Debug, #derives)]
#addl_path
#lint_attrs
#vis struct #struct_name {
#(#fields),*
}
@@ -1478,8 +1465,6 @@ pub struct ServerFnBody {
pub block: TokenStream2,
/// The documentation of the server function.
pub docs: Vec<(String, Span)>,
/// The lint attributes of the server function.
pub lint_attrs: Vec<Attribute>,
/// The middleware attributes applied to the server function.
pub middlewares: Vec<Middleware>,
}
@@ -1537,27 +1522,6 @@ impl Parse for ServerFnBody {
};
!attr.path.is_ident("doc")
});
let lint_attrs = attrs
.iter()
.filter_map(|attr| {
if attr.path().is_ident("allow")
|| attr.path().is_ident("warn")
|| attr.path().is_ident("deny")
|| attr.path().is_ident("forbid")
{
return Some(attr.clone());
}
None
})
.collect();
attrs.retain(|attr| {
!attr.path().is_ident("allow")
&& !attr.path().is_ident("warn")
&& !attr.path().is_ident("deny")
&& !attr.path().is_ident("forbid")
});
// extract all #[middleware] attributes, removing them from signature of dummy
let mut middlewares: Vec<Middleware> = vec![];
attrs.retain(|attr| {
@@ -1593,7 +1557,6 @@ impl Parse for ServerFnBody {
block,
attrs,
docs,
lint_attrs,
middlewares,
})
}

View File

@@ -72,7 +72,6 @@ web-sys = { features = [
"SecurityPolicyViolationEvent",
"StorageEvent",
"SubmitEvent",
"ToggleEvent",
"TouchEvent",
"TransitionEvent",
"UiEvent",
@@ -180,7 +179,6 @@ default = ["testing"]
delegation = [] # enables event delegation
error-hook = []
hydrate = []
lazy = []
islands = ["dep:serde", "dep:serde_json"]
ssr = []
oco = ["dep:oco_ref"]

View File

@@ -608,7 +608,7 @@ generate_event_types! {
animation start: AnimationEvent,
aux click: MouseEvent,
before input: InputEvent,
before toggle: ToggleEvent,
before toggle: Event, // web_sys does not include `ToggleEvent`
#[does_not_bubble]
blur: FocusEvent,
#[does_not_bubble]
@@ -719,7 +719,7 @@ generate_event_types! {
#[does_not_bubble]
time update: Event,
#[does_not_bubble]
toggle: ToggleEvent,
toggle: Event,
touch cancel: TouchEvent,
touch end: TouchEvent,
touch move: TouchEvent,

View File

@@ -17,7 +17,7 @@ use crate::{
};
use futures::future::{join, join_all};
use std::{any::TypeId, fmt::Debug};
#[cfg(any(feature = "ssr", all(feature = "hydrate", feature = "lazy")))]
#[cfg(any(feature = "ssr", feature = "hydrate"))]
use std::{future::Future, pin::Pin};
/// A type-erased view. This can be used if control flow requires that multiple different types of
@@ -67,10 +67,10 @@ pub struct AnyView {
resolve: fn(Erased) -> Pin<Box<dyn Future<Output = AnyView> + Send>>,
#[cfg(feature = "ssr")]
dry_resolve: fn(&mut Erased),
#[cfg(all(feature = "hydrate", not(feature = "lazy")))]
#[cfg(feature = "hydrate")]
#[allow(clippy::type_complexity)]
hydrate_from_server: fn(Erased, &Cursor, &PositionState) -> AnyViewState,
#[cfg(all(feature = "hydrate", feature = "lazy"))]
#[cfg(feature = "hydrate")]
#[allow(clippy::type_complexity)]
hydrate_async: fn(
Erased,
@@ -291,7 +291,7 @@ where
}
}
#[cfg(all(feature = "hydrate", not(feature = "lazy")))]
#[cfg(feature = "hydrate")]
fn hydrate_from_server<T: RenderHtml + 'static>(
value: Erased,
cursor: &Cursor,
@@ -313,7 +313,7 @@ where
}
}
#[cfg(all(feature = "hydrate", feature = "lazy"))]
#[cfg(feature = "hydrate")]
fn hydrate_async<T: RenderHtml + 'static>(
value: Erased,
cursor: &Cursor,
@@ -367,9 +367,9 @@ where
to_html_async: to_html_async::<T::Owned>,
#[cfg(feature = "ssr")]
to_html_async_ooo: to_html_async_ooo::<T::Owned>,
#[cfg(all(feature = "hydrate", not(feature = "lazy")))]
#[cfg(feature = "hydrate")]
hydrate_from_server: hydrate_from_server::<T::Owned>,
#[cfg(all(feature = "hydrate", feature = "lazy"))]
#[cfg(feature = "hydrate")]
hydrate_async: hydrate_async::<T::Owned>,
value: Erased::new(value),
}
@@ -572,7 +572,7 @@ impl RenderHtml for AnyView {
cursor: &Cursor,
position: &PositionState,
) -> Self::State {
#[cfg(all(feature = "hydrate", not(feature = "lazy")))]
#[cfg(feature = "hydrate")]
{
if FROM_SERVER {
(self.hydrate_from_server)(self.value, cursor, position)
@@ -583,14 +583,6 @@ impl RenderHtml for AnyView {
);
}
}
#[cfg(all(feature = "hydrate", feature = "lazy"))]
{
use futures::FutureExt;
(self.hydrate_async)(self.value, cursor, position)
.now_or_never()
.unwrap()
}
#[cfg(not(feature = "hydrate"))]
{
_ = cursor;
@@ -607,22 +599,12 @@ impl RenderHtml for AnyView {
cursor: &Cursor,
position: &PositionState,
) -> Self::State {
#[cfg(all(feature = "hydrate", feature = "lazy"))]
#[cfg(feature = "hydrate")]
{
#[cfg(all(feature = "hydrate", feature = "lazy"))]
let state =
(self.hydrate_async)(self.value, cursor, position).await;
state
}
#[cfg(all(feature = "hydrate", not(feature = "lazy")))]
{
_ = cursor;
_ = position;
panic!(
"the `lazy` feature on `tachys` must be activated to use lazy \
hydration"
);
}
#[cfg(not(feature = "hydrate"))]
{
_ = cursor;

View File

@@ -23,32 +23,14 @@ pub fn keyed<T, I, K, KF, VF, VFS, V>(
) -> Keyed<T, I, K, KF, VF, VFS, V>
where
I: IntoIterator<Item = T>,
K: Eq + Hash + SerializableKey + 'static,
K: Eq + Hash + 'static,
KF: Fn(&T) -> K,
V: Render,
VF: Fn(usize, T) -> (VFS, V),
VFS: Fn(usize),
{
Keyed {
#[cfg(not(feature = "ssr"))]
items: Some(items),
#[cfg(feature = "ssr")]
items: None,
#[cfg(feature = "ssr")]
ssr_items: items
.into_iter()
.enumerate()
.map(|(i, t)| {
let key = if cfg!(feature = "islands") {
let key = (key_fn)(&t);
key.ser_key()
} else {
String::new()
};
let (_, view) = (view_fn)(i, t);
(key, view)
})
.collect::<Vec<_>>(),
items,
key_fn,
view_fn,
}
@@ -63,9 +45,7 @@ where
VF: Fn(usize, T) -> (VFS, V),
VFS: Fn(usize),
{
items: Option<I>,
#[cfg(feature = "ssr")]
ssr_items: Vec<(String, V)>,
items: I,
key_fn: KF,
view_fn: VF,
}
@@ -126,13 +106,14 @@ where
VFS: Fn(usize),
{
type State = KeyedState<K, VFS, V>;
// TODO fallible state and try_build()/try_rebuild() here
fn build(self) -> Self::State {
let items = self.items.into_iter().flatten();
let items = self.items.into_iter();
let (capacity, _) = items.size_hint();
let mut hashed_items =
FxIndexSet::with_capacity_and_hasher(capacity, Default::default());
let mut rendered_items = Vec::with_capacity(capacity);
let mut rendered_items = Vec::new();
for (index, item) in items.enumerate() {
hashed_items.insert((self.key_fn)(&item));
let (set_index, view) = (self.view_fn)(index, item);
@@ -153,7 +134,7 @@ where
hashed_items,
ref mut rendered_items,
} = state;
let new_items = self.items.into_iter().flatten();
let new_items = self.items.into_iter();
let (capacity, _) = new_items.size_hint();
let mut new_hashed_items =
FxIndexSet::with_capacity_and_hasher(capacity, Default::default());
@@ -217,8 +198,6 @@ where
{
let Keyed {
items,
#[cfg(feature = "ssr")]
ssr_items,
key_fn,
view_fn,
} = self;
@@ -226,11 +205,6 @@ where
Keyed {
items,
key_fn,
#[cfg(feature = "ssr")]
ssr_items: ssr_items
.into_iter()
.map(|(k, v)| (k, v.add_any_attr(attr.clone())))
.collect(),
view_fn: Box::new(move |index, item| {
let (index, view) = view_fn(index, item);
(index, view.add_any_attr(attr.clone()))
@@ -255,39 +229,21 @@ where
const MIN_LENGTH: usize = 0;
fn dry_resolve(&mut self) {
#[cfg(feature = "ssr")]
for view in &mut self.ssr_items {
view.dry_resolve();
}
// TODO...
}
async fn resolve(self) -> Self::AsyncOutput {
#[cfg(feature = "ssr")]
{
futures::future::join_all(
self.ssr_items.into_iter().map(|(_, view)| view.resolve()),
)
.await
.into_iter()
.collect::<Vec<_>>()
}
#[cfg(not(feature = "ssr"))]
{
futures::future::join_all(
self.items.into_iter().flatten().enumerate().map(
|(index, item)| {
let (_, view) = (self.view_fn)(index, item);
view.resolve()
},
),
)
.await
.into_iter()
.collect::<Vec<_>>()
}
futures::future::join_all(self.items.into_iter().enumerate().map(
|(index, item)| {
let (_, view) = (self.view_fn)(index, item);
view.resolve()
},
))
.await
.into_iter()
.collect::<Vec<_>>()
}
#[allow(unused)]
fn to_html_with_buf(
self,
buf: &mut String,
@@ -299,9 +255,8 @@ where
if mark_branches && escape {
buf.open_branch("for");
}
#[cfg(feature = "ssr")]
for item in self.ssr_items {
for (index, item) in self.items.into_iter().enumerate() {
let (_, item) = (self.view_fn)(index, item);
if mark_branches && escape {
buf.open_branch("item");
}
@@ -323,7 +278,6 @@ where
buf.push_str("<!>");
}
#[allow(unused)]
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
buf: &mut StreamBuilder,
@@ -335,10 +289,13 @@ where
if mark_branches && escape {
buf.open_branch("for");
}
#[cfg(feature = "ssr")]
for (key, item) in self.ssr_items {
let branch_name = mark_branches.then(|| format!("item-{key}"));
for (index, item) in self.items.into_iter().enumerate() {
let branch_name = mark_branches.then(|| {
let key = (self.key_fn)(&item);
let key = key.ser_key();
format!("item-{key}")
});
let (_, item) = (self.view_fn)(index, item);
if mark_branches && escape {
buf.open_branch(branch_name.as_ref().unwrap());
}
@@ -354,7 +311,6 @@ where
}
*position = Position::NextChild;
}
if mark_branches && escape {
buf.close_branch("for");
}
@@ -378,11 +334,11 @@ where
.expect("parent of keyed list should be an element");
// build list
let items = self.items.into_iter().flatten();
let items = self.items.into_iter();
let (capacity, _) = items.size_hint();
let mut hashed_items =
FxIndexSet::with_capacity_and_hasher(capacity, Default::default());
let mut rendered_items = Vec::with_capacity(capacity);
let mut rendered_items = Vec::new();
for (index, item) in items.enumerate() {
hashed_items.insert((self.key_fn)(&item));
let (set_index, view) = (self.view_fn)(index, item);
@@ -417,11 +373,11 @@ where
.expect("parent of keyed list should be an element");
// build list
let items = self.items.into_iter().flatten();
let items = self.items.into_iter();
let (capacity, _) = items.size_hint();
let mut hashed_items =
FxIndexSet::with_capacity_and_hasher(capacity, Default::default());
let mut rendered_items = Vec::with_capacity(capacity);
let mut rendered_items = Vec::new();
for (index, item) in items.enumerate() {
hashed_items.insert((self.key_fn)(&item));
let (set_index, view) = (self.view_fn)(index, item);