mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Deduplicate suspensions when considering subsequent renders for suspensions (#3099)
* FIx duplicate suspension. * Fix tests. * Fix tests. * Fix tests.
This commit is contained in:
parent
456a05ba40
commit
65b930acb6
@ -87,6 +87,11 @@ mod feat_csr_ssr {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a suspension already exists, ignore it.
|
||||||
|
if self.suspensions.iter().any(|n| n == &m) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
self.suspensions.push(m);
|
self.suspensions.push(m);
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|||||||
@ -786,3 +786,40 @@ async fn resume_after_unmount() {
|
|||||||
let result = obtain_result();
|
let result = obtain_result();
|
||||||
assert_eq!(result.as_str(), "<div>Content replacement</div>");
|
assert_eq!(result.as_str(), "<div>Content replacement</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
async fn test_duplicate_suspension() {
|
||||||
|
use yew::html::ChildrenProps;
|
||||||
|
|
||||||
|
#[function_component]
|
||||||
|
fn FetchingProvider(props: &ChildrenProps) -> HtmlResult {
|
||||||
|
use_future(|| async {
|
||||||
|
sleep(Duration::ZERO).await;
|
||||||
|
})?;
|
||||||
|
Ok(html! { <>{props.children.clone()}</> })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[function_component]
|
||||||
|
fn Child() -> Html {
|
||||||
|
html! {<div id="result">{"hello!"}</div>}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[function_component]
|
||||||
|
fn App() -> Html {
|
||||||
|
let fallback = Html::default();
|
||||||
|
html! {
|
||||||
|
<Suspense {fallback}>
|
||||||
|
<FetchingProvider>
|
||||||
|
<Child />
|
||||||
|
</FetchingProvider>
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yew::Renderer::<App>::with_root(gloo::utils::document().get_element_by_id("output").unwrap())
|
||||||
|
.render();
|
||||||
|
|
||||||
|
sleep(Duration::from_millis(50)).await;
|
||||||
|
let result = obtain_result();
|
||||||
|
assert_eq!(result.as_str(), "hello!");
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user