From d8153ed619026aabdfb3dca75b5c49caec8cf1f0 Mon Sep 17 00:00:00 2001 From: Kenzo Date: Mon, 22 Dec 2025 22:44:22 +0100 Subject: [PATCH] feat(Banner): enhance loading logic and add detailed debug logs - Updated `loadBanner` to wait for DOM readiness with `DOMContentLoaded` support. - Added comprehensive debug logs for banner loading, response status, and DOM interactions. --- src/components/Banner.astro | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/Banner.astro b/src/components/Banner.astro index 3923440..77ba833 100644 --- a/src/components/Banner.astro +++ b/src/components/Banner.astro @@ -10,11 +10,18 @@ import "../styles/components/Banner.css" async function loadBanner() { try { + console.log('Loading banner from:', `${API_BASE}/api/banners/active`); const response = await fetch(`${API_BASE}/api/banners/active`); + console.log('Banner response status:', response.status); + if (response.ok) { const data = await response.json(); + console.log('Banner data:', data); + if (data.banner) { const container = document.getElementById('banner-container'); + console.log('Banner container found:', !!container); + if (container) { container.innerHTML = ` `; + console.log('Banner displayed successfully'); } + } else { + console.log('No active banner found'); } } } catch (error) { @@ -31,6 +41,10 @@ import "../styles/components/Banner.css" } } - // Load banner when page loads - loadBanner(); + // Load banner when DOM is ready + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', loadBanner); + } else { + loadBanner(); + }