Fix TypeScript errors in onError handlers for image/video elements
Some checks are pending
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
CI / build (push) Blocked by required conditions

This commit is contained in:
KV-Tube Deployer 2026-03-24 23:35:16 +07:00
parent 1a04f8f486
commit 82a51b7ee4
8 changed files with 34 additions and 18 deletions

View file

@ -52,8 +52,10 @@ function VideoCard({ video, hideChannelAvatar }: { video: VideoData; hideChannel
className="videocard-thumb" className="videocard-thumb"
priority={false} priority={false}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{video.duration && !video.is_mix && ( {video.duration && !video.is_mix && (

View file

@ -150,8 +150,10 @@ export default async function LibraryPage() {
className="videocard-thumb" className="videocard-thumb"
style={{ width: '100%', height: '100%', objectFit: 'cover' }} style={{ width: '100%', height: '100%', objectFit: 'cover' }}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{video.duration && ( {video.duration && (

View file

@ -124,8 +124,10 @@ export default async function SubscriptionsPage() {
alt={video.title} alt={video.title}
style={{ width: '100%', height: '100%', objectFit: 'cover' }} style={{ width: '100%', height: '100%', objectFit: 'cover' }}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{video.duration && ( {video.duration && (

View file

@ -88,8 +88,10 @@ async function SearchResults({ query }: { query: string }) {
style={{ width: '100%', height: '100%', objectFit: 'cover', backgroundColor: '#272727' }} style={{ width: '100%', height: '100%', objectFit: 'cover', backgroundColor: '#272727' }}
className="search-result-thumb" className="search-result-thumb"
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{v.duration && ( {v.duration && (
@ -119,8 +121,9 @@ async function SearchResults({ query }: { query: string }) {
alt="" alt=""
style={{ width: '100%', height: '100%', objectFit: 'cover' }} style={{ width: '100%', height: '100%', objectFit: 'cover' }}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/img/channels/c_ip_m_default.jpg'; // Fallback to YouTube's default channel avatar img.onerror = null;
img.src = 'https://i.ytimg.com/img/channels/c_ip_m_default.jpg'; // Fallback to YouTube's default channel avatar
}} }}
/> />
) : firstLetter} ) : firstLetter}

View file

@ -122,8 +122,9 @@ export default function Comments({ videoId }: CommentsProps) {
sizes="40px" sizes="40px"
style={{ objectFit: 'cover' }} style={{ objectFit: 'cover' }}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/img/channels/c_ip_m_default.jpg'; // Fallback to YouTube's default channel avatar img.onerror = null;
img.src = 'https://i.ytimg.com/img/channels/c_ip_m_default.jpg'; // Fallback to YouTube's default channel avatar
}} }}
/> />
</div> </div>

View file

@ -100,8 +100,10 @@ export default function PlaylistPanel({ videos, currentVideoId, listId, title }:
sizes="100px" sizes="100px"
style={{ objectFit: 'cover' }} style={{ objectFit: 'cover' }}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{video.duration && ( {video.duration && (

View file

@ -54,8 +54,10 @@ export default async function RelatedVideos({ videoId, title, uploader }: { vide
alt={video.title} alt={video.title}
className="related-thumb-img" className="related-thumb-img"
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const img = e.target as HTMLImageElement;
e.target.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (img.src !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
img.src = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />
{video.duration && ( {video.duration && (

View file

@ -569,8 +569,10 @@ export default function VideoPlayer({ videoId, title }: VideoPlayerProps) {
preload="auto" preload="auto"
poster={`https://i.ytimg.com/vi/${videoId}/maxresdefault.jpg`} poster={`https://i.ytimg.com/vi/${videoId}/maxresdefault.jpg`}
onError={(e) => { onError={(e) => {
e.target.onError = null; // Prevent infinite loop const video = e.target as HTMLVideoElement;
e.target.poster = 'https://i.ytimg.com/vi/default/hqdefault.jpg'; // Fallback to YouTube's default thumbnail if (video.poster !== 'https://i.ytimg.com/vi/default/hqdefault.jpg') {
video.poster = 'https://i.ytimg.com/vi/default/hqdefault.jpg';
}
}} }}
/> />