Skip to content

Commit dcbf384

Browse files
Update Header.astro
1 parent 6b1bbd9 commit dcbf384

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

landing/src/components/Header.astro

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,35 @@ const { isHome } = Astro.props;
167167
// Handle demo button click - redirect to home if not already there
168168
function setupDemoButton() {
169169
const showTourBtn = document.querySelector('#showTour');
170-
170+
171171
if (!showTourBtn) return;
172-
173-
// Remove any existing listeners
174-
const newBtn = showTourBtn.cloneNode(true) as HTMLElement;
175-
showTourBtn.parentNode?.replaceChild(newBtn, showTourBtn);
176-
177-
newBtn.addEventListener('click', () => {
178-
// Check if we're on the home page
179-
if (window.location.pathname !== '/') {
180-
// Store flag to start tour after navigation
181-
sessionStorage.setItem('startTourOnLoad', 'true');
182-
window.location.href = '/';
183-
} else {
184-
// We're already on home page, dispatch event to start tour
185-
window.dispatchEvent(new CustomEvent('startTour'));
186-
}
187-
});
172+
173+
// Clean up previous listener if it exists
174+
if ((window as any).__demoButtonAbortController) {
175+
(window as any).__demoButtonAbortController.abort();
176+
}
177+
178+
// Create new AbortController for this listener
179+
const controller = new AbortController();
180+
(window as any).__demoButtonAbortController = controller;
181+
182+
showTourBtn.addEventListener(
183+
'click',
184+
() => {
185+
// Check if we're on the home page
186+
if (window.location.pathname !== '/') {
187+
// Store flag to start tour after navigation
188+
sessionStorage.setItem('startTourOnLoad', 'true');
189+
window.location.href = '/';
190+
} else {
191+
// We're already on home page, dispatch event to start tour
192+
window.dispatchEvent(new CustomEvent('startTour'));
193+
}
194+
},
195+
{ signal: controller.signal }
196+
);
188197
}
189-
190-
// Run on initial load
191-
document.addEventListener('DOMContentLoaded', setupDemoButton);
192-
193-
// Run on Astro page transitions
198+
199+
// Run on Astro page transitions (fires on both initial load and transitions)
194200
document.addEventListener('astro:page-load', setupDemoButton);
195201
</script>

0 commit comments

Comments
 (0)