Skip to content

Commit 47384c1

Browse files
authored
Merge pull request #2463 from Pistonight/bug/theme_popup
fix: themes broken when localStorage has invalid theme id stored
2 parents 5ec4f65 + 4a330ae commit 47384c1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/theme/book.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ function playground_text(playground, hidden = true) {
289289
var themeToggleButton = document.getElementById('theme-toggle');
290290
var themePopup = document.getElementById('theme-list');
291291
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
292+
var themeIds = [];
293+
themePopup.querySelectorAll('button.theme').forEach(function (el) {
294+
themeIds.push(el.id);
295+
});
292296
var stylesheets = {
293297
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
294298
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
@@ -317,7 +321,7 @@ function playground_text(playground, hidden = true) {
317321
function get_theme() {
318322
var theme;
319323
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
320-
if (theme === null || theme === undefined) {
324+
if (theme === null || theme === undefined || !themeIds.includes(theme)) {
321325
return default_theme;
322326
} else {
323327
return theme;

0 commit comments

Comments
 (0)