-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: A bug, incorrect or unintended behaviorCategory: A bug, incorrect or unintended behavior
Description
Problem
If mdbook-theme
in localStorage contains a theme id that's not in the book, an uncaught exception causes theme popup to not function properly
Steps
- Create a new project with
--theme
, build and serve the book - Switch the theme so
mdbook-theme
gets set in localStorage (may not be needed?) - Edit
theme/index.hbs
, find<ul id="theme-list"
and remove/change theid
of the button so that the saved theme is no longer in the list - Rebuild the book
- Observe that clicking on the theme button no longer opens the menu
Possible Solution(s)
The root cause is updateThemeSelected()
throws if the selected theme is not in the DOM
I think the cleanest fix is to update get_theme()
to return default_theme
if the saved theme is invalid
// cache the valid theme ids
var themeIds = [];
themePopup.querySelectorAll('button.theme').forEach(function (el) {
themeIds.push(el.id);
});
// ...
function get_theme() {
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
if (theme === null || theme === undefined || !themeIds.includes(theme)) { // <- add this check
return default_theme;
} else {
return theme;
}
}
Verified that the solution works
Notes
No response
Version
mdbook v0.4.40
Metadata
Metadata
Assignees
Labels
C-bugCategory: A bug, incorrect or unintended behaviorCategory: A bug, incorrect or unintended behavior