Skip to content

Commit

Permalink
Merge pull request #3893 from thematters/fix/update-book-color-in-fir…
Browse files Browse the repository at this point in the history
…efox

fix(useColorThief): fix theme color
  • Loading branch information
wlliaml authored Oct 16, 2023
2 parents 97d043f + 397e004 commit 663b0f6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Hook/useColorThief.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const rgbToHsl = (r: number, g: number, b: number) => {
export const useColorThief = () => {
const [dominantColor, setDominantColor] = useState<string>()
const nodeRef = useRef<HTMLDivElement>(null)
let tryGetColorTime = 5

const _getColor = () => {
import('colorthief').then(({ default: ColorThief }) => {
Expand All @@ -33,8 +34,16 @@ export const useColorThief = () => {
2
)}% 30%)`
)
} catch (error) {
//
} catch (error: any) {
if (error.name === 'SecurityError') {
// Throws this error in Firefox
setTimeout(() => {
if (tryGetColorTime > 0) {
_getColor()
tryGetColorTime--
}
}, 1000)
}
}
})
}
Expand Down

1 comment on commit 663b0f6

@vercel
Copy link

@vercel vercel bot commented on 663b0f6 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.