Skip to content
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

fix(upgrade): throw clear error when calling downgradeModule() twice #26084

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Sep 24, 2018

PR Checklist

PR Type

[x] Bugfix

What is the current behavior?

Calling downgradeModule() more than once is not supported (and will not work correctly), but it fails silently. An error will only be thrown if a downgraded component from any but the last downgraded module needs to be instantiated. Even then, the error message is unclear and not actionable.

Issue Number: #26062

What is the new behavior?

Calling downgradeModule() more than once will throw a clear, actionable error message as soon as the AngularJS app is bootstrapped.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Fixes #26062.
This is an alternative to #26217.

@gkalpak gkalpak force-pushed the fix-ngUpgradeLite-multi-downgradeModule branch from 41d71a5 to 3286050 Compare September 24, 2018 15:24
@gkalpak gkalpak added action: review The PR is still awaiting reviews from at least one requested reviewer comp: upgrade/static target: patch This PR is targeted for the next patch release type: bug/fix labels Sep 24, 2018
@mary-poppins
Copy link

You can preview 3286050 at https://pr26084-3286050.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-ngUpgradeLite-multi-downgradeModule branch from 3286050 to c139092 Compare September 24, 2018 16:17
@mary-poppins
Copy link

You can preview c139092 at https://pr26084-c139092.ngbuilds.io/.

@gkalpak gkalpak force-pushed the fix-ngUpgradeLite-multi-downgradeModule branch from c139092 to eb4249f Compare September 24, 2018 19:06
@mary-poppins
Copy link

You can preview eb4249f at https://pr26084-eb4249f.ngbuilds.io/.

@@ -26,6 +32,9 @@ export interface IModule {
factory(key: Ng1Token, factoryFn: IInjectable): IModule;
value(key: Ng1Token, value: any): IModule;
constant(token: Ng1Token, value: any): IModule;
provider(key: Ng1Token, provider: IServiceProvider): IModule;
provider(key: Ng1Token, provider: IServiceProviderFactory): IModule;
provider(key: Ng1Token, provider: (Ng1Token|IServiceProviderFactory)[]): IModule;
Copy link
Member

@petebacondarwin petebacondarwin Oct 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC - why use 3 overloads rather than a union parameter type:

provider(key: Ng1Token, provider: IServiceProvider|IServiceProviderFactory|(Ng1Token|IServiceProviderFactory)[]): IModule;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question 🤔
For some reason, I didn't think about using a union type. But overloads are more readable 😁

*
* You can only call `downgradeModule()` once per AngularJS application.<br />
* If you want to downgrade multiple modules, create and downgrade a new Angular module that
* imports all the rest.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports => exports ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it has to export them. Importing them should be enough (since nobody will be importing that "super module".

@@ -104,7 +114,7 @@ import {NgAdapterInjector} from './util';
export function downgradeModule<T>(
moduleFactoryOrBootstrapFn: NgModuleFactory<T>|
((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>)): string {
const LAZY_MODULE_NAME = UPGRADE_MODULE_NAME + '.lazy';
const LAZY_MODULE_NAME = UPGRADE_MODULE_NAME + '.lazy' + (++moduleUid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The modules must have different names for all their providers to be available. If they have the same name, the one overwrites the other and it is as if the original one never existed (and this check will alwasy be false).

@@ -25,6 +25,65 @@ withEachNg1Version(() => {

beforeEach(() => destroyPlatform());

it('should throw if called for more than one Angular modules', async(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: modules => module

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments.

Calling `downgradeModule()` more than once is not supported (and will
not work correctly), but it fails silently. An error will only be thrown
if a downgraded component from any but the last downgraded module needs
to be instantiated. Even then, the error message is unclear and not
actionable.

This commit fixes it by throwing a clear, actionable error message as
soon as the AngularJS app is bootstrapped.

Fixes angular#26062
@gkalpak gkalpak force-pushed the fix-ngUpgradeLite-multi-downgradeModule branch from eb4249f to f2f8336 Compare October 3, 2018 11:04
@mary-poppins
Copy link

You can preview f2f8336 at https://pr26084-f2f8336.ngbuilds.io/.

@gkalpak
Copy link
Member Author

gkalpak commented Nov 6, 2018

Merged #26217 instead.

@gkalpak gkalpak closed this Nov 6, 2018
@gkalpak gkalpak deleted the fix-ngUpgradeLite-multi-downgradeModule branch November 6, 2018 08:44
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NgUpgrade for Performance's downgradeModule can only be called once
4 participants