-
Notifications
You must be signed in to change notification settings - Fork 15
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
🍪 Use localStorage
instead of cookie for static builds' theme
#445
Conversation
🦋 Changeset detectedLatest commit: d4b6d63 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I took great inspiration from https://www.mattstobbs.com/remix-dark-mode/#2-initial-state-from-user-preferences |
localStorage
instead of cookie for static buildslocalStorage
instead of cookie for static builds' theme
08621a8
to
634a8e7
Compare
Wow, that was a bit of a journey. I think I've learned a lot more about React and SSR. The challenging part of this puzzle was dealing with client-side state ( The way that the above guide handles dark-mode is to defer responsibility for choosing the theme to the client in cases where we don't have an SSR_available theme. When the client hydrates, it can read the client-side APIs to determine the proper value of
(2) is the approach taken in the core theme logic that sets the tailwind class on the We also need to contend with the theme selector which has to reconcile the same problem. I opted to remove any theme-dependence of the DOM here, so the tooltips, aria labels, and SVGs are invariant, and tailwind is left in charge of handling appearance. Another |
3481676
to
52a3db7
Compare
One point to note; this means that the |
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.
These changes are going to conflict with the choices made in downstream themes. I think there are a few small tweaks that we can make to ensure the logic/components for these choices is made in site
, not providers
.
Let me know if that makes sense, or I can expand on what I mean further..!
db92e3b
to
0b728ce
Compare
@rowanc1 I've reworked the logic such that the providers are very thin, and all of the business logic is really in a new |
Thank you yes, that looks solid - I will take a look/test this afternoon and aim to get it in! |
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.
Removing change to cookie
I will fix up the conflicts and merge on Monday. Sorry for my delay. |
e6adf6e
to
46b414d
Compare
This reverts commit 8b9b8b2.
46b414d
to
cd3c0ab
Compare
did some final regression checks on non-static sites, looks good, merging! |
Looks like @rowca1's concerns were addressed, but this flag just remains
This PR doesn't remove the cookie pathway, but rather augments it for static builds. We shouldn't end up with a cookie in these contexts.
Fixes #319
Fixes jupyter-book/mystmd#585
Also fixes bug in which system preference is ignored.
Live MyST server:
2024-08-27.11-41-48.mp4
Static MyST HTML build:
2024-08-27.11-42-21.mp4