@@ -424,29 +424,27 @@ function onPjaxPopstate(event) {
424424
425425 var previousState = pjax . state
426426 var state = event . state
427+ var direction
427428
428429 if ( state && state . container ) {
429430 // When coming forward from a separate history session, will get an
430431 // initial pop with a state we are already at. Skip reloading the current
431432 // page.
432433 if ( initialPop && initialURL == state . url ) return
433434
434- var direction , containerSelector = state . container
435-
436435 if ( previousState ) {
437436 // If popping back to the same state, just skip.
438437 // Could be clicking back from hashchange rather than a pushState.
439438 if ( previousState . id === state . id ) return
440439
441440 // Since state IDs always increase, we can deduce the navigation direction
442441 direction = previousState . id < state . id ? 'forward' : 'back'
443- if ( direction == 'back' ) containerSelector = previousState . container
444442 }
445443
446- var container = $ ( containerSelector )
447- if ( container . length ) {
448- var contents = cacheMapping [ state . id ]
444+ var cache = cacheMapping [ state . id ] || [ ]
445+ var container = $ ( cache [ 0 ] || state . container ) , contents = cache [ 1 ]
449446
447+ if ( container . length ) {
450448 if ( previousState ) {
451449 // Cache current container before replacement and inform the
452450 // cache which direction the history shifted.
@@ -564,7 +562,7 @@ function cloneContents(container) {
564562 cloned . find ( 'script' ) . each ( function ( ) {
565563 if ( ! this . src ) jQuery . _data ( this , 'globalEval' , false )
566564 } )
567- return cloned . contents ( )
565+ return [ container . selector , cloned . contents ( ) ]
568566}
569567
570568// Internal: Strips named query param from url
0 commit comments