The contents were occasionally hidden by commenting #2012
-
Below is the definition of one of my components: #[component]
pub fn PredictedNgRateTd(batch: String, previous_n_days: u8) -> impl IntoView {
let predicted_count_source = batch.clone();
let predicted_count = create_resource(
move || (predicted_count_source.clone(), previous_n_days),
|(name, previous_n_days)| async move { get_predicted_count(name, previous_n_days).await },
);
let predicted_ng_count_source = batch.clone();
let predicted_ng_count = create_resource(
move || (predicted_ng_count_source.clone(), previous_n_days),
|(name, previous_n_days)| async move { get_predicted_ng_count(name, previous_n_days).await },
);
view! {
<Suspense fallback=move || {
view! {
<td class="border px-4 py-2">
<div class="bg-gray-300 h-2 w-12 animate-pulse"></div>
</td>
}
}>
<ErrorBoundary fallback=move |_| {
view! { <span>"加载失败"</span> }
}>
<td class="border px-4 py-2">
{move || {
predicted_ng_count
.and_then(|ng_count| {
predicted_count
.and_then(|count| {
format!("{:.1}%", *ng_count as f32 / *count as f32)
})
})
}}
</td>
</ErrorBoundary>
</Suspense>
}
} Inside the If I terminate the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm not quite sure how to reproduce this issue to explore it. Do you have a reproducible example? It seems like some kind of hydration error but I'm not sure exactly what's going on. |
Beta Was this translation helpful? Give feedback.
Okay, so here's my understanding: On the server, the
<Suspense/>
renders once initially to register all resource reads that happen in it, and when they've all resolved, it renders the actual children to HTML. Because of the nested.and_then()
,posts1
is actually not registered as part of the<Suspense/>
on the server, because when it's first renderedposts
is stillNone
.The good news is that it's relatively easy to fix this by matching a bit more manually on the two resources