From 62d746662aa928fa705f4342a652a8ba4be14ec3 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 17 Jun 2025 13:57:46 -0700 Subject: [PATCH] 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. --- .../discourse/components/modal/diff-modal.gjs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/modal/diff-modal.gjs b/assets/javascripts/discourse/components/modal/diff-modal.gjs index dc29b7ed..8eea2fd9 100644 --- a/assets/javascripts/discourse/components/modal/diff-modal.gjs +++ b/assets/javascripts/discourse/components/modal/diff-modal.gjs @@ -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(); + } +