@@ -393,22 +393,26 @@ export default class LiveSocket {
393393 }
394394
395395 replaceMain ( href , flash , callback = null , linkRef = this . setPendingLink ( href ) ) {
396- let liveReferer = this . currentLocation . href
396+ const liveReferer = this . currentLocation . href
397397 this . outgoingMainEl = this . outgoingMainEl || this . main . el
398- let removeEls = DOM . all ( this . outgoingMainEl , `[${ this . binding ( "remove" ) } ]` )
399- let newMainEl = DOM . cloneNode ( this . outgoingMainEl , "" )
398+
399+ const stickies = DOM . findPhxSticky ( document ) || [ ]
400+ const removeEls = DOM . all ( this . outgoingMainEl , `[${ this . binding ( "remove" ) } ]` )
401+ . filter ( el => ! DOM . isChildOfAny ( el , stickies ) )
402+
403+ const newMainEl = DOM . cloneNode ( this . outgoingMainEl , "" )
400404 this . main . showLoader ( this . loaderTimeout )
401405 this . main . destroy ( )
402406
403407 this . main = this . newRootView ( newMainEl , flash , liveReferer )
404408 this . main . setRedirect ( href )
405- this . transitionRemoves ( removeEls , true )
409+ this . transitionRemoves ( removeEls )
406410 this . main . join ( ( joinCount , onDone ) => {
407411 if ( joinCount === 1 && this . commitPendingLink ( linkRef ) ) {
408412 this . requestDOMUpdate ( ( ) => {
409413 // remove phx-remove els right before we replace the main element
410414 removeEls . forEach ( el => el . remove ( ) )
411- DOM . findPhxSticky ( document ) . forEach ( el => newMainEl . appendChild ( el ) )
415+ stickies . forEach ( el => newMainEl . appendChild ( el ) )
412416 this . outgoingMainEl . replaceWith ( newMainEl )
413417 this . outgoingMainEl = null
414418 callback && callback ( linkRef )
@@ -418,12 +422,8 @@ export default class LiveSocket {
418422 } )
419423 }
420424
421- transitionRemoves ( elements , skipSticky , callback ) {
425+ transitionRemoves ( elements , callback ) {
422426 let removeAttr = this . binding ( "remove" )
423- if ( skipSticky ) {
424- const stickies = DOM . findPhxSticky ( document ) || [ ]
425- elements = elements . filter ( el => ! DOM . isChildOfAny ( el , stickies ) )
426- }
427427 let silenceEvents = ( e ) => {
428428 e . preventDefault ( )
429429 e . stopImmediatePropagation ( )
@@ -800,7 +800,8 @@ export default class LiveSocket {
800800 }
801801
802802 historyRedirect ( e , href , linkState , flash , targetEl ) {
803- if ( targetEl && e . isTrusted && e . type !== "popstate" ) { targetEl . classList . add ( "phx-click-loading" ) }
803+ const clickLoading = targetEl && e . isTrusted && e . type !== "popstate"
804+ if ( clickLoading ) { targetEl . classList . add ( "phx-click-loading" ) }
804805 if ( ! this . isConnected ( ) || ! this . main . isMain ( ) ) { return Browser . redirect ( href , flash ) }
805806
806807 // convert to full href if only path prefix
@@ -829,6 +830,9 @@ export default class LiveSocket {
829830 DOM . dispatchEvent ( window , "phx:navigate" , { detail : { href, patch : false , pop : false , direction : "forward" } } )
830831 this . registerNewLocation ( window . location )
831832 }
833+ // explicitly undo click-loading class
834+ // (in case it originated in a sticky live view, otherwise it would be removed anyway)
835+ if ( clickLoading ) { targetEl . classList . remove ( "phx-click-loading" ) }
832836 done ( )
833837 } )
834838 } )
0 commit comments