Skip to content

Commit

Permalink
[8.9] [dashboard] fix Memory leak when reset causes by-value panel to…
Browse files Browse the repository at this point in the history
… be deleted (#161394) (#161467)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[dashboard] fix Memory leak when reset causes by-value panel to be
deleted (#161394)](#161394)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-07-07T14:53:50Z","message":"[dashboard]
fix Memory leak when reset causes by-value panel to be deleted
(#161394)\n\nCloses
https://github.com/elastic/kibana/issues/161310\r\n\r\nIssue caused by
`setState` call after async action without checking that\r\ncomponent is
still mounted. Resolved issue by checking component is\r\nmounted after
any async action or
subscription.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d9c0c554f8e54068c5fd8d0c27094f0d04c6dac3","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Embedding","Team:Presentation","release_note:skip","v8.9.0","v8.10.0","Feature:Embeddables"],"number":161394,"url":"https://github.com/elastic/kibana/pull/161394","mergeCommit":{"message":"[dashboard]
fix Memory leak when reset causes by-value panel to be deleted
(#161394)\n\nCloses
https://github.com/elastic/kibana/issues/161310\r\n\r\nIssue caused by
`setState` call after async action without checking that\r\ncomponent is
still mounted. Resolved issue by checking component is\r\nmounted after
any async action or
subscription.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d9c0c554f8e54068c5fd8d0c27094f0d04c6dac3"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161394","number":161394,"mergeCommit":{"message":"[dashboard]
fix Memory leak when reset causes by-value panel to be deleted
(#161394)\n\nCloses
https://github.com/elastic/kibana/issues/161310\r\n\r\nIssue caused by
`setState` call after async action without checking that\r\ncomponent is
still mounted. Resolved issue by checking component is\r\nmounted after
any async action or
subscription.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d9c0c554f8e54068c5fd8d0c27094f0d04c6dac3"}}]}]
BACKPORT-->

Co-authored-by: Nathan Reese <[email protected]>
  • Loading branch information
kibanamachine and nreese authored Jul 7, 2023
1 parent 2c93de6 commit aa6c21c
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/plugins/embeddable/public/lib/panel/embeddable_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ export class EmbeddablePanel extends React.Component<Props, State> {
}

private async refreshBadges() {
if (!this.mounted) {
return;
}
if (this.props.showBadges === false) {
return;
}
Expand All @@ -173,6 +170,10 @@ export class EmbeddablePanel extends React.Component<Props, State> {
embeddable: this.props.embeddable,
})) as BadgeAction[]) ?? [];

if (!this.mounted) {
return;
}

const { disabledActions } = this.props.embeddable.getInput();
if (disabledActions) {
badges = badges.filter((badge) => disabledActions.indexOf(badge.id) === -1);
Expand All @@ -186,9 +187,6 @@ export class EmbeddablePanel extends React.Component<Props, State> {
}

private async refreshNotifications() {
if (!this.mounted) {
return;
}
if (this.props.showNotifications === false) {
return;
}
Expand All @@ -202,6 +200,10 @@ export class EmbeddablePanel extends React.Component<Props, State> {
embeddable: this.props.embeddable,
})) as NotificationAction[]) ?? [];

if (!this.mounted) {
return;
}

const { disabledActions } = this.props.embeddable.getInput();
if (disabledActions) {
notifications = notifications.filter((badge) => disabledActions.indexOf(badge.id) === -1);
Expand Down Expand Up @@ -353,20 +355,28 @@ export class EmbeddablePanel extends React.Component<Props, State> {
this.subscription.add(
this.props.embeddable.getOutput$().subscribe(
(output: EmbeddableOutput) => {
this.setState({
error: output.error,
loading: output.loading,
});
if (this.mounted) {
this.setState({
error: output.error,
loading: output.loading,
});
}
},
(error) => {
this.setState({ error });
if (this.mounted) {
this.setState({ error });
}
}
)
);

const node = this.props.embeddable.render(this.embeddableRoot.current) ?? undefined;
if (isPromise(node)) {
node.then((resolved) => this.setState({ node: resolved }));
node.then((resolved) => {
if (this.mounted) {
this.setState({ node: resolved });
}
});
} else {
this.setState({ node });
}
Expand Down

0 comments on commit aa6c21c

Please sign in to comment.