Skip to content

Commit

Permalink
fix: clean up dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Aug 21, 2023
1 parent a80ea56 commit 9863ae0
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions shell/src/PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,20 @@ const PluginInner = ({
const divRef = useRef()
const innerDivRef = useRef()
useEffect(() => {
if (
divRef &&
divRef.current &&
(resizePluginHeight || resizePluginWidth)
) {
if (divRef && divRef.current && resizePluginHeight) {
const resizeObserver = new ResizeObserver(() => {
console.log(
'height,scrollHeight,offsetWidth,scrollWidth',
divRef.current.offsetHeight,
divRef.current.scrollHeight,
divRef.current.offsetWidth,
divRef.current.scrollWidth
)
// the additional pixels currently account for possible horizontal scroll bar
if (resizePluginHeight) {
resizePluginHeight(divRef.current.offsetHeight + 20)
}
})
resizeObserver.observe(divRef.current)
}
}, [])
}, [resizePluginHeight])

let previousWidth

const resetWidth = () => {
const resetWidth = useCallback(() => {
const currentWidth = innerDivRef.current?.scrollWidth
if (resizePluginWidth && currentWidth) {
if (previousWidth && Math.abs(currentWidth - previousWidth) > 20) {
Expand All @@ -47,11 +36,13 @@ const PluginInner = ({
previousWidth = currentWidth
}
requestAnimationFrame(resetWidth)
}
}, [resizePluginWidth])

useEffect(() => {
requestAnimationFrame(resetWidth)
}, [])
if (resizePluginWidth) {
requestAnimationFrame(resetWidth)
}
}, [resetWidth, resizePluginWidth])

// inner div disables margin collapsing which would prevent computing correct height
return (
Expand Down

0 comments on commit 9863ae0

Please sign in to comment.