Skip to content

Commit 555aeec

Browse files
committed
theme: Fix TOC links broken after first click
1 parent 3e760fa commit 555aeec

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

assets/js/helpers/bridgeTurboAndAlpine.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export function bridgeTurboAndAlpine(Alpine) {
22
document.addEventListener('turbo:before-render', (event) => {
3+
// Stop observing mutations before render
4+
Alpine.stopObservingMutations();
5+
36
event.detail.newBody.querySelectorAll('[data-alpine-generated]').forEach((el) => {
47
if (el.hasAttribute('data-alpine-generated')) {
58
el.removeAttribute('data-alpine-generated');
@@ -9,10 +12,6 @@ export function bridgeTurboAndAlpine(Alpine) {
912
});
1013

1114
document.addEventListener('turbo:render', () => {
12-
if (document.documentElement.hasAttribute('data-turbo-preview')) {
13-
return;
14-
}
15-
1615
document.querySelectorAll('[data-alpine-ignored]').forEach((el) => {
1716
el.removeAttribute('x-ignore');
1817
el.removeAttribute('data-alpine-ignored');
@@ -30,9 +29,6 @@ export function bridgeTurboAndAlpine(Alpine) {
3029

3130
// Cleanup Alpine state on navigation.
3231
document.addEventListener('turbo:before-cache', () => {
33-
// This will be restarted in turbo:render.
34-
Alpine.stopObservingMutations();
35-
3632
document.body.querySelectorAll('[data-turbo-permanent]').forEach((el) => {
3733
if (!el.hasAttribute('x-ignore')) {
3834
el.setAttribute('x-ignore', true);
@@ -53,15 +49,5 @@ export function bridgeTurboAndAlpine(Alpine) {
5349
el._x_teleport.setAttribute('data-alpine-generated', true);
5450
}
5551
});
56-
57-
document.body.querySelectorAll('[x-data]').forEach((el) => {
58-
if (!el.hasAttribute('data-turbo-permanent')) {
59-
Alpine.destroyTree(el);
60-
// Turbo leaks DOM elements via their data-turbo-permanent handling.
61-
// That needs to be fixed upstream, but until then.
62-
let clone = el.cloneNode(true);
63-
el.replaceWith(clone);
64-
}
65-
});
6652
});
6753
}

assets/js/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import focus from '@alpinejs/focus';
88

99
var debug = 0 ? console.log.bind(console, '[index]') : function () {};
1010

11+
// Expose Alpine to window for access from other modules/scripts
12+
window.Alpine = Alpine;
13+
1114
// Set up and start Alpine.
1215
(function () {
1316
// Register AlpineJS plugins.

layouts/_partials/layouts/header/mobilemenu.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{/* Mobile menu overlay and panel - only visible on small screens */}}
22
<div
33
x-show="$store.nav.mobileMenu.open"
4+
:class="$store.nav.mobileMenu.open ? 'pointer-events-auto' : 'pointer-events-none'"
45
x-transition:enter="transition-opacity ease-out duration-200"
56
x-transition:enter-start="opacity-0"
67
x-transition:enter-end="opacity-100"
@@ -15,6 +16,7 @@
1516
{{/* Mobile menu panel */}}
1617
<div
1718
x-show="$store.nav.mobileMenu.open"
19+
:class="$store.nav.mobileMenu.open ? 'pointer-events-auto' : 'pointer-events-none'"
1820
x-transition:enter="transition ease-out duration-200"
1921
x-transition:enter-start="translate-x-full"
2022
x-transition:enter-end="translate-x-0"

layouts/_partials/layouts/search/results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div
2-
class="fixed inset-0 overflow-hidden z-20"
3-
:class="{'fixed': open}"
2+
class="fixed inset-0 overflow-hidden z-20 pointer-events-none"
3+
:class="open && 'pointer-events-auto'"
44
aria-label="Search docs"
55
role="dialog"
66
aria-modal="true"

0 commit comments

Comments
 (0)