Skip to content

Commit a509895

Browse files
committed
fix: constant re-rendering and possible lost evenlisteners in hover
1 parent f10f18c commit a509895

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/webui/src/client/ui/PreviewPopUp/PreviewPopUp.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ export const PreviewPopUp = React.forwardRef<
8080
x,
8181
anchor?.getBoundingClientRect().y ?? 0
8282
)
83-
if (update) update().catch((e) => console.error(e))
83+
// If update is available, call it to reposition the popper:
84+
if (updateRef.current) {
85+
updateRef.current().catch((e) => console.error(e))
86+
}
8487
}
8588
document.addEventListener('mousemove', listener)
8689

8790
return () => {
8891
document.removeEventListener('mousemove', listener)
8992
}
9093
}
91-
}, [update, anchor])
94+
}, [trackMouse, anchor])
9295

9396
useImperativeHandle(ref, () => {
9497
return {

packages/webui/src/client/ui/PreviewPopUp/Previews/IFramePreview.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ export function IFramePreview({ content }: IFramePreviewProps): React.ReactEleme
2020
const url = new URL(content.href)
2121
iFrameElement.current?.contentWindow?.postMessage(content.postMessage, url.origin)
2222
}
23-
}, [])
23+
}, [content.postMessage, content.href])
2424

2525
useEffect(() => {
26-
if (!iFrameElement) return
26+
// Create a stable reference to the iframe element:
27+
const currentIFrame = iFrameElement.current
28+
if (!currentIFrame) return
29+
currentIFrame.addEventListener('load', onLoadListener)
2730

28-
iFrameElement.current?.addEventListener('load', onLoadListener)
29-
30-
return () => iFrameElement.current?.removeEventListener('load', onLoadListener)
31-
}, [iFrameElement.current, onLoadListener])
31+
return () => currentIFrame.removeEventListener('load', onLoadListener)
32+
}, [onLoadListener])
3233

3334
const style: Record<string, string | number> = {}
3435
if (content.dimensions) {

packages/webui/src/client/ui/PreviewPopUp/Previews/VTPreview.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ export function VTPreviewElement({ content, time }: VTPreviewProps): React.React
3636
const studioContext = useContext(StudioContext)
3737

3838
useEffect(() => {
39-
if (!videoElement.current) return
39+
// Create a stable reference to the video element:
40+
const currentVideoElement = videoElement.current
41+
if (!currentVideoElement) return
4042

4143
setVideoElementPosition(
42-
videoElement.current,
44+
currentVideoElement,
4345
time ?? 0,
4446
content.itemDuration ?? 0,
4547
content.seek ?? 0,
4648
content.loop ?? false
4749
)
48-
}, [videoElement.current, time])
50+
}, [time, content.itemDuration, content.seek, content.loop])
4951

5052
const itemDuration = content.itemDuration ?? 0
5153
const offsetTimePosition = (time ?? 0) + (content.seek ?? 0)

0 commit comments

Comments
 (0)