Fix safari 13 crash

pull/2375/head
Jérémy Rialland 2022-11-14 19:08:38 +01:00 committed by Jérémy Rialland
parent e7c957ab18
commit 1aef3657c0
2 changed files with 14 additions and 5 deletions

View File

@ -46,9 +46,18 @@ export const DarkModeProvider: React.FC = ({ children }) => {
setDarkMode(e.matches)
}
const matchDarkMode = window.matchMedia('(prefers-color-scheme: dark)')
matchDarkMode.addEventListener('change', onDarkModeChange)
return () => matchDarkMode.removeEventListener('change', onDarkModeChange)
// safari 13 doesn't have addEventListener
matchDarkMode.addEventListener
? matchDarkMode.addEventListener('change', onDarkModeChange)
: matchDarkMode.addListener(onDarkModeChange)
return () => {
// safari 13 doesn't have removeEventListener
matchDarkMode.removeEventListener
? matchDarkMode.removeEventListener('change', onDarkModeChange)
: matchDarkMode.removeListener(onDarkModeChange)
}
})
return (

View File

@ -223,7 +223,7 @@
<script>
// Set the main colors from the provided customization in the URL We do it
// before loading the whole JS bundle to avoid a UI flash. cf. #1786
const parseColor = (rawColor) => {
function parseColor(rawColor) {
try {
return JSON.parse(decodeURIComponent(rawColor))
} catch (error) {
@ -233,10 +233,10 @@
}
}
try {
let rawColor = new URLSearchParams(
const rawColor = new URLSearchParams(
document.location.search.substring(1)
).get('couleur')
let iframeColor = rawColor && parseColor(rawColor)
const iframeColor = rawColor && parseColor(rawColor)
;[
document.documentElement,
...document.querySelectorAll('[data-js-color-element]'),