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
Conversation
Note for reviewers: the main changes are in |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should.
packages/core/src/util/empty.ts
Outdated
@@ -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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
You can preview 35534b5 at https://pr32079-35534b5.ngbuilds.io/. |
1d9bb3f
to
a15e75a
Compare
You can preview a15e75a at https://pr32079-a15e75a.ngbuilds.io/. |
Blocked on rollup/rollup#3044, this syntax change is causing the side effect test and golden symbol tests to erroneously retain code. |
a15e75a
to
8f4ef0d
Compare
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should.
packages/core/src/di/r3_injector.ts
Outdated
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'; |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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:
- explicit import
- should be tree shakable
- does not need function in-lining, so it should have better warmup characteristics.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8f4ef0d
to
4a450a5
Compare
You can preview 4a450a5 at https://pr32079-4a450a5.ngbuilds.io/. |
4a450a5
to
1d42191
Compare
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export interface NgDevModePerfCounters { |
There was a problem hiding this comment.
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 @@ | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed.
You can preview 1d42191 at https://pr32079-1d42191.ngbuilds.io/. |
8093353
to
0c2d747
Compare
You can preview 8093353 at https://pr32079-8093353.ngbuilds.io/. |
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. |
One more presubmit, to make sure g3 checks are "green": |
d4fedc2
to
3597281
Compare
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 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 ℹ️ Googlers: Go here for more info. |
You can preview 3597281 at https://pr32079-3597281.ngbuilds.io/. |
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. |
FYI, most recent VE and Ivy presubmits are successful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
merge-assistance: global approval |
@filipesilva this fails on |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
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?
Other information