8000 fix(upgrade): fix HMR for hybrid applications by gkalpak · Pull Request #40045 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(upgrade): fix HMR for hybrid applications #40045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! fix(upgrade): fix HMR for hybrid applications
  • Loading branch information
gkalpak committed Dec 10, 2020
commit 885710a3082e3469f09bdf2ab9bc90983750f06c
12 changes: 9 additions & 3 deletions packages/upgrade/src/common/src/util.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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