Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 62d7466

Browse files
authored
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.
1 parent 9dccc1e commit 62d7466

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

assets/javascripts/discourse/components/modal/diff-modal.gjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ export default class ModalDiffModal extends Component {
114114

115115
@action
116116
async suggestChanges() {
117-
this.smoothStreamer.resetStreaming();
118-
this.diffStreamer.reset();
117+
this.#resetState();
119118

120119
try {
121120
this.loading = true;
@@ -159,11 +158,25 @@ export default class ModalDiffModal extends Component {
159158
}
160159
}
161160

161+
@action
162+
cleanupAndClose() {
163+
this.#resetState();
164+
this.loading = false;
165+
this.args.closeModal();
166+
}
167+
168+
#resetState() {
169+
this.suggestion = "";
170+
this.finalResult = "";
171+
this.smoothStreamer.resetStreaming();
172+
this.diffStreamer.reset();
173+
}
174+
162175
<template>
163176
<DModal
164177
class="composer-ai-helper-modal"
165178
@title={{i18n "discourse_ai.ai_helper.context_menu.changes"}}
166-
@closeModal={{@closeModal}}
179+
@closeModal={{this.cleanupAndClose}}
167180
>
168181
<:body>
169182
<div
@@ -218,7 +231,7 @@ export default class ModalDiffModal extends Component {
218231
</DButton>
219232
<DButton
220233
class="btn-flat discard"
221-
@action={{@closeModal}}
234+
@action={{this.cleanupAndClose}}
222235
@label="discourse_ai.ai_helper.context_menu.discard"
223236
/>
224237
<DButton

0 commit comments

Comments
 (0)