From 5b35d7c644ce306a6a9b70d3a33b9583eaecad55 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 28 May 2024 02:35:40 +0200 Subject: [PATCH] fix occasional errors in Dearrow & ImageZoom --- src/plugins/dearrow/index.tsx | 4 ++-- src/plugins/imageZoom/components/Magnifier.tsx | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/dearrow/index.tsx b/src/plugins/dearrow/index.tsx index 888e2bb4..89199da8 100644 --- a/src/plugins/dearrow/index.tsx +++ b/src/plugins/dearrow/index.tsx @@ -182,8 +182,8 @@ export default definePlugin({ // add dearrow button { - match: /children:\[(?=null!=\i\?\i\.renderSuppressButton)/, - replace: "children:[$self.renderButton(this),", + match: /children:\[(?=null!=\i\?(\i)\.renderSuppressButton)/, + replace: "children:[$self.renderButton($1),", predicate: () => !settings.store.hideButton } ] diff --git a/src/plugins/imageZoom/components/Magnifier.tsx b/src/plugins/imageZoom/components/Magnifier.tsx index aadd0903..585026d6 100644 --- a/src/plugins/imageZoom/components/Magnifier.tsx +++ b/src/plugins/imageZoom/components/Magnifier.tsx @@ -67,15 +67,18 @@ export const Magnifier = ErrorBoundary.wrap(({ instance, size: i } }; const syncVideos = () => { - currentVideoElementRef.current!.currentTime = originalVideoElementRef.current!.currentTime; + if (currentVideoElementRef.current && originalVideoElementRef.current) + currentVideoElementRef.current.currentTime = originalVideoElementRef.current.currentTime; }; const updateMousePosition = (e: MouseEvent) => { + if (!element.current) return; + if (instance.state.mouseOver && instance.state.mouseDown) { const offset = size.current / 2; const pos = { x: e.pageX, y: e.pageY }; - const x = -((pos.x - element.current!.getBoundingClientRect().left) * zoom.current - offset); - const y = -((pos.y - element.current!.getBoundingClientRect().top) * zoom.current - offset); + const x = -((pos.x - element.current.getBoundingClientRect().left) * zoom.current - offset); + const y = -((pos.y - element.current.getBoundingClientRect().top) * zoom.current - offset); setLensPosition({ x: e.x - offset, y: e.y - offset }); setImagePosition({ x, y }); setOpacity(1); @@ -184,6 +187,7 @@ export const Magnifier = ErrorBoundary.wrap(({ instance, size: i src={originalVideoElementRef.current?.src ?? instance.props.src} autoPlay loop + muted /> ) : (