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(core): check global ngDevMode is defined before checking value #32079

Closed

Conversation

filipesilva
Copy link
Contributor

@filipesilva filipesilva commented Aug 9, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Fix #31595

What is the new behavior?

ngDevMode is defined without being a toplevel side effect.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@filipesilva filipesilva added the target: major This PR is targeted for the next major release label Aug 9, 2019
@filipesilva filipesilva requested review from a team as code owners August 9, 2019 15:05
@filipesilva
Copy link
Contributor Author

Note for reviewers: the main changes are in packages/core/src/util/ng_dev_mode.ts.

@filipesilva filipesilva added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Aug 9, 2019
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.

LGTM for ngcc

// TODO(misko): uncomment the next line once `ngDevMode` works with closure.
// if(ngDevMode) debugger;
// TODO(misko): uncomment the next line once `getNgDevMode()` works with closure.
// if(getNgDevMode()) debugger;
Copy link
Member

Choose a reason for hiding this comment

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

Will getNgDevMode() work with closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea. It seemed to not work with ngDevMode either.

Copy link
Contributor

Choose a reason for hiding this comment

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

it should.

@@ -18,8 +18,8 @@ export const EMPTY_OBJ: {} = {};
export const EMPTY_ARRAY: any[] = [];

// freezing the values prevents any code from accidentally inserting new values in
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
// These property accesses can be ignored because ngDevMode will be set to false
if (typeof getNgDevMode() !== 'undefined' && getNgDevMode()) {
Copy link
Member

Choose a reason for hiding this comment

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

Is the typeof getNgDevMode() !== 'undefined' needed still?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think not. Nice catch!

@mary-poppins
Copy link

You can preview 35534b5 at https://pr32079-35534b5.ngbuilds.io/.

@filipesilva filipesilva force-pushed the ngdevmode-side-effects branch 2 times, most recently from 1d9bb3f to a15e75a Compare August 9, 2019 15:19
@mary-poppins
Copy link

You can preview a15e75a at https://pr32079-a15e75a.ngbuilds.io/.

@filipesilva
Copy link
Contributor Author

filipesilva commented Aug 9, 2019

Blocked on rollup/rollup#3044, this syntax change is causing the side effect test and golden symbol tests to erroneously retain code.

@mary-poppins
Copy link

You can preview 8f4ef0d at https://pr32079-8f4ef0d.ngbuilds.io/.

@@ -479,7 +479,7 @@ runInEachFileSystem(() => {
}

function compileNgModuleFactory__POST_R3__(injector, options, moduleType) {
ngDevMode && assertNgModuleType(moduleType);
getNgDevMode() && assertNgModuleType(moduleType);
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for the nit pick, but I would prefer isNgDevMode()

// TODO(misko): uncomment the next line once `ngDevMode` works with closure.
// if(ngDevMode) debugger;
// TODO(misko): uncomment the next line once `getNgDevMode()` works with closure.
// if(getNgDevMode()) debugger;
Copy link
Contributor

Choose a reason for hiding this comment

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

it should.

import {OnDestroy} from '../interface/lifecycle_hooks';
import {Type} from '../interface/type';
import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors';
import {deepForEach} from '../util/array_utils';
import {getNgDevMode} from '../util/ng_dev_mode';
Copy link
Contributor

Choose a reason for hiding this comment

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

love the explicit import!

* as much early warning and errors as possible.
*
* NOTE: changes to the `ngDevMode` name must be synced with `compiler-cli/src/tooling.ts`.
*/
if (typeof ngDevMode === 'undefined' || ngDevMode) {
ngDevModeResetPerfCounters();
export function getNgDevMode() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the getNgDevMode instead of being a function would be a constant such as:

export const isNgDevMode = (typeof ngDevMode === 'undefined' || ngDevMode) && ngDevModeResetPerfCounters();

This way it should still be:

  1. explicit import
  2. should be tree shakable
  3. does not need function in-lining, so it should have better warmup characteristics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would work, and be a nicer approach overall.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this would work. Imagine a case where ngDevMode is imported across chunks. In such a case the optimizer would not be able to tree shake this statements.

@mary-poppins
Copy link

You can preview 4a450a5 at https://pr32079-4a450a5.ngbuilds.io/.

* found in the LICENSE file at https://angular.io/license
*/

export interface NgDevModePerfCounters {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the interface to avoid a circular dependency (ng_dev_mode.ts -> captured_globals.ts -> ng_dev_mode.ts).

@@ -0,0 +1,26 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file should also capture ngI18nClosureMode and localize in the future, providing similar usage patterns as ngDevMode in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed.

@mary-poppins
Copy link

You can preview 1d42191 at https://pr32079-1d42191.ngbuilds.io/.

@filipesilva filipesilva force-pushed the ngdevmode-side-effects branch 2 times, most recently from 8093353 to 0c2d747 Compare August 12, 2019 19:53
@mary-poppins
Copy link

You can preview 8093353 at https://pr32079-8093353.ngbuilds.io/.

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@AndrewKushnir
Copy link
Contributor

One more presubmit, to make sure g3 checks are "green":

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@mary-poppins
Copy link

You can preview 3597281 at https://pr32079-3597281.ngbuilds.io/.

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@AndrewKushnir
Copy link
Contributor

FYI, most recent VE and Ivy presubmits are successful.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@kara kara added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Sep 11, 2019
@kara
Copy link
Contributor

kara commented Sep 11, 2019

merge-assistance: global approval

@matsko
Copy link
Contributor

matsko commented Sep 12, 2019

@filipesilva this fails on patch.

@matsko matsko added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release labels Sep 12, 2019
@matsko matsko closed this in 5f095a5 Sep 12, 2019
@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 Oct 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReferenceError: ngDevMode is not defined
10 participants