Skip to content

Commit 5bf9468

Browse files
fix: guard video.play promise chain for Safari compatibility (#1416)
* fix: guard video.play promise chain for Safari compatibility * ci: apply automated fixes --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 4ed6fae commit 5bf9468

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎src/components/home/HeroPalmMedia.tsx‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ export function HeroPalmMedia() {
99
const [isPlaying, setIsPlaying] = React.useState(false)
1010

1111
const playVideo = React.useCallback((video: HTMLVideoElement) => {
12-
void video
13-
.play()
14-
.then(() => setIsVideoReady(true))
15-
.catch((error: unknown) => {
16-
if (error instanceof DOMException && error.name === 'AbortError') return
17-
console.error('Unable to play the homepage hero animation', error)
18-
setIsPlaying(false)
19-
setIsVideoReady(false)
20-
})
12+
const promise = video.play()
13+
if (promise !== undefined) {
14+
promise
15+
.then(() => setIsVideoReady(true))
16+
.catch((error: unknown) => {
17+
if (error instanceof DOMException && error.name === 'AbortError')
18+
return
19+
console.error('Unable to play the homepage hero animation', error)
20+
setIsPlaying(false)
21+
setIsVideoReady(false)
22+
})
23+
}
2124
}, [])
2225

2326
React.useEffect(() => {

0 commit comments

Comments
 (0)