Skip to content

Commit aae3d82

Browse files
authored
Cleanup event listeners (#4456)
1 parent 8be1b76 commit aae3d82

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

packages/playground/src/components/KycVerifier.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
<v-card>
2525
<v-card-title class="bg-primary d-flex align-center">
2626
<v-icon icon="mdi-security" />
27-
<div class="pl-2">
28-
Terms & Conditions
29-
</div>
27+
<div class="pl-2">Terms & Conditions</div>
3028
</v-card-title>
3129

3230
<v-card-text class="pb-0">
3331
We use iDenfy to verify your identity.
34-
<br>
32+
<br />
3533
Please ensure you review iDenfy’s <span class="font-weight-bold">Security and Compliance</span>, which
3634
includes their <span class="font-weight-bold">Terms & Conditions, Privacy Policy</span>, and other relevant
3735
documents.
@@ -46,12 +44,8 @@
4644
</v-checkbox>
4745
</v-card-text>
4846
<v-card-actions class="justify-end my-1 mr-2">
49-
<v-btn color="anchor" @click="handleAgreementDialog(false)">
50-
Cancel
51-
</v-btn>
52-
<v-btn :disabled="!agreedCheckbox" @click="handleAgreementDialog(true)">
53-
Continue
54-
</v-btn>
47+
<v-btn color="anchor" @click="handleAgreementDialog(false)"> Cancel </v-btn>
48+
<v-btn :disabled="!agreedCheckbox" @click="handleAgreementDialog(true)"> Continue </v-btn>
5549
</v-card-actions>
5650
</v-card>
5751
</v-dialog>
@@ -85,6 +79,10 @@ export default {
8579
const agreed = ref(false);
8680
const agreedCheckbox = ref(false);
8781
const handleUpdateDialog = (event: boolean) => {
82+
// Clean up listener when dialog closes
83+
if (!event) {
84+
window.removeEventListener("message", handleReceiveMessage, false);
85+
}
8886
emit("update:moduleValue", event);
8987
};
9088
const handleAgreementDialog = (agreed: boolean) => {
@@ -103,10 +101,14 @@ export default {
103101
agreed.value = true;
104102
if (!kyc.client) throw new Error("KYC client is not initialized");
105103
token.value = await kyc.client.getToken();
104+
// Remove any existing listener before adding a new one to prevent duplicates
105+
window.removeEventListener("message", handleReceiveMessage, false);
106106
window.addEventListener("message", handleReceiveMessage, false);
107107
kycDialog.value = true;
108108
} catch (e) {
109109
handleUpdateDialog(false);
110+
// Clean up listener on error
111+
window.removeEventListener("message", handleReceiveMessage, false);
110112
if (e instanceof KycErrors.AlreadyVerified) {
111113
kyc.updateStatus();
112114
createCustomToast("Already verified", ToastType.info);

packages/playground/src/components/weblet_layout.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<script lang="ts" setup>
110110
import { events, type GridClient, type NodeInfo } from "@threefold/grid_client";
111111
import debounce from "lodash/debounce.js";
112-
import { computed, ref, watch } from "vue";
112+
import { computed, onUnmounted, ref, watch } from "vue";
113113
import { useTheme } from "vuetify";
114114
115115
import { manual } from "@/utils/manual";
@@ -180,6 +180,11 @@ watch(status, s => {
180180
if (s === "deploy") events.addListener("logs", onLogMessage);
181181
else events.removeListener("logs", onLogMessage);
182182
});
183+
184+
// Ensure cleanup on component unmount
185+
onUnmounted(() => {
186+
events.removeListener("logs", onLogMessage);
187+
});
183188
const alertType = computed(() => {
184189
if (status.value === "deploy") return "info";
185190
else if (status.value === "failed") return "error";

0 commit comments

Comments
 (0)