Skip to content

Commit

Permalink
fixup! fix(upgrade): fix HMR for hybrid applications
Browse files Browse the repository at this point in the history
  • Loading branch information
gkalpak committed Dec 10, 2020
1 parent 43e994d commit 885710a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
12 changes: 9 additions & 3 deletions packages/upgrade/src/common/src/util.ts
Expand Up @@ -48,9 +48,15 @@ export function controllerKey(name: string): string {
return '$' + name + 'Controller';
}

// Destroy an AngularJS app given the app `$injector`.
//
// NOTE: Destroying an app is not officially supported by AngularJS, but we do our best.
/**
* Destroy an AngularJS app given the app `$injector`.
*
* NOTE: Destroying an app is not officially supported by AngularJS, but try to do our best by
* destroying `$rootScope` and clean the jqLite/jQuery data on `$rootElement` and all
* descendants.
*
* @param $injector The `$injector` of the AngularJS app to destroy.
*/
export function destroyApp($injector: IInjectorService): void {
const $rootElement: IAugmentedJQuery = $injector.get($ROOT_ELEMENT);
const $rootScope: IRootScopeService = $injector.get($ROOT_SCOPE);
Expand Down
5 changes: 3 additions & 2 deletions packages/upgrade/src/dynamic/src/upgrade_adapter.ts
Expand Up @@ -622,8 +622,9 @@ export class UpgradeAdapter {

// Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
// This does not happen in a typical SPA scenario, but it might be useful for
// other usecases where desposing of an Angular/AngularJS app is necessary (such
// as Hot Module Replacement (HMR)).
// other use-cases where disposing of an Angular/AngularJS app is necessary
// (such as Hot Module Replacement (HMR)).
// See https://github.com/angular/angular/issues/39935.
platformRef.onDestroy(() => destroyApp(ng1Injector));
});
})
Expand Down
5 changes: 3 additions & 2 deletions packages/upgrade/static/src/downgrade_module.ts
Expand Up @@ -169,8 +169,9 @@ export function downgradeModule<T>(moduleFactoryOrBootstrapFn: NgModuleFactory<T

// Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
// This does not happen in a typical SPA scenario, but it might be useful for
// other usecases where desposing of an Angular/AngularJS app is necessary (such
// as Hot Module Replacement (HMR)).
// other use-cases where disposing of an Angular/AngularJS app is necessary
// (such as Hot Module Replacement (HMR)).
// See https://github.com/angular/angular/issues/39935.
injector.get(PlatformRef).onDestroy(() => destroyApp($injector));

return injector;
Expand Down
5 changes: 3 additions & 2 deletions packages/upgrade/static/src/upgrade_module.ts
Expand Up @@ -259,8 +259,9 @@ export class UpgradeModule {

// Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
// This does not happen in a typical SPA scenario, but it might be useful for
// other usecases where desposing of an Angular/AngularJS app is necessary (such
// as Hot Module Replacement (HMR)).
// other use-cases where disposing of an Angular/AngularJS app is necessary
// (such as Hot Module Replacement (HMR)).
// See https://github.com/angular/angular/issues/39935.
this.platformRef.onDestroy(() => destroyApp($injector));

// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
Expand Down

0 comments on commit 885710a

Please sign in to comment.