11import * as AngularCore from '@angular/core' ;
22import { ApplicationRef , EnvironmentProviders , NgModuleRef , NgZone , PlatformRef , Provider } from '@angular/core' ;
3+ import { Router } from '@angular/router' ;
34import {
45 Application ,
56 ApplicationEventData ,
@@ -15,7 +16,9 @@ import {
1516import { Observable , Subject } from 'rxjs' ;
1617import { filter , map , take } from 'rxjs/operators' ;
1718import { AppHostView } from './app-host-view' ;
19+ import { resetAngularHmrCompiledComponents } from './hmr-compiled-components-core' ;
1820import { NativeScriptLoadingService } from './loading.service' ;
21+ import { clearAngularHmrRouteConfigCaches } from './legacy/router/hmr-route-cache-core' ;
1922import { APP_ROOT_VIEW , DISABLE_ROOT_VIEW_HANDLING , NATIVESCRIPT_ROOT_MODULE_ID } from './tokens' ;
2023import { NativeScriptDebug } from './trace' ;
2124
@@ -230,6 +233,17 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
230233 let loadingModuleRef : NgModuleRef < K > | ApplicationRef ;
231234 let platformRef : PlatformRef = null ;
232235 let bootstrapId = - 1 ;
236+ const clearAngularHmrRouteCaches = ( ) => {
237+ try {
238+ const injector = ( mainModuleRef as any ) ?. injector ;
239+ const router = injector ?. get ?.( Router , null ) ;
240+ const cleared = clearAngularHmrRouteConfigCaches ( router ?. config ) ;
241+
242+ if ( cleared > 0 ) {
243+ console . log ( '[ng-hmr] cleared Angular route caches before reboot:' , cleared ) ;
244+ }
245+ } catch { }
246+ } ;
233247 const updatePlatformRef = ( moduleRef : NgModuleRef < T | K > | ApplicationRef , reason : NgModuleReason ) => {
234248 const newPlatformRef = moduleRef . injector . get ( PlatformRef ) ;
235249 if ( newPlatformRef === platformRef ) {
@@ -555,12 +569,20 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
555569 platformRef = null ;
556570 } ;
557571 const disposeLastModules = ( reason : NgModuleReason ) => {
572+ if ( reason === 'hotreload' ) {
573+ clearAngularHmrRouteCaches ( ) ;
574+ }
575+
558576 // reset bootstrap ID to make sure any modules bootstrapped after this are discarded
559577 bootstrapId = - 1 ;
560578 destroyRef ( loadingModuleRef , 'loading' , reason ) ;
561579 loadingModuleRef = null ;
562580 destroyRef ( mainModuleRef , 'main' , reason ) ;
563581 mainModuleRef = null ;
582+
583+ if ( reason === 'hotreload' ) {
584+ resetAngularHmrCompiledComponents ( AngularCore as any ) ;
585+ }
564586 } ;
565587 const launchCallback = profile ( '@nativescript/angular/platform-common.launchCallback' , ( args : LaunchEventData ) => {
566588 launchEventDone = false ;
@@ -615,6 +637,9 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
615637 global [ '__reboot_ng_modules__' ] = ( shouldDisposePlatform : boolean = false ) => {
616638 console . log ( '[ng-hmr] __reboot_ng_modules__ called, shouldDisposePlatform:' , shouldDisposePlatform ) ;
617639 console . log ( '[ng-hmr] current bootstrapId:' , bootstrapId , 'mainModuleRef:' , ! ! mainModuleRef ) ;
640+ try {
641+ global [ '__NS_CAPTURE_ANGULAR_HMR_ROUTE__' ] ?.( ) ;
642+ } catch { }
618643 disposeLastModules ( 'hotreload' ) ;
619644 console . log ( '[ng-hmr] after disposeLastModules, bootstrapId:' , bootstrapId ) ;
620645 if ( shouldDisposePlatform ) {
0 commit comments