Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adaptive cards destroy #848

Merged
merged 2 commits into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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