Annotations: Fixing recursive angular watch loop (#33090)

This commit is contained in:
Torkel Ödegaard 2021-04-19 09:35:43 +02:00 committed by GitHub
parent 58380368af
commit 76034ad1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,9 @@ export class AngularEditorLoader extends React.PureComponent<Props> {
} }
if (this.angularComponent && prevProps.annotation !== this.props.annotation) { if (this.angularComponent && prevProps.annotation !== this.props.annotation) {
this.angularComponent.getScope().ctrl.currentAnnotation = this.props.annotation; const scope = this.angularComponent.getScope();
scope.ctrl.ignoreNextWatcherFiring = true;
scope.ctrl.currentAnnotation = this.props.annotation;
} }
} }
@ -45,12 +47,19 @@ export class AngularEditorLoader extends React.PureComponent<Props> {
ctrl: { ctrl: {
currentDatasource: this.props.datasource, currentDatasource: this.props.datasource,
currentAnnotation: this.props.annotation, currentAnnotation: this.props.annotation,
ignoreNextWatcherFiring: false,
}, },
}; };
this.angularComponent = loader.load(this.ref, scopeProps, template); this.angularComponent = loader.load(this.ref, scopeProps, template);
this.angularComponent.digest(); this.angularComponent.digest();
this.angularComponent.getScope().$watch(() => { this.angularComponent.getScope().$watch(() => {
// To avoid recursive loop when the annotation is updated from outside angular in componentDidUpdate
if (scopeProps.ctrl.ignoreNextWatcherFiring) {
scopeProps.ctrl.ignoreNextWatcherFiring = false;
return;
}
this.props.onChange({ this.props.onChange({
...scopeProps.ctrl.currentAnnotation, ...scopeProps.ctrl.currentAnnotation,
}); });