Commit 32c4704
committed
fix: prevent back-button trap when partials navigate through redirects
When clicking a link that triggers a server redirect (e.g. /docs → /docs/syntax),
both URLs were pushed to history, creating a back-button trap: pressing back would
go to /docs, which immediately redirects back to /docs/syntax.
Root cause: the click handler pushed the clicked URL before fetch, then
fetchPartials pushed the redirect target after — two pushState calls for one
navigation.
Fix: pull history management out of fetchPartials (which now just returns the
final URL) and let each caller handle history appropriately:
- Click handler: pushState before fetch, replaceState after if redirected
- Form handler: pushState after fetch with the final URL (preserves POST-redirect-GET)
- Popstate handler: replaceState if redirected (prevents infinite loops on back/forward)
- Button handler: no history changes
Also fixes:
- ?fresh-partial query param stripped from URLs before they enter history
- updateLinks() now uses the post-redirect URL for correct active link highlighting
- Form submissions now save scroll position before fetch (was previously missed)1 parent cb6d02d commit 32c4704
1 file changed
Lines changed: 41 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
90 | 100 | | |
| 101 | + | |
91 | 102 | | |
92 | 103 | | |
93 | 104 | | |
94 | | - | |
95 | | - | |
| 105 | + | |
| 106 | + | |
96 | 107 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
109 | 118 | | |
110 | 119 | | |
111 | 120 | | |
| |||
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
157 | | - | |
| 166 | + | |
| 167 | + | |
158 | 168 | | |
159 | 169 | | |
160 | 170 | | |
161 | 171 | | |
162 | 172 | | |
| 173 | + | |
163 | 174 | | |
164 | | - | |
165 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
166 | 180 | | |
167 | 181 | | |
168 | 182 | | |
| |||
185 | 199 | | |
186 | 200 | | |
187 | 201 | | |
188 | | - | |
| 202 | + | |
189 | 203 | | |
190 | 204 | | |
191 | 205 | | |
| |||
223 | 237 | | |
224 | 238 | | |
225 | 239 | | |
226 | | - | |
227 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
228 | 245 | | |
229 | 246 | | |
230 | 247 | | |
| |||
304 | 321 | | |
305 | 322 | | |
306 | 323 | | |
| 324 | + | |
307 | 325 | | |
308 | | - | |
| 326 | + | |
| 327 | + | |
309 | 328 | | |
310 | 329 | | |
311 | 330 | | |
| |||
347 | 366 | | |
348 | 367 | | |
349 | 368 | | |
350 | | - | |
351 | 369 | | |
352 | | - | |
| 370 | + | |
353 | 371 | | |
354 | 372 | | |
355 | 373 | | |
| |||
361 | 379 | | |
362 | 380 | | |
363 | 381 | | |
| 382 | + | |
364 | 383 | | |
365 | 384 | | |
366 | 385 | | |
| |||
369 | 388 | | |
370 | 389 | | |
371 | 390 | | |
372 | | - | |
| 391 | + | |
373 | 392 | | |
374 | 393 | | |
375 | 394 | | |
376 | 395 | | |
377 | | - | |
378 | | - | |
379 | | - | |
| 396 | + | |
380 | 397 | | |
381 | 398 | | |
382 | 399 | | |
| |||
0 commit comments