Skip to content

Commit ea204c8

Browse files
committed
tmp disable ClientRouter
1 parent f22c15e commit ea204c8

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/components/blog/single.astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ const hideToC = tocDepth === 0 || reducedHeadings.length === 0;
192192
};
193193

194194
const setupToC = () => {
195+
// Keep setup idempotent: this runs immediately for regular navigation and
196+
// again after each ClientRouter navigation.
197+
cleanupToC();
195198
document.getElementById('open-toc')?.addEventListener('click', openToC);
196199
document.getElementById('close-toc')?.addEventListener('click', closeToC);
197200
document.addEventListener('keyup', handleKeyup);
@@ -207,7 +210,9 @@ const hideToC = tocDepth === 0 || reducedHeadings.length === 0;
207210
document.querySelectorAll('.toc-link').forEach((link) => link.removeEventListener('click', closeToC));
208211
};
209212

210-
// astro:page-load fires on initial load and after every view-transition swap.
213+
// Module scripts run on regular page loads; astro:page-load also covers
214+
// initial and subsequent ClientRouter navigations.
215+
setupToC();
211216
document.addEventListener('astro:page-load', setupToC);
212217
document.addEventListener('astro:before-swap', cleanupToC);
213218
</script>

src/components/layout/language-select.astro

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const languageUrls = await Promise.all(
107107
};
108108

109109
const setupLanguageSelect = () => {
110+
// Keep setup idempotent: this runs immediately for regular navigation and
111+
// again after each ClientRouter navigation.
112+
cleanupLanguageSelect();
110113
document.getElementById('close-language-menu')?.addEventListener('click', closeLanguageSelect);
111114
document.getElementById('open-language-menu')?.addEventListener('click', openLanguageSelect);
112115
document.addEventListener('keyup', handleKeyup);
@@ -120,8 +123,9 @@ const languageUrls = await Promise.all(
120123
document.removeEventListener('keydown', trapFocus);
121124
};
122125

123-
// astro:page-load fires on initial load and after every view-transition swap.
126+
// Module scripts run on regular page loads; astro:page-load also covers
127+
// initial and subsequent ClientRouter navigations.
128+
setupLanguageSelect();
124129
document.addEventListener('astro:page-load', setupLanguageSelect);
125-
// astro:before-swap fires right before the DOM is swapped out.
126130
document.addEventListener('astro:before-swap', cleanupLanguageSelect);
127131
</script>

src/components/layout/light-mode-switch.astro

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ const { label } = Astro.props as Props;
5454

5555
const setup = () => {
5656
syncUi(getUserTheme());
57-
document.getElementById(SWITCH_ID)?.addEventListener('click', handleClick);
57+
const button = document.getElementById(SWITCH_ID);
58+
// Keep setup idempotent when both the module script and astro:page-load run.
59+
button?.removeEventListener('click', handleClick);
60+
button?.addEventListener('click', handleClick);
5861
};
5962

60-
// astro:page-load fires on initial load and after every view-transition swap,
61-
// so we don't need the manual astro:after-swap re-registration the Solid
62-
// version used.
63+
// Module scripts run on regular page loads; astro:page-load also covers
64+
// initial and subsequent ClientRouter navigations.
65+
setup();
6366
document.addEventListener('astro:page-load', setup);
6467
</script>

src/layouts/article.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const showTopBanner = (themeConfig.promotions?.topBanner && header?.showTopBanne
7777
<!-- Structured Data -->
7878
<ArticleStructuredData {title} {description} {articleEntry} {locale} />
7979
<!-- Transitions -->
80-
<ClientRouter />
80+
<!--<ClientRouter />-->
8181
</head>
8282
<body>
8383
{showTopBanner ? <TopBanner {locale} /> : null}

src/layouts/default.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const showTopBanner = (themeConfig.promotions?.topBanner && header?.showTopBanne
9595
{isHome ? <WebsiteStructuredData {title} image={structuredDataImage} {author} {publisher} {locale} /> : null}
9696
<WebPageStructuredData {type} {title} {description} image={structuredDataImage} {author} {publisher} {locale} />
9797
<!-- Transitions -->
98-
<ClientRouter />
98+
<!--<ClientRouter />-->
9999
</head>
100100
<body>
101101
{showTopBanner ? <TopBanner {locale} /> : null}

0 commit comments

Comments
 (0)