We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
mdbook-theme
--theme
theme/index.hbs
<ul id="theme-list"
id
The root cause is updateThemeSelected() throws if the selected theme is not in the DOM
updateThemeSelected()
I think the cleanest fix is to update get_theme() to return default_theme if the saved theme is invalid
get_theme()
default_theme
// 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
No response
mdbook v0.4.40
The text was updated successfully, but these errors were encountered:
@ehuss pinging according to the contribution guide. Should I open a PR for this fix?
Sorry, something went wrong.
Seems like a reasonable fix to me, would appreciate a PR!
Successfully merging a pull request may close this issue.
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 properlySteps
--theme
, build and serve the bookmdbook-theme
gets set in localStorage (may not be needed?)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 listPossible Solution(s)
The root cause is
updateThemeSelected()
throws if the selected theme is not in the DOMI think the cleanest fix is to update
get_theme()
to returndefault_theme
if the saved theme is invalidVerified that the solution works
Notes
No response
Version
mdbook v0.4.40
The text was updated successfully, but these errors were encountered: