[fix] Missing element crash (rare) on video shapes. (#3037)

This PR adds a few guards against crashes when the video shape element
is not found.

### Change Type

- [x] `patch` — Bug fix

### Release Notes

- Fixed a rare crash with video shapes.
pull/2994/head^2
Steve Ruiz 2024-03-02 19:38:21 +00:00 zatwierdzone przez GitHub
rodzic 52df06b014
commit 1aef0e8f61
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -46,6 +46,7 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
const handlePlay = useCallback<ReactEventHandler<HTMLVideoElement>>(
(e) => {
const video = e.currentTarget
if (!video) return
editor.updateShapes([
{
@ -64,6 +65,7 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
const handlePause = useCallback<ReactEventHandler<HTMLVideoElement>>(
(e) => {
const video = e.currentTarget
if (!video) return
editor.updateShapes([
{
@ -82,6 +84,7 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
const handleSetCurrentTime = useCallback<ReactEventHandler<HTMLVideoElement>>(
(e) => {
const video = e.currentTarget
if (!video) return
if (isEditing) {
editor.updateShapes([
@ -103,6 +106,7 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
const handleLoadedData = useCallback<ReactEventHandler<HTMLVideoElement>>(
(e) => {
const video = e.currentTarget
if (!video) return
if (time !== video.currentTime) {
video.currentTime = time
}
@ -119,7 +123,6 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
// If the current time changes and we're not editing the video, update the video time
useEffect(() => {
const video = rVideo.current
if (!video) return
if (isLoaded && !isEditing && time !== video.currentTime) {
@ -136,6 +139,7 @@ export class VideoShapeUtil extends BaseBoxShapeUtil<TLVideoShape> {
useEffect(() => {
if (prefersReducedMotion) {
const video = rVideo.current
if (!video) return
video.pause()
video.currentTime = 0
}