refactor: fix memory leak in auth-modal, consolidate escapeHTML helper across 11 components

This commit is contained in:
2026-02-05 15:07:18 +01:00
parent cd437f20e1
commit 08a650ea80
13 changed files with 44 additions and 131 deletions

View File

@@ -1,4 +1,5 @@
import { t } from '../i18n.js'
import { escapeHTML } from '../utils/helpers.js'
/**
* Error Boundary Component
@@ -37,7 +38,7 @@ class ErrorBoundary extends HTMLElement {
<div class="error-boundary">
<div class="error-icon">⚠️</div>
<h3 class="error-title">${t('error.title') || 'Etwas ist schiefgelaufen'}</h3>
<p class="error-message">${this.escapeHtml(errorMessage)}</p>
<p class="error-message">${escapeHTML(errorMessage)}</p>
<button class="btn btn-primary error-retry" type="button">
${t('error.retry') || 'Erneut versuchen'}
</button>
@@ -59,14 +60,6 @@ class ErrorBoundary extends HTMLElement {
this.error = null
}
escapeHtml(str) {
if (!str) return ''
return String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}
}
customElements.define('error-boundary', ErrorBoundary)
@@ -137,7 +130,7 @@ function showErrorToast(message) {
toast.className = 'error-toast'
toast.innerHTML = /* html */`
<span class="error-toast-icon">⚠️</span>
<span class="error-toast-message">${escapeHtml(message)}</span>
<span class="error-toast-message">${escapeHTML(message)}</span>
<button class="error-toast-close" aria-label="Schließen">×</button>
`
@@ -155,15 +148,6 @@ function showErrorToast(message) {
requestAnimationFrame(() => toast.classList.add('visible'))
}
function escapeHtml(str) {
if (!str) return ''
return String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}
// Styles
const style = document.createElement('style')
style.textContent = /* css */`