@@ -365,7 +365,7 @@ F.prototype.runHandlers = function (handlers, messageMapper, event) {
365365} ;
366366
367367F . prototype . resume = function ( updatedHtml ) {
368- this . cachedHtml = this . updateAllNodes ( this . root , this . cachedHtml , updatedHtml ) ; ;
368+ this . cachedHtml = this . updateAllNodes ( this . root , this . cachedHtml , updatedHtml ) ;
369369} ;
370370
371371/** Patches over the parent element*/
@@ -375,9 +375,14 @@ F.prototype.updateAllNodes = function (parent, currentHtml, updatedHtml) {
375375 updatedHtml = shallowCopy ( updatedHtml ) ;
376376 //recreate node if it has changed tag or node type
377377 if ( currentHtml . tag !== updatedHtml . tag || currentHtml . nodeType !== updatedHtml . nodeType ) {
378- //moving the node instead of using clearNode allows us to reuse nodes
379- this . createAllNodes ( parent , updatedHtml , currentHtml . node ) ;
380- parent . removeChild ( currentHtml . node ) ;
378+ if ( currentHtml . nodeType === fragmentNode ) {
379+ this . createAllNodes ( parent , updatedHtml , firstFragmentChildNode ( currentHtml . children ) ) ;
380+ removeFragmentChildren ( parent , currentHtml . children ) ;
381+ } else {
382+ //moving the node instead of using clearNode allows us to reuse nodes
383+ this . createAllNodes ( parent , updatedHtml , currentHtml . node ) ;
384+ parent . removeChild ( currentHtml . node ) ;
385+ }
381386 }
382387 else {
383388 updatedHtml . node = currentHtml . node ;
@@ -434,6 +439,31 @@ F.prototype.updateAllNodes = function (parent, currentHtml, updatedHtml) {
434439 return updatedHtml ;
435440} ;
436441
442+ /** Fragments are not child of any nodes, so we must find the first actual node */
443+ function firstFragmentChildNode ( children ) {
444+ let childrenLength = children . length ;
445+
446+ for ( let i = 0 ; i < childrenLength ; ++ i ) {
447+ if ( children [ i ] . nodeType === fragmentNode )
448+ return firstFragmentChildNode ( children [ i ] . children ) ;
449+
450+ return children [ i ] . node ;
451+ }
452+
453+ return undefined ;
454+ }
455+
456+ /** fragments are not child of any nodes, so we must recursively remove the actual child nodes */
457+ function removeFragmentChildren ( parent , children ) {
458+ let childrenLength = children . length ;
459+
460+ for ( let i = 0 ; i < childrenLength ; ++ i )
461+ if ( children [ i ] . nodeType === fragmentNode )
462+ removeFragmentChildren ( children [ i ] . children )
463+ else
464+ parent . removeChild ( children [ i ] . node ) ;
465+ }
466+
437467function clearNode ( node ) {
438468 node . textContent = '' ;
439469}
0 commit comments