@@ -16,16 +16,21 @@ import {
1616import { Observable , Subject } from 'rxjs' ;
1717import { filter , map , take } from 'rxjs/operators' ;
1818import { AppHostView } from './app-host-view' ;
19- import { resetAngularHmrCompiledComponents } from './hmr-compiled-components-core' ;
19+ import {
20+ getAngularCoreForHmrReset ,
21+ rememberAngularCoreForHmr ,
22+ resetAngularHmrCompiledComponents ,
23+ } from './hmr-compiled-components-core' ;
2024import { NativeScriptLoadingService } from './loading.service' ;
2125import { clearAngularHmrRouteConfigCaches } from './legacy/router/hmr-route-cache-core' ;
26+ import { createAngularRootTransitionGuard } from './root-transition-guard' ;
2227import { APP_ROOT_VIEW , DISABLE_ROOT_VIEW_HANDLING , NATIVESCRIPT_ROOT_MODULE_ID } from './tokens' ;
2328import { NativeScriptDebug } from './trace' ;
2429
2530// Store the original @angular /core module for HMR
2631// This is crucial because HMR imports a fresh @angular /core with empty LView tracking
2732// We need to use the original one that has the registered LViews
28- ( globalThis as any ) . __NS_ANGULAR_CORE__ = AngularCore ;
33+ rememberAngularCoreForHmr ( AngularCore as any , globalThis as any ) ;
2934
3035export interface AppLaunchView extends LayoutBase {
3136 // called when the animation is to begin
@@ -255,6 +260,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
255260 } ;
256261 let launchEventDone = true ;
257262 let targetRootView : View = null ;
263+ const rootTransitionGuard = createAngularRootTransitionGuard ( globalThis as any ) ;
258264 const refreshRootViewCss = ( expectedRoot ?: View ) => {
259265 setTimeout ( ( ) => {
260266 const currentRoot = Application . getRootView ( ) ;
@@ -296,7 +302,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
296302 if ( options . embedded ) {
297303 Application . run ( { create : ( ) => ref } ) ;
298304 } else if ( launchEventDone ) {
299- Application . resetRootView ( { create : ( ) => ref } ) ;
305+ rootTransitionGuard . runApplicationResetRootView ( Application , ( ) => ref , ref ?. constructor ?. name || 'View' ) ;
300306 refreshRootViewCss ( ref ) ;
301307 } else {
302308 targetRootView = ref ;
@@ -326,7 +332,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
326332 parent : newRoot ?. parent ?. constructor ?. name ,
327333 childCount : ( newRoot as any ) ?. getChildrenCount ?.( ) ?? 'N/A' ,
328334 } ) ;
329- Application . resetRootView ( { create : ( ) => newRoot } ) ;
335+ rootTransitionGuard . runApplicationResetRootView ( Application , ( ) => newRoot , newRoot ?. constructor ?. name || 'View' ) ;
330336 refreshRootViewCss ( newRoot ) ;
331337 console . log ( '[ng-hmr] setRootView: Application.resetRootView returned' ) ;
332338 // Check root view after reset
@@ -353,6 +359,10 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
353359 const bootstrapRoot = ( reason : NgModuleReason ) => {
354360 console . log ( '[ng-hmr] bootstrapRoot called, reason:' , reason ) ;
355361 try {
362+ if ( reason === 'hotreload' ) {
363+ resetAngularHmrCompiledComponents ( getAngularCoreForHmrReset ( AngularCore as any , globalThis as any ) ) ;
364+ }
365+
356366 bootstrapId = Date . now ( ) ;
357367 console . log ( '[ng-hmr] bootstrapRoot: new bootstrapId:' , bootstrapId ) ;
358368 const currentBootstrapId = bootstrapId ;
@@ -579,10 +589,6 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
579589 loadingModuleRef = null ;
580590 destroyRef ( mainModuleRef , 'main' , reason ) ;
581591 mainModuleRef = null ;
582-
583- if ( reason === 'hotreload' ) {
584- resetAngularHmrCompiledComponents ( AngularCore as any ) ;
585- }
586592 } ;
587593 const launchCallback = profile ( '@nativescript/angular/platform-common.launchCallback' , ( args : LaunchEventData ) => {
588594 launchEventDone = false ;
0 commit comments