mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-03-19 19:37:14 +08:00
fix(webui): close EventSource and clear timers on component unmount
Prevent memory leaks by ensuring the search EventSource connection is closed when the modal unmounts and setTimeout handles are cleared in copy-to-clipboard flows across modal components. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -147,17 +147,24 @@ function goBack() {
|
|||||||
step.value = 'input';
|
step.value = 'input';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
async function copyRssLink() {
|
async function copyRssLink() {
|
||||||
const rssLink = rule.value.rss_link?.[0] || rss.value.url || '';
|
const rssLink = rule.value.rss_link?.[0] || rss.value.url || '';
|
||||||
if (rssLink) {
|
if (rssLink) {
|
||||||
await navigator.clipboard.writeText(rssLink);
|
await navigator.clipboard.writeText(rssLink);
|
||||||
copied.value = true;
|
copied.value = true;
|
||||||
setTimeout(() => {
|
clearTimeout(copyTimer);
|
||||||
|
copyTimer = setTimeout(() => {
|
||||||
copied.value = false;
|
copied.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearTimeout(copyTimer);
|
||||||
|
});
|
||||||
|
|
||||||
async function autoDetectOffset() {
|
async function autoDetectOffset() {
|
||||||
if (!rule.value.id) return;
|
if (!rule.value.id) return;
|
||||||
offsetLoading.value = true;
|
offsetLoading.value = true;
|
||||||
|
|||||||
@@ -82,17 +82,24 @@ const infoTags = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Copy RSS link
|
// Copy RSS link
|
||||||
|
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
async function copyRssLink() {
|
async function copyRssLink() {
|
||||||
const rssLink = localRule.value.rss_link?.[0] || '';
|
const rssLink = localRule.value.rss_link?.[0] || '';
|
||||||
if (rssLink) {
|
if (rssLink) {
|
||||||
await navigator.clipboard.writeText(rssLink);
|
await navigator.clipboard.writeText(rssLink);
|
||||||
copied.value = true;
|
copied.value = true;
|
||||||
setTimeout(() => {
|
clearTimeout(copyTimer);
|
||||||
|
copyTimer = setTimeout(() => {
|
||||||
copied.value = false;
|
copied.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearTimeout(copyTimer);
|
||||||
|
});
|
||||||
|
|
||||||
// Auto detect offset using the new detectOffset API
|
// Auto detect offset using the new detectOffset API
|
||||||
async function autoDetectOffset() {
|
async function autoDetectOffset() {
|
||||||
if (!localRule.value.official_title || !localRule.value.season) return;
|
if (!localRule.value.official_title || !localRule.value.season) return;
|
||||||
|
|||||||
@@ -103,17 +103,24 @@ const infoTags = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Copy RSS link
|
// Copy RSS link
|
||||||
|
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
async function copyRssLink() {
|
async function copyRssLink() {
|
||||||
const rssLink = localBangumi.value.rss_link?.[0] || '';
|
const rssLink = localBangumi.value.rss_link?.[0] || '';
|
||||||
if (rssLink) {
|
if (rssLink) {
|
||||||
await navigator.clipboard.writeText(rssLink);
|
await navigator.clipboard.writeText(rssLink);
|
||||||
copied.value = true;
|
copied.value = true;
|
||||||
setTimeout(() => {
|
clearTimeout(copyTimer);
|
||||||
|
copyTimer = setTimeout(() => {
|
||||||
copied.value = false;
|
copied.value = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearTimeout(copyTimer);
|
||||||
|
});
|
||||||
|
|
||||||
// Auto detect offset
|
// Auto detect offset
|
||||||
async function autoDetectOffset() {
|
async function autoDetectOffset() {
|
||||||
if (!localBangumi.value.id) return;
|
if (!localBangumi.value.id) return;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const {
|
|||||||
getProviders,
|
getProviders,
|
||||||
onSearch,
|
onSearch,
|
||||||
clearSearch,
|
clearSearch,
|
||||||
|
closeSearch,
|
||||||
selectResult,
|
selectResult,
|
||||||
clearSelectedResult,
|
clearSelectedResult,
|
||||||
} = useSearchStore();
|
} = useSearchStore();
|
||||||
@@ -61,6 +62,11 @@ const expandedCategories = ref<Set<'group' | 'resolution' | 'subtitle' | 'season
|
|||||||
// Track which bangumi groups have expanded variants
|
// Track which bangumi groups have expanded variants
|
||||||
const expandedVariants = ref<Set<string>>(new Set());
|
const expandedVariants = ref<Set<string>>(new Set());
|
||||||
|
|
||||||
|
// Close EventSource on unmount (prevents leak if navigating away mid-search)
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
closeSearch();
|
||||||
|
});
|
||||||
|
|
||||||
// Close on Escape
|
// Close on Escape
|
||||||
onKeyStroke('Escape', () => {
|
onKeyStroke('Escape', () => {
|
||||||
if (selectedResult.value) {
|
if (selectedResult.value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user