Skip to content

Commit

Permalink
fix bug on firefox where non-forcedTheme is not updated on navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pacocoursey committed Feb 20, 2022
1 parent e73e36f commit f810f12
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({

const setTheme = useCallback(
theme => {
// If there is a forced theme, changing the theme is a no-op
if (forcedTheme) return

applyTheme(theme)
setThemeState(theme)

// Save to storage
Expand Down Expand Up @@ -120,11 +116,10 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
return () => window.removeEventListener('storage', handleStorage)
}, [setTheme])

// Whenever theme or forcedTheme changes, apply it
useEffect(() => {
if (forcedTheme) {
applyTheme(forcedTheme)
}
}, [forcedTheme])
applyTheme(forcedTheme ?? theme)
}, [forcedTheme, theme])

return (
<ThemeContext.Provider
Expand Down

0 comments on commit f810f12

Please sign in to comment.