@@ -96,7 +96,10 @@ function createMorphContext(options = {}) {
9696 // So we're using `shouldSkipChildren()` instead which doesn't have this problem as it allows us to pass in the `skipChildren()`
9797 // function as an earlier parameter and then append it to the `updating` hook signature manually. The signature of `updating`
9898 // hook is now `updating: (el, toEl, childrenOnly, skip, skipChildren)`.
99- if ( shouldSkipChildren ( context . updating , ( ) => skipChildren = true , from , to , ( ) => updateChildrenOnly = true ) ) return
99+
100+ let skipUntil = predicate => context . skipUntilCondition = predicate
101+
102+ if ( shouldSkipChildren ( context . updating , ( ) => skipChildren = true , skipUntil , from , to , ( ) => updateChildrenOnly = true ) ) return
100103
101104 // Initialize the server-side HTML element with Alpine...
102105 if ( from . nodeType === 1 && window . Alpine ) {
@@ -201,6 +204,18 @@ function createMorphContext(options = {}) {
201204 let toKey = context . getKey ( currentTo )
202205 let fromKey = context . getKey ( currentFrom )
203206
207+ if ( context . skipUntilCondition ) {
208+ let fromDone = ! currentFrom || context . skipUntilCondition ( currentFrom )
209+ let toDone = ! currentTo || context . skipUntilCondition ( currentTo )
210+ if ( fromDone && toDone ) {
211+ context . skipUntilCondition = null
212+ } else {
213+ if ( ! fromDone ) currentFrom = currentFrom && getNextSibling ( from , currentFrom )
214+ if ( ! toDone ) currentTo = currentTo && getNextSibling ( to , currentTo )
215+ continue
216+ }
217+ }
218+
204219 // Add new elements...
205220 if ( ! currentFrom ) {
206221 if ( toKey && fromKeyHoldovers [ toKey ] ) {
@@ -431,11 +446,9 @@ function shouldSkip(hook, ...args) {
431446// are using this function instead which doesn't have this problem as we can pass the
432447// `skipChildren` function in as an earlier argument and then append it to the end
433448// of the hook signature manually.
434- function shouldSkipChildren ( hook , skipChildren , ...args ) {
449+ function shouldSkipChildren ( hook , skipChildren , skipUntil , ...args ) {
435450 let skip = false
436-
437- hook ( ...args , ( ) => skip = true , skipChildren )
438-
451+ hook ( ...args , ( ) => skip = true , skipChildren , skipUntil )
439452 return skip
440453}
441454
0 commit comments