Skip to content

Commit

Permalink
Merge pull request #2463 from Pistonight/bug/theme_popup
Browse files Browse the repository at this point in the history
fix: themes broken when localStorage has invalid theme id stored
  • Loading branch information
ehuss authored Nov 2, 2024
2 parents 5ec4f65 + 4a330ae commit 47384c1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ function playground_text(playground, hidden = true) {
var themeToggleButton = document.getElementById('theme-toggle');
var themePopup = document.getElementById('theme-list');
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
var themeIds = [];
themePopup.querySelectorAll('button.theme').forEach(function (el) {
themeIds.push(el.id);
});
var stylesheets = {
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
Expand Down Expand Up @@ -317,7 +321,7 @@ function playground_text(playground, hidden = true) {
function get_theme() {
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
if (theme === null || theme === undefined) {
if (theme === null || theme === undefined || !themeIds.includes(theme)) {
return default_theme;
} else {
return theme;
Expand Down

0 comments on commit 47384c1

Please sign in to comment.