Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions components/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,24 @@ export function useTheme() {
})

useEffect(() => {
const cookieValue = Cookies.get('color_mode')
const css = getCssTheme(cookieValue)
const component = getComponentTheme(cookieValue)
setTheme({ css, component })
// Using setTimeout with a default delay value of 0 interjects one
// additional event cycle, which works around a bug that is the
// result of a timing issue. Without the setTimeout function
// the page loads, then the docs site switches the color mode to
// match the user's GitHub color mode. Primer React has a useEffect
// call that overrides this change, causing the site to ignore the
// user's GitHub color mode and revert to auto.
// As a temporary workaround, this code that fetches the user's GitHub
// color mode will be called after Primer React's useEffect call.
// The long term solution to this theming issue is to migrate to CSS variables
// under the hood, which Primer is planning to do in the next couple quarters.
Comment thread
colebemis marked this conversation as resolved.
// Reference: https://github.com/primer/react/issues/2229
setTimeout(() => {
Comment thread
colebemis marked this conversation as resolved.
const cookieValue = Cookies.get('color_mode')
const css = getCssTheme(cookieValue)
const component = getComponentTheme(cookieValue)
setTheme({ css, component })
})
}, [])

return { theme }
Expand Down