-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
feat: sync color mode between browser tabs #6723
Conversation
✔️ [V2] 🔨 Explore the source changes: 0de81ae 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6216545d2a3b480008694ebf 😎 Browse the preview: https://deploy-preview-6723--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6723--docusaurus-2.netlify.app/ |
Size Change: +629 B (0%) Total Size: 782 kB
ℹ️ View Unchanged
|
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.
That's interesting, certainly works!
this is so cool |
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.
LGTM thanks 👍
console.error(err); | ||
} | ||
}; | ||
window.addEventListener('storage', onChange); |
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.
I don't think it's going to be a problem but it's worth double-checking if this storage event listener could throw in some cases? (like iframe + blocking cookies, see #4501)
@@ -31,6 +31,10 @@ const ToggleComponent = memo( | |||
const [focused, setFocused] = useState(false); | |||
const inputRef = useRef<HTMLInputElement>(null); | |||
|
|||
useEffect(() => { |
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.
hmm I have mitigated feeling because we now have the toggle state in 2 places: localstorage + react state
but it's probably fine because localstorage can't be considered reliable in all cases (and we want the toggle to keep working on such cases)
that should be fine for now 👍 but I have some refactoring ideas for later
setTheme(coerceToTheme(storedTheme)); | ||
} | ||
} catch (err) { | ||
console.error(err); |
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.
a good candidate for reportError
later, see #6747
Motivation
This is quite handy, especially when you have several tabs open from the same docs site.
Also fixes #6733.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Related PRs