@@ -32,11 +32,16 @@ function updateActiveNav(path) {
3232}
3333
3434async function navigate ( url , pushState = true ) {
35- if ( isNavigating ) return ;
35+ if ( isNavigating ) {
36+ console . log ( '[PJAX] Navigation skipped — already navigating' ) ;
37+ return ;
38+ }
3639 isNavigating = true ;
40+ console . log ( `[PJAX] Navigating to: ${ url } ` ) ;
3741
3842 const container = document . getElementById ( CONTAINER_ID ) ;
3943 if ( ! container ) {
44+ console . warn ( '[PJAX] #swup container not found, falling back to full page load' ) ;
4045 window . location . href = url ;
4146 return ;
4247 }
@@ -46,6 +51,7 @@ async function navigate(url, pushState = true) {
4651
4752 try {
4853 // Fade out main content only
54+ console . log ( '[PJAX] Fading out main content' ) ;
4955 if ( mainContent ) {
5056 mainContent . style . transition = `opacity ${ TRANSITION_DURATION } ms ease-in-out` ;
5157 mainContent . style . opacity = '0' ;
@@ -55,7 +61,9 @@ async function navigate(url, pushState = true) {
5561
5662 // Fetch new page
5763 const response = await fetch ( url ) ;
64+ console . log ( `[PJAX] Fetch response: ${ response . status } ` ) ;
5865 if ( ! response . ok ) {
66+ console . warn ( `[PJAX] Fetch failed (${ response . status } ), falling back` ) ;
5967 window . location . href = url ;
6068 return ;
6169 }
@@ -66,31 +74,42 @@ async function navigate(url, pushState = true) {
6674
6775 const newContainer = doc . getElementById ( CONTAINER_ID ) ;
6876 if ( ! newContainer ) {
77+ console . warn ( '[PJAX] New page has no #swup container, falling back' ) ;
6978 window . location . href = url ;
7079 return ;
7180 }
7281
7382 // Wait for fade out to finish
7483 await new Promise ( ( r ) => setTimeout ( r , TRANSITION_DURATION ) ) ;
84+ console . log ( '[PJAX] Fade out complete, replacing DOM' ) ;
7585
7686 // Replace main content
7787 const newMain = newContainer . querySelector ( 'main' ) ;
7888 if ( mainContent && newMain ) {
7989 mainContent . innerHTML = newMain . innerHTML ;
90+ console . log ( '[PJAX] ✓ Main content replaced' ) ;
91+ } else {
92+ console . warn ( '[PJAX] ✗ Main content not found' , { mainContent : ! ! mainContent , newMain : ! ! newMain } ) ;
8093 }
8194
8295 // Silently replace sidebar (no animation)
8396 const panel = container . querySelector ( '#panel-wrapper' ) ;
8497 const newPanel = newContainer . querySelector ( '#panel-wrapper' ) ;
8598 if ( panel && newPanel ) {
8699 panel . innerHTML = newPanel . innerHTML ;
100+ console . log ( '[PJAX] ✓ Panel replaced (silent)' ) ;
101+ } else {
102+ console . warn ( '[PJAX] ✗ Panel not found' , { panel : ! ! panel , newPanel : ! ! newPanel } ) ;
87103 }
88104
89105 // Replace tail/footer
90106 const tail = container . querySelector ( '#tail-wrapper' ) ;
91107 const newTail = newContainer . querySelector ( '#tail-wrapper' ) ;
92108 if ( tail && newTail ) {
93109 tail . innerHTML = newTail . innerHTML ;
110+ console . log ( '[PJAX] ✓ Tail/footer replaced (silent)' ) ;
111+ } else {
112+ console . warn ( '[PJAX] ✗ Tail not found' , { tail : ! ! tail , newTail : ! ! newTail } ) ;
94113 }
95114
96115 // Update title
@@ -103,6 +122,7 @@ async function navigate(url, pushState = true) {
103122
104123 // Update sidebar active state
105124 updateActiveNav ( new URL ( url , window . location . origin ) . pathname ) ;
125+ console . log ( '[PJAX] Sidebar nav updated' ) ;
106126
107127 // Scroll to top
108128 window . scrollTo ( { top : 0 } ) ;
@@ -113,14 +133,18 @@ async function navigate(url, pushState = true) {
113133 } else {
114134 container . style . opacity = '1' ;
115135 }
136+ console . log ( `[PJAX] ✓ Navigation complete: ${ url } ` ) ;
116137 } catch ( e ) {
138+ console . error ( '[PJAX] Navigation error:' , e ) ;
117139 window . location . href = url ;
118140 } finally {
119141 isNavigating = false ;
120142 }
121143}
122144
123145export function initPjax ( ) {
146+ console . log ( '[PJAX] Setting up event listeners' ) ;
147+
124148 // Intercept clicks on internal links
125149 document . addEventListener ( 'click' , ( e ) => {
126150 const link = e . target . closest ( 'a' ) ;
@@ -129,13 +153,18 @@ export function initPjax() {
129153 e . preventDefault ( ) ;
130154
131155 // Skip if same page
132- if ( link . href === window . location . href ) return ;
156+ if ( link . href === window . location . href ) {
157+ console . log ( '[PJAX] Same page click ignored:' , link . href ) ;
158+ return ;
159+ }
133160
161+ console . log ( '[PJAX] Link intercepted:' , link . href ) ;
134162 navigate ( link . href ) ;
135163 } ) ;
136164
137165 // Handle browser back/forward
138166 window . addEventListener ( 'popstate' , ( ) => {
167+ console . log ( '[PJAX] Popstate (back/forward):' , window . location . href ) ;
139168 navigate ( window . location . href , false ) ;
140169 } ) ;
141170}
0 commit comments