Skip to content

Commit bffb157

Browse files
committed
fix(webui): More fixes [copilot]
1 parent 2ba1f1a commit bffb157

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

packages/webui/src/client/lib/SplitDropdown.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export class SplitDropdown extends React.Component<IProps, IState> {
4242
}
4343
}
4444

45+
componentWillUnmount(): void {
46+
this._popperRef = null
47+
this._popperUpdate = undefined
48+
}
49+
4550
private toggleExpco = async (e: React.MouseEvent<HTMLElement>) => {
4651
e.preventDefault()
4752
e.stopPropagation()

packages/webui/src/client/ui/SegmentList/LinePartPieceIndicator/LinePartIndicator.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export function LinePartIndicator({
4949
)
5050
return
5151
setIsMenuOpen(false)
52-
window.removeEventListener('mousedown', onClickAway)
5352
},
5453
[element]
5554
)
@@ -58,14 +57,16 @@ export function LinePartIndicator({
5857
const shouldBeOpen = !isMenuOpen
5958
setIsMenuOpen(shouldBeOpen)
6059
onClickExternal?.(e)
61-
window.addEventListener('mousedown', onClickAway)
6260
}
6361

6462
useEffect(() => {
63+
if (!isMenuOpen) return
64+
window.addEventListener('mousedown', onClickAway)
65+
6566
return () => {
6667
window.removeEventListener('mousedown', onClickAway)
6768
}
68-
}, [onClickAway])
69+
}, [isMenuOpen, onClickAway])
6970

7071
return (
7172
<>

packages/webui/src/client/ui/SegmentList/LinePartPieceIndicator/PieceIndicatorMenu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function PieceIndicatorMenu({
3131
}, [pieces.length])
3232

3333
useEffect(() => {
34-
if (!indicatorMenuEl) return
34+
if (!indicatorMenuEl || !indicatorMenuEl.isConnected) return
3535

3636
let timeout: NodeJS.Timeout | undefined = undefined
3737

@@ -55,7 +55,7 @@ export function PieceIndicatorMenu({
5555
indicatorMenuEl.removeEventListener('mouseenter', onMouseEnter)
5656
indicatorMenuEl.removeEventListener('mouseleave', onMouseLeave)
5757
}
58-
}, [indicatorMenuEl])
58+
}, [indicatorMenuEl, setIsOver])
5959

6060
useLayoutEffect(() => {
6161
if (!indicatorMenuEl) return
@@ -78,7 +78,7 @@ export function PieceIndicatorMenu({
7878
<div
7979
className="segment-opl__piece-indicator-menu"
8080
/** This is so that we avoid updating the state once the component has been unmounted */
81-
ref={(el) => el !== null && setIndicatorMenuEl(el)}
81+
ref={setIndicatorMenuEl}
8282
style={styles.popper}
8383
{...attributes.popper}
8484
>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,22 @@ const SegmentListInner = React.forwardRef<HTMLDivElement, IProps>(function Segme
195195
return
196196
}
197197

198-
const partEl = combinedRef.current.querySelector('.segment-opl__part')
198+
const segmentEl = combinedRef.current
199+
const partEl = segmentEl.querySelector('.segment-opl__part')
199200
if (!partEl) return
200201

201-
const { top, height } = combinedRef.current.getBoundingClientRect()
202+
const { top, height } = segmentEl.getBoundingClientRect()
202203
const absoluteTop = top + window.scrollY
203204
const { height: partHeight } = partEl.getBoundingClientRect()
205+
const threshold = absoluteTop + height - getHeaderHeight() - partHeight * 2 - 10
204206

205207
function onScroll() {
206-
if (window.scrollY > absoluteTop + height - getHeaderHeight() - partHeight * 2 - 10) {
208+
if (!segmentEl.isConnected) {
209+
setHeaderDetachedStick(false)
210+
return
211+
}
212+
213+
if (window.scrollY > threshold) {
207214
setHeaderDetachedStick(true)
208215
} else {
209216
setHeaderDetachedStick(false)

0 commit comments

Comments
 (0)