Deduplicate suspensions when considering subsequent renders for suspensions (#3099)

* FIx duplicate suspension.

* Fix tests.

* Fix tests.

* Fix tests.
This commit is contained in:
Kaede Hoshikawa 2023-02-02 02:04:43 +09:00 committed by GitHub
parent 456a05ba40
commit 65b930acb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -87,6 +87,11 @@ mod feat_csr_ssr {
return false;
}
// If a suspension already exists, ignore it.
if self.suspensions.iter().any(|n| n == &m) {
return false;
}
self.suspensions.push(m);
true

View File

@ -786,3 +786,40 @@ async fn resume_after_unmount() {
let result = obtain_result();
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!");
}