Skip to content

Commit

Permalink
fix: adaptive cards destroy (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Feb 15, 2021
1 parent 100ddf1 commit 933e9bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { genericCopy } from '../../common/copy';
import { queryResponseStyles } from './../queryResponse.styles';

class AdaptiveCard extends Component<IAdaptiveCardProps> {
private adaptiveCard: AdaptiveCardsAPI.AdaptiveCard;
private adaptiveCard: AdaptiveCardsAPI.AdaptiveCard | null;

constructor(props: IAdaptiveCardProps) {
super(props);
Expand All @@ -26,7 +26,7 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
const { body, sampleQuery, hostConfig } = this.props;
this.props.actions!.getAdaptiveCard(body, sampleQuery);
if (hostConfig) {
this.adaptiveCard.hostConfig = new AdaptiveCardsAPI.HostConfig(
this.adaptiveCard!.hostConfig = new AdaptiveCardsAPI.HostConfig(
hostConfig
);
}
Expand All @@ -41,7 +41,8 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
}

public componentWillUnmount() {
this.adaptiveCard = new AdaptiveCardsAPI.AdaptiveCard();
// setting the adaptive card reference to null so as to avoid memory leaks
this.adaptiveCard = null;
}

public shouldComponentUpdate(nextProps: IAdaptiveCardProps) {
Expand Down Expand Up @@ -99,8 +100,8 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
}

try {
this.adaptiveCard.parse(data);
const renderedCard = this.adaptiveCard.render();
this.adaptiveCard!.parse(data);
const renderedCard = this.adaptiveCard!.render();
return (
<Pivot className='pivot-response'>
<PivotItem
Expand Down

0 comments on commit 933e9bb

Please sign in to comment.