-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
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
fix(v2): set stored theme only if it exists #2113
Conversation
Deploy preview for docusaurus-preview ready! Built with commit ba17d3e |
Deploy preview for docusaurus-2 ready! Built with commit ba17d3e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt it be
let localStorageTheme = null;
try
catch
if locaStorageTheme !== null,
setTheme
I don't think so, the current code is simple and working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is correct because getItem will always return null if key does not exist (local storage cleared). Always thought it was undefined. Although i believe this below still achieve the same. let localStorageTheme = null; |
@endiliey where are you suggesting to add that? I don't think the above code will work if you meant to put it in the fouc script. |
^ in the same code of this PR Its just the same. But more code Just forget it lol. 🤣 |
Motivation
Currently, automatic switching to a dark theme does not work if a dark theme is selected in the system (because even when there is no saved theme in local storage, we set (override init value with correct theme) the theme to
null
value which is cast to an empty string (i.e. light theme)). This PR solves this bug.docusaurus/packages/docusaurus-theme-classic/src/index.js
Lines 29 to 30 in ba7c38c
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan