@@ -6,7 +6,6 @@ use crate::dom_bundle::{DomBundle, Reconcilable};
66use crate :: html:: { AnyScope , NodeRef } ;
77use crate :: virtual_dom:: Key ;
88use crate :: virtual_dom:: VPortal ;
9- use std:: borrow:: BorrowMut ;
109use web_sys:: Element ;
1110
1211/// The bundle implementation to [VPortal].
@@ -15,7 +14,7 @@ pub struct BPortal {
1514 /// The element under which the content is inserted.
1615 host : Element ,
1716 /// The next sibling after the inserted content
18- next_sibling : NodeRef ,
17+ inner_sibling : NodeRef ,
1918 /// The inserted node
2019 node : Box < BNode > ,
2120}
@@ -41,18 +40,18 @@ impl Reconcilable for VPortal {
4140 _parent : & Element ,
4241 host_next_sibling : NodeRef ,
4342 ) -> ( NodeRef , Self :: Bundle ) {
44- let VPortal {
43+ let Self {
4544 host,
46- next_sibling ,
45+ inner_sibling ,
4746 node,
4847 } = self ;
49- let ( _, inner) = node. attach ( parent_scope, & host, next_sibling . clone ( ) ) ;
48+ let ( _, inner) = node. attach ( parent_scope, & host, inner_sibling . clone ( ) ) ;
5049 (
5150 host_next_sibling,
5251 BPortal {
5352 host,
5453 node : Box :: new ( inner) ,
55- next_sibling ,
54+ inner_sibling ,
5655 } ,
5756 )
5857 }
@@ -62,25 +61,33 @@ impl Reconcilable for VPortal {
6261 parent_scope : & AnyScope ,
6362 parent : & Element ,
6463 next_sibling : NodeRef ,
65- ancestor : & mut BNode ,
64+ bundle : & mut BNode ,
6665 ) -> NodeRef {
67- if let BNode :: BPortal ( portal) = ancestor {
68- let old_host = std:: mem:: replace ( & mut portal. host , self . host ) ;
69- let old_sibling = std:: mem:: replace ( & mut portal. next_sibling , self . next_sibling ) ;
70- let node = & mut portal. node ;
71- if old_host != portal. host || old_sibling != portal. next_sibling {
72- // Remount the inner node somewhere else instead of diffing
73- // Move the node, but keep the state
74- node. shift ( & portal. host , portal. next_sibling . clone ( ) ) ;
66+ let portal = match bundle {
67+ BNode :: BPortal ( portal) => portal,
68+ _ => {
69+ let ( self_ref, self_) = self . attach ( parent_scope, parent, next_sibling) ;
70+ bundle. replace ( parent, self_. into ( ) ) ;
71+ return self_ref;
7572 }
76- let inner_ancestor = node. borrow_mut ( ) ;
77- self . node
78- . reconcile ( parent_scope, parent, next_sibling. clone ( ) , inner_ancestor) ;
79- return next_sibling;
80- }
73+ } ;
74+ let Self {
75+ host,
76+ inner_sibling,
77+ node,
78+ } = self ;
79+
80+ let old_host = std:: mem:: replace ( & mut portal. host , host) ;
81+ let old_inner_sibling = std:: mem:: replace ( & mut portal. inner_sibling , inner_sibling) ;
8182
82- let ( _, self_) = self . attach ( parent_scope, parent, next_sibling. clone ( ) ) ;
83- ancestor. replace ( parent, self_. into ( ) ) ;
83+ if old_host != portal. host || old_inner_sibling != portal. inner_sibling {
84+ // Remount the inner node somewhere else instead of diffing
85+ // Move the node, but keep the state
86+ portal
87+ . node
88+ . shift ( & portal. host , portal. inner_sibling . clone ( ) ) ;
89+ }
90+ node. reconcile ( parent_scope, parent, next_sibling. clone ( ) , & mut portal. node ) ;
8491 next_sibling
8592 }
8693}
0 commit comments