Skip to content

Commit 41ce0b8

Browse files
authored
fix for back button bug
I prompted Claude: > `There's a bug where hitting back cannot get to the previous page`
1 parent c81ecb1 commit 41ce0b8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

mdn-timelines.html

+16-3
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,23 @@ <h1>MDN Browser Support Timelines</h1>
212212
}
213213

214214
function updateUrlHash(filePath) {
215-
history.pushState(null, '', `#${filePath}`);
215+
if (filePath) {
216+
history.pushState({ filePath }, '', `#${filePath}`);
217+
} else {
218+
history.pushState({ filePath: null }, '', window.location.pathname);
219+
}
220+
}
221+
222+
function clearDisplay() {
223+
document.getElementById('search-input').value = '';
224+
document.getElementById('timeline').innerHTML = '';
225+
document.getElementById('api-details').innerHTML = '';
226+
document.getElementById('suggestions').innerHTML = '';
216227
}
217228

218229
function getHashPath() {
219230
const hash = window.location.hash.slice(1);
220-
return hash ? hash : null;
231+
return hash ? decodeURIComponent(hash) : null;
221232
}
222233

223234
function setupAutocomplete() {
@@ -469,11 +480,13 @@ <h1>MDN Browser Support Timelines</h1>
469480
}
470481

471482
// Handle back/forward navigation
472-
window.addEventListener('popstate', () => {
483+
window.addEventListener('popstate', (event) => {
473484
const hashPath = getHashPath();
474485
if (hashPath) {
475486
document.getElementById('search-input').value = hashPath;
476487
fetchBrowserCompatData(hashPath);
488+
} else {
489+
clearDisplay();
477490
}
478491
});
479492

0 commit comments

Comments
 (0)