Skip to content

Commit

Permalink
refactor(forms): wrap _checkParentType with ngDevMode (#59489)
Browse files Browse the repository at this point in the history
The `_checkParentType` bodies are wrapped with `ngDevMode`, meaning they act as no-ops in production. We can wrap the actual calls to `_checkParentType` with `ngDevMode` to prevent calling no-op functions in production

PR Close #59489
  • Loading branch information
arturovt authored and pkozlowski-opensource committed Jan 24, 2025
1 parent 819795b commit e483831
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/forms/src/directives/ng_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class NgModel extends NgControl implements OnChanges, OnDestroy {
}

private _checkForErrors(): void {
if (!this._isStandalone()) {
if ((typeof ngDevMode === 'undefined' || ngDevMode) && !this._isStandalone()) {
this._checkParentType();
}
this._checkName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
}

private _setUpControl() {
this._checkParentType();
if (typeof ngDevMode === 'undefined' || ngDevMode) {
this._checkParentType();
}
(this as Writable<this>).control = this.formDirective.addControl(this);
this._added = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
* @nodoc
*/
ngOnInit(): void {
this._checkParentType();
if (typeof ngDevMode === 'undefined' || ngDevMode) {
this._checkParentType();
}
this.formDirective!.addFormArray(this);
}

Expand Down

0 comments on commit e483831

Please sign in to comment.