Merge pull request #193 from DioxusLabs/jk/warn-on-reuse
fix: diffing allows component reuse
This commit is contained in:
1 file changed
+17
-20
+17
-20
@@ -270,26 +270,23 @@ impl<'b> DiffState<'b> {
|
|||||||
fn create_component_node(&mut self, vcomponent: &'b VComponent<'b>) -> usize {
|
fn create_component_node(&mut self, vcomponent: &'b VComponent<'b>) -> usize {
|
||||||
let parent_idx = self.current_scope().unwrap();
|
let parent_idx = self.current_scope().unwrap();
|
||||||
|
|
||||||
// ensure this scope doesn't already exist if we're trying to create it
|
// the component might already exist - if it does, we need to reuse it
|
||||||
debug_assert!(
|
// this makes figure out when to drop the component more complicated
|
||||||
vcomponent
|
let new_idx = if let Some(idx) = vcomponent.scope.get() {
|
||||||
.scope
|
assert!(self.scopes.get_scope(idx).is_some());
|
||||||
.get()
|
idx
|
||||||
.and_then(|f| self.scopes.get_scope(f))
|
} else {
|
||||||
.is_none(),
|
// Insert a new scope into our component list
|
||||||
"component scope already exists"
|
let props: Box<dyn AnyProps + 'b> = vcomponent.props.borrow_mut().take().unwrap();
|
||||||
);
|
let props: Box<dyn AnyProps + 'static> = unsafe { std::mem::transmute(props) };
|
||||||
|
self.scopes.new_with_key(
|
||||||
// Insert a new scope into our component list
|
vcomponent.user_fc,
|
||||||
let props: Box<dyn AnyProps + 'b> = vcomponent.props.borrow_mut().take().unwrap();
|
props,
|
||||||
let props: Box<dyn AnyProps + 'static> = unsafe { std::mem::transmute(props) };
|
Some(parent_idx),
|
||||||
let new_idx = self.scopes.new_with_key(
|
self.element_stack.last().copied().unwrap(),
|
||||||
vcomponent.user_fc,
|
0,
|
||||||
props,
|
)
|
||||||
Some(parent_idx),
|
};
|
||||||
self.element_stack.last().copied().unwrap(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Actually initialize the caller's slot with the right address
|
// Actually initialize the caller's slot with the right address
|
||||||
vcomponent.scope.set(Some(new_idx));
|
vcomponent.scope.set(Some(new_idx));
|
||||||
|
|||||||
Reference in new issue
Block a user