Skip to content

Commit 5a75a28

Browse files
committed
Fixed theme switcher bfcache handling.
Reloaded the theme setting from the cookie when the browser restores page state from the backward/forward cache. This fixes a problem where a theme change on one page appeared to be reverted when navigating via history buttons.
1 parent a230fa9 commit 5a75a28

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

djangoproject/static/js/mod/switch-dark-mode.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ document.addEventListener('DOMContentLoaded', function () {
9595
setupThemeToggle();
9696
});
9797

98+
window.addEventListener('pageshow', function (e) {
99+
if (e.persisted) {
100+
// Re-initialize from cookie in case theme was changed on another page.
101+
initTheme();
102+
}
103+
});
104+
98105
prefersDarkMediaQuery.addEventListener('change', (e) => {
99106
prefersDark = e.matches;
100107
});

0 commit comments

Comments
 (0)