Skip to content

Commit

Permalink
fix(module:code-editor): only emit update if value changed (#5933)
Browse files Browse the repository at this point in the history
Before notifying Angular (through the ControlValueAccessor mechanism) of a change to
the value we make sure that the value has actually changed. This is necessary to
avoid feedback loops as writeValue (model -> view) would otherwise cause this to be
fired (view -> model) which can cause infinite loop issues on the usage side or
broken validation detection.

fixes #5869
  • Loading branch information
Airblader committed Oct 16, 2020
1 parent f617ded commit d8c9b4d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/code-editor/code-editor.component.ts
Expand Up @@ -248,6 +248,12 @@ export class NzCodeEditorComponent implements OnDestroy, AfterViewInit {
}

private emitValue(value: string): void {
if (this.value === value) {
// If the value didn't change there's no reason to send an update.
// Specifically this may happen during an update from the model (writeValue) where sending an update to the model would actually be incorrect.
return;
}

this.value = value;
this.onChange(value);
}
Expand Down

0 comments on commit d8c9b4d

Please sign in to comment.