Skip to content

Commit

Permalink
Fix re-entrancy bug. TodoMVC should work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekdreery committed Jul 8, 2023
1 parent a64be37 commit b5ca1d2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions crates/xilem_html/src/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<El, ViewSeq> Element<El, ViewSeq> {
pub struct ElementState<ViewSeqState> {
child_states: ViewSeqState,
child_elements: Vec<Pod>,
scratch: Vec<Pod>,
}

/// Create a new element view
Expand Down Expand Up @@ -140,6 +141,7 @@ where
let state = ElementState {
child_states,
child_elements,
scratch: vec![],
};
(id, state, el)
}
Expand Down Expand Up @@ -216,13 +218,10 @@ where
}

// update children
SCRATCH.with(|scratch| {
let mut scratch = scratch.borrow_mut();
let mut splice = VecSplice::new(&mut state.child_elements, &mut *scratch);
changed |= cx.with_id(*id, |cx| {
self.children
.rebuild(cx, &prev.children, &mut state.child_states, &mut splice)
});
let mut splice = VecSplice::new(&mut state.child_elements, &mut state.scratch);
changed |= cx.with_id(*id, |cx| {
self.children
.rebuild(cx, &prev.children, &mut state.child_states, &mut splice)
});
if changed.contains(ChangeFlags::STRUCTURE) {
// This is crude and will result in more DOM traffic than needed.
Expand Down

0 comments on commit b5ca1d2

Please sign in to comment.