Skip to content

Commit

Permalink
fix: infinite loop theme flicker (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbien authored Dec 5, 2024
1 parent 32ef714 commit ae2ab9b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions next-themes/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ const Theme = ({
}

// If default theme set, use it if localstorage === null (happens on local storage manual deletion)
const theme = e.newValue || defaultTheme
setTheme(theme)
if (!e.newValue) {
setTheme(defaultTheme)
} else {
setThemeState(e.newValue) // Direct state update to avoid loops
}
}

window.addEventListener('storage', handleStorage)
Expand Down

0 comments on commit ae2ab9b

Please sign in to comment.