Skip to content

Commit

Permalink
fixup! perf(core): allow checkNoChanges mode to be tree-shaken in p…
Browse files Browse the repository at this point in the history
…roduction
  • Loading branch information
JoostK committed May 7, 2022
1 parent 83f75f3 commit ad3103a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/change_detection/change_detector_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export abstract class ChangeDetectorRef {
* Checks the change detector and its children, and throws if any changes are detected.
*
* Use in development mode to verify that running change detection doesn't introduce
* other changes.
* other changes. Calling it in production mode is a noop.
*/
abstract checkNoChanges(): void;

Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/render3/instructions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,22 @@ export function refreshView<T>(
export function renderComponentOrTemplate<T>(
tView: TView, lView: LView, templateFn: ComponentTemplate<{}>|null, context: T) {
const rendererFactory = lView[RENDERER_FACTORY];
const normalExecutionPath = !ngDevMode || !isInCheckNoChangesMode();

// Check no changes mode is a dev only mode used to verify that bindings have not changed
// since they were assigned. We do not want to invoke renderer factory functions in that mode
// to avoid any possible side-effects.
const checkNoChangesMode = !!ngDevMode && isInCheckNoChangesMode();
const creationModeIsActive = isCreationMode(lView);
try {
if (normalExecutionPath && !creationModeIsActive && rendererFactory.begin) {
if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.begin) {
rendererFactory.begin();
}
if (creationModeIsActive) {
renderView(tView, lView, context);
}
refreshView(tView, lView, templateFn, context);
} finally {
if (normalExecutionPath && !creationModeIsActive && rendererFactory.end) {
if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.end) {
rendererFactory.end();
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ const instructionState: InstructionState = {
*
* Necessary to support ChangeDetectorRef.checkNoChanges().
*
* checkNoChanges Runs only in devmode=true and verifies that no unintended changes exist in
* the change detector or its children.
* The `checkNoChanges` function is invoked only in ngDevMode=true and verifies that no unintended
* changes exist in the change detector or its children.
*/
let _isInCheckNoChangesMode = false;

Expand Down

0 comments on commit ad3103a

Please sign in to comment.