Skip to content

Commit f8cd037

Browse files
committed
fix: 修复bug
1 parent 7941846 commit f8cd037

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/layouts/Layout.astro

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,6 @@ updateScrollUI();
723723
window.addEventListener('scroll', requestScrollUpdate, { passive: true });
724724
window.addEventListener('resize', requestResizeUpdate, { passive: true });
725725

726-
if (window?.swup?.hooks) {
727-
setup()
728-
} else {
729-
document.addEventListener('swup:enable', setup)
730-
}
731-
732726
</script>
733727

734728
<script>
@@ -796,9 +790,15 @@ const setup = () => {
796790
)
797791
}
798792

799-
if (window.swup) {
800-
setup()
801-
} else {
802-
document.addEventListener("swup:enable", setup)
793+
// Initialize Swup hooks when ready
794+
// In production, swup may initialize after this script loads
795+
const initSwupHooks = () => {
796+
if (!window.swup?.hooks) return false;
797+
setup();
798+
return true;
799+
};
800+
801+
if (!initSwupHooks()) {
802+
document.addEventListener('swup:enable', initSwupHooks, { once: true });
803803
}
804804
</script>

0 commit comments

Comments
 (0)