-
-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buggy Resource
/Transition
#1742
Comments
Another (buggy) example where I wanted to implement a fade-in for newly added elements:
#[cfg(feature = "ssr")]
use std::sync::Mutex;
#[cfg(feature = "ssr")]
static DATA: Mutex<Vec<String>> = Mutex::new(Vec::new());
#[server]
async fn fetch_data() -> Result<Vec<String>, ServerFnError> {
std::thread::sleep(std::time::Duration::from_millis(1250));
Ok(DATA.lock().unwrap().clone())
}
#[server]
async fn add_data(data: String) -> Result<(), ServerFnError> {
std::thread::sleep(std::time::Duration::from_millis(1250));
DATA.lock().unwrap().push(data);
Ok(())
}
#[component]
fn HomePage() -> impl IntoView {
let add_data = create_server_action::<AddData>();
let data = create_resource(add_data.version(), |_| fetch_data());
let data_len = move || {
data.with(|data| {
if let Some(Ok(data)) = data {
data.iter().count()
} else {
0
}
})
};
view! {
<Transition fallback=move || view! { <p>Loading...</p> }>
<div>{data_len}</div>
<ul>
<For
each=move || data.get().map(|d| d.unwrap()).unwrap_or_else(|| vec![])
key=|d| d.clone()
view=move |d| view! { <div class="fade">{d}</div> }
/>
</ul>
</Transition>
<ActionForm action=add_data>
<input type="text" name="data" />
<button type="submit">Add</button>
</ActionForm>
}
}
@keyframes fade {
0% {
transform: translateY(40px);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
.fade {
animation: fade 0.6s ease;
} But it seems to fade in all elements and not only the new one. Also it shows the first added data for every following add. bug.webm |
@cometship The second example is caused by an unrelated issue, and has turned up a bug in which |
Was not sure if it is related or not 😅 |
Describe the bug
When using
create_server_action
/create_server_multi_action
, a derived value with.with()
and aTransition
the DOM-Element gets duplicated the first two times theResource
is updated.Some crude minimal repro:
Leptos Dependencies
To Reproduce
Steps to reproduce the behavior:
v0.5.0-rc2
).0
above the input.Add
.1
and below another1
.Add
again.1
and below2
.Add
again.3
.Add
press works as expected.Expected behavior
It should show just one count and that count should update with every
Add
press.Screenshots
The text was updated successfully, but these errors were encountered: