@@ -61,7 +61,7 @@ export class FakeNavigation implements Navigation {
6161 * A prospective current active entry index, which includes unresolved
6262 * traversals. Used by `go` to determine where navigations are intended to go.
6363 */
64- private prospectiveEntryIndex = 0 ;
64+ private propsectiveTraversalDestinations : number [ ] = [ ] ;
6565
6666 /**
6767 * A test-only option to make traversals synchronous, rather than emulate
@@ -300,7 +300,7 @@ export class FakeNavigation implements Navigation {
300300 index : entry . index ,
301301 sameDocument : entry . sameDocument ,
302302 } ) ;
303- this . prospectiveEntryIndex = entry . index ;
303+ this . propsectiveTraversalDestinations . push ( entry . index ) ;
304304 const result = new InternalNavigationResult ( this ) ;
305305 this . traversalQueue . set ( entry . key , result ) ;
306306 this . runTraversal ( ( ) => {
@@ -366,11 +366,13 @@ export class FakeNavigation implements Navigation {
366366 * `back(); forward()` chains it collapses certain traversals.
367367 */
368368 go ( direction : number ) : void {
369- const targetIndex = this . prospectiveEntryIndex + direction ;
369+ const targetIndex =
370+ ( this . propsectiveTraversalDestinations [ this . propsectiveTraversalDestinations . length - 1 ] ??
371+ this . currentEntryIndex ) + direction ;
370372 if ( targetIndex >= this . entriesArr . length || targetIndex < 0 ) {
371373 return ;
372374 }
373- this . prospectiveEntryIndex = targetIndex ;
375+ this . propsectiveTraversalDestinations . push ( targetIndex ) ;
374376 this . runTraversal ( ( ) => {
375377 // Check again that destination is in the entries array.
376378 if ( targetIndex >= this . entriesArr . length || targetIndex < 0 ) {
@@ -407,6 +409,7 @@ export class FakeNavigation implements Navigation {
407409 private runTraversal ( traversal : ( ) => void ) {
408410 if ( this . synchronousTraversals ) {
409411 traversal ( ) ;
412+ this . propsectiveTraversalDestinations . shift ( ) ;
410413 return ;
411414 }
412415
@@ -418,6 +421,7 @@ export class FakeNavigation implements Navigation {
418421 setTimeout ( ( ) => {
419422 resolve ( ) ;
420423 traversal ( ) ;
424+ this . propsectiveTraversalDestinations . shift ( ) ;
421425 } ) ;
422426 } ) ;
423427 } ) ;
@@ -558,7 +562,7 @@ export class FakeNavigation implements Navigation {
558562 }
559563 } else if ( navigationType === 'push' ) {
560564 this . currentEntryIndex ++ ;
561- this . prospectiveEntryIndex = this . currentEntryIndex ; // prospectiveEntryIndex isn't in the spec but is an implementation detail
565+ this . propsectiveTraversalDestinations = [ ] ; // prospectiveEntryIndex isn't in the spec but is an implementation detail
562566 disposedNHEs . push ( ...this . entriesArr . splice ( this . currentEntryIndex ) ) ;
563567 } else if ( navigationType === 'replace' ) {
564568 disposedNHEs . push ( oldCurrentNHE ) ;
0 commit comments