FIX: Cleanup properties on closing DiffModal (#1442)
This update ensures that we reset the tracked properties when closing the DiffModal so that the state doesn't leak when triggering the AI suggestions again. We also reset before suggesting new changes, thus if regeneration is called there shouldn't be any leaks either. No tests in this PR as tests currently not working great due to streaming/animation issues. Will do a broader PR following up with various specs to improve test coverage here.
This commit is contained in:
@@ -114,8 +114,7 @@ export default class ModalDiffModal extends Component {
|
||||
|
||||
@action
|
||||
async suggestChanges() {
|
||||
this.smoothStreamer.resetStreaming();
|
||||
this.diffStreamer.reset();
|
||||
this.#resetState();
|
||||
|
||||
try {
|
||||
this.loading = true;
|
||||
@@ -159,11 +158,25 @@ export default class ModalDiffModal extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
cleanupAndClose() {
|
||||
this.#resetState();
|
||||
this.loading = false;
|
||||
this.args.closeModal();
|
||||
}
|
||||
|
||||
#resetState() {
|
||||
this.suggestion = "";
|
||||
this.finalResult = "";
|
||||
this.smoothStreamer.resetStreaming();
|
||||
this.diffStreamer.reset();
|
||||
}
|
||||
|
||||
<template>
|
||||
<DModal
|
||||
class="composer-ai-helper-modal"
|
||||
@title={{i18n "discourse_ai.ai_helper.context_menu.changes"}}
|
||||
@closeModal={{@closeModal}}
|
||||
@closeModal={{this.cleanupAndClose}}
|
||||
>
|
||||
<:body>
|
||||
<div
|
||||
@@ -218,7 +231,7 @@ export default class ModalDiffModal extends Component {
|
||||
</DButton>
|
||||
<DButton
|
||||
class="btn-flat discard"
|
||||
@action={{@closeModal}}
|
||||
@action={{this.cleanupAndClose}}
|
||||
@label="discourse_ai.ai_helper.context_menu.discard"
|
||||
/>
|
||||
<DButton
|
||||
|
||||
Reference in New Issue
Block a user