99// 3p-only-start
1010import {
1111 NavigationNavigateOptions ,
12- NavigationTypeString ,
12+ NavigationType ,
1313 NavigationOptions ,
1414 NavigateEvent ,
1515 NavigationCurrentEntryChangeEvent ,
@@ -80,6 +80,8 @@ export class FakeNavigation implements Navigation {
8080 */
8181 eventTarget : EventTarget ;
8282
83+ readonly activation : NavigationActivation | null = null ;
84+
8385 /** The next unique id for created entries. Replace recreates this id. */
8486 private nextId = 0 ;
8587
@@ -179,7 +181,7 @@ export class FakeNavigation implements Navigation {
179181 const fromUrl = new URL ( this . currentEntry . url ! ) ;
180182 const toUrl = new URL ( url , this . currentEntry . url ! ) ;
181183
182- let navigationType : NavigationTypeString ;
184+ let navigationType : NavigationType ;
183185 if ( ! options ?. history || options . history === 'auto' ) {
184186 // Auto defaults to push, but if the URLs are the same, is a replace.
185187 if ( fromUrl . toString ( ) === toUrl . toString ( ) ) {
@@ -231,7 +233,7 @@ export class FakeNavigation implements Navigation {
231233 }
232234
233235 private pushOrReplaceState (
234- navigationType : NavigationTypeString ,
236+ navigationType : NavigationType ,
235237 data : unknown ,
236238 _title : string ,
237239 url ?: string ,
@@ -617,13 +619,15 @@ export class FakeNavigation implements Navigation {
617619 }
618620
619621 set oncurrententrychange (
620- _handler : // tslint:disable-next-line:no-any
622+ _handler :
623+ // tslint:disable-next-line:no-any
621624 ( ( this : Navigation , ev : NavigationCurrentEntryChangeEvent ) => any ) | null ,
622625 ) {
623626 throw new Error ( 'unimplemented' ) ;
624627 }
625628
626- get oncurrententrychange ( ) : // tslint:disable-next-line:no-any
629+ get oncurrententrychange ( ) :
630+ // tslint:disable-next-line:no-any
627631 ( ( this : Navigation , ev : NavigationCurrentEntryChangeEvent ) => any ) | null {
628632 throw new Error ( 'unimplemented' ) ;
629633 }
@@ -816,7 +820,7 @@ function dispatchNavigateEvent({
816820 canIntercept : boolean ;
817821 userInitiated : boolean ;
818822 hashChange : boolean ;
819- navigationType : NavigationTypeString ;
823+ navigationType : NavigationType ;
820824 destination : FakeNavigationDestination ;
821825 info : unknown ;
822826 sameDocument : boolean ;
@@ -846,7 +850,7 @@ function dispatchNavigateEvent({
846850 event . sameDocument = sameDocument ;
847851
848852 let precommitHandlers : Array < ( controller : NavigationPrecommitController ) => Promise < void > > = [ ] ;
849- let handlers : Array < ( ) => Promise < void > > = [ ] ;
853+ let handlers : Array < ( ) => PromiseLike < void > | void > = [ ] ;
850854
851855 // https://whatpr.org/html/10919/nav-history-apis.html#dom-navigateevent-intercept
852856 event . intercept = function (
@@ -962,7 +966,14 @@ function dispatchNavigateEvent({
962966 }
963967 }
964968 ( navigation . transition as InternalNavigationTransition ) ?. committedResolve ( ) ;
965- const promisesList : Array < Promise < unknown > > = handlers . map ( ( handler ) => handler ( ) ) ;
969+ const promisesList : Array < PromiseLike < unknown > > = [ ] ;
970+ for ( const handler of handlers ) {
971+ const handlerResult = handler ( ) ;
972+
973+ if ( handlerResult ) {
974+ promisesList . push ( handlerResult ) ;
975+ }
976+ }
966977 promisesList . push ( result . committed ) ;
967978 Promise . all ( promisesList )
968979 . then ( ( ) => {
@@ -1134,7 +1145,7 @@ function createFakeNavigationCurrentEntryChangeEvent({
11341145 navigationType,
11351146} : {
11361147 from : FakeNavigationHistoryEntry ;
1137- navigationType : NavigationTypeString ;
1148+ navigationType : NavigationType ;
11381149} ) {
11391150 const event = new Event ( 'currententrychange' , {
11401151 bubbles : false ,
@@ -1176,8 +1187,8 @@ function createHashChangeEvent(newURL: string, oldURL: string) {
11761187export class FakeNavigationDestination implements NavigationDestination {
11771188 url : string ;
11781189 readonly sameDocument : boolean ;
1179- readonly key : string | null ;
1180- readonly id : string | null ;
1190+ readonly key : string ;
1191+ readonly id : string ;
11811192 readonly index : number ;
11821193
11831194 state ?: unknown ;
@@ -1204,8 +1215,8 @@ export class FakeNavigationDestination implements NavigationDestination {
12041215 this . sameDocument = sameDocument ;
12051216 this . state = state ;
12061217 this . historyState = historyState ;
1207- this . key = key ;
1208- this . id = id ;
1218+ this . key = key ?? '' ;
1219+ this . id = id ?? '' ;
12091220 this . index = index ;
12101221 }
12111222
@@ -1238,7 +1249,7 @@ class InternalNavigationTransition implements NavigationTransition {
12381249 constructor (
12391250 readonly from : NavigationHistoryEntry ,
12401251 readonly to : NavigationDestination ,
1241- readonly navigationType : NavigationTypeString ,
1252+ readonly navigationType : NavigationType ,
12421253 ) {
12431254 this . finished = new Promise < void > ( ( resolve , reject ) => {
12441255 this . finishedReject = reject ;
@@ -1303,7 +1314,7 @@ class InternalNavigationResult {
13031314
13041315/** Internal options for performing a navigate. */
13051316interface InternalNavigateOptions {
1306- navigationType : NavigationTypeString ;
1317+ navigationType : NavigationType ;
13071318 cancelable : boolean ;
13081319 canIntercept : boolean ;
13091320 userInitiated : boolean ;
0 commit comments