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:
Keegan George 2025-06-17 13:57:46 -07:00 committed by GitHub
parent 9dccc1eb93
commit 62d746662a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -114,8 +114,7 @@ export default class ModalDiffModal extends Component {
@action @action
async suggestChanges() { async suggestChanges() {
this.smoothStreamer.resetStreaming(); this.#resetState();
this.diffStreamer.reset();
try { try {
this.loading = true; 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> <template>
<DModal <DModal
class="composer-ai-helper-modal" class="composer-ai-helper-modal"
@title={{i18n "discourse_ai.ai_helper.context_menu.changes"}} @title={{i18n "discourse_ai.ai_helper.context_menu.changes"}}
@closeModal={{@closeModal}} @closeModal={{this.cleanupAndClose}}
> >
<:body> <:body>
<div <div
@ -218,7 +231,7 @@ export default class ModalDiffModal extends Component {
</DButton> </DButton>
<DButton <DButton
class="btn-flat discard" class="btn-flat discard"
@action={{@closeModal}} @action={{this.cleanupAndClose}}
@label="discourse_ai.ai_helper.context_menu.discard" @label="discourse_ai.ai_helper.context_menu.discard"
/> />
<DButton <DButton