From 556d1bea4f6e5c8dcb7ee05b154747d38018af7c Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Sun, 30 Nov 2025 15:42:31 +0100 Subject: [PATCH] fix: handles view not found error gracefully (#4788) --- .../src/core/video-view/VideoView.tsx | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/react-native-video/src/core/video-view/VideoView.tsx b/packages/react-native-video/src/core/video-view/VideoView.tsx index c4c43d55..b4d488e2 100644 --- a/packages/react-native-video/src/core/video-view/VideoView.tsx +++ b/packages/react-native-video/src/core/video-view/VideoView.tsx @@ -8,7 +8,11 @@ import type { } from '../../spec/nitro/VideoViewViewManager.nitro'; import type { VideoViewEvents } from '../types/Events'; import type { ResizeMode } from '../types/ResizeMode'; -import { tryParseNativeVideoError, VideoError } from '../types/VideoError'; +import { + tryParseNativeVideoError, + VideoComponentError, + VideoError, +} from '../types/VideoError'; import type { VideoPlayer } from '../VideoPlayer'; import { NativeVideoView } from './NativeVideoView'; @@ -172,7 +176,31 @@ const VideoView = React.forwardRef( resizeMode: resizeMode, }); } catch (error) { - throw tryParseNativeVideoError(error); + const parsedError = tryParseNativeVideoError(error); + + if ( + parsedError instanceof VideoComponentError && + parsedError.code === 'view/not-found' + ) { + // The view was not found, did view get unmounted? + if (id === nitroId) { + // The id from native is same as the one we have, + // so the view was unmounted before native manager was able to find it + + // On slow devices, when we quickly mount and unmount the view, + // the native manager may not have been able to find the view before the view was unmounted + // This should really never happen, but it's better to be safe than sorry + + // We don't throw an error here, because it's not an actual error. + console.warn( + '[ReactNativeVideo] VideoView was unmounted before native manager was able to find it. It can happen when the view is quickly mounted and unmounted.' + ); + + return; + } + } + + throw parsedError; } }, [ @@ -182,6 +210,7 @@ const VideoView = React.forwardRef( pictureInPicture, autoEnterPictureInPicture, resizeMode, + nitroId, ] );