-
Notifications
You must be signed in to change notification settings - Fork 671
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
[question] ColorModeProvider with Gatsby #874
Comments
I might be misunderstanding, but couldn’t you leverage CSS’s loading behavior instead of detecting all this activity with JS? Put your webfont first, then all the system fonts as fallbacks, with font-display: swap on the webfont. That way, the page text will immediately show up in system fonts, then when the webfont loads, will switch to it. If that’s the behavior you’re looking for, I don’t think changing your theme dynamically will be necessary. |
@lachlanjc I have to use a tiny bit of JS (CSS font loading API) so I know when all 3 of the web fonts are loaded and only after this I append CSS class with all the custom fonts to the HTML tag. This way we minimize the number of layout repaints from 3 times to just 1. You can find more information about this technique in this awesome article - Comperhansive webfonts. |
OMG this such an embarrassment! 🤣 I have copied over the code from |
I was experimenting with various font loading strategies with Gatsby and ended up coping over the source of gatsby-plugin-theme-ui so I can update
theme.fonts
values once all the fonts are loaded by the client (by defaulttheme.fonts
are set to system fonts). If there is any other way to do it without modifying the originalgatsby-plugin-theme-ui
please share it.After doing all of that I installed
ColorModeProvider
and added it to thewrap-root-element.js
inside of theThemeProvider
, but it's not completely working. Onlytext
&background
colors are updating, butprimary
,secondary
andmuted
colors are not changing (default theme colors are being used). I can confirm that CSS variables are getting updated each time I change the theme.Please let me know what I'm missing here?
ThemeProvider:
wrap-root-element.js:
ColorModeButton:
I have also asked this question on Stackoverflow and Spectrum in case anyone else is interested in checking these threads.
The text was updated successfully, but these errors were encountered: