mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-26 10:40:08 +02:00
Debounce position updates in review panel for improved performance (#23190)
* Debounce position updates in review panel for improved performance * move debounce inside useMemo * move 'review-panel:position' inside debounce GitOrigin-RevId: 2b2d0e59537875f85036b0105ccb1a7d2035c0de
This commit is contained in:
committed by
Copybot
parent
d9a32a8dca
commit
2ef13e93be
@@ -32,6 +32,7 @@ import { reviewTooltipStateField } from '@/features/source-editor/extensions/rev
|
||||
import ReviewPanelMoreCommentsButton from './review-panel-more-comments-button'
|
||||
import useMoreCommments from '../hooks/use-more-comments'
|
||||
import { Decoration } from '@codemirror/view'
|
||||
import { debounce } from 'lodash'
|
||||
|
||||
type AggregatedRanges = {
|
||||
changes: Change<EditOperation>[]
|
||||
@@ -116,6 +117,19 @@ const ReviewPanelCurrentFile: FC = () => {
|
||||
false
|
||||
)?.addCommentRanges
|
||||
|
||||
const setUpdatedPositions = useMemo(
|
||||
() =>
|
||||
debounce(() => {
|
||||
setPositions(new Map(positionsRef.current))
|
||||
window.setTimeout(() => {
|
||||
containerRef.current?.dispatchEvent(
|
||||
new Event('review-panel:position')
|
||||
)
|
||||
})
|
||||
}, 50),
|
||||
[]
|
||||
)
|
||||
|
||||
const positionsMeasureRequest = useCallback(() => {
|
||||
if (aggregatedRanges) {
|
||||
view.requestMeasure({
|
||||
@@ -166,16 +180,11 @@ const ReviewPanelCurrentFile: FC = () => {
|
||||
}
|
||||
},
|
||||
write() {
|
||||
setPositions(new Map(positionsRef.current))
|
||||
window.setTimeout(() => {
|
||||
containerRef.current?.dispatchEvent(
|
||||
new Event('review-panel:position')
|
||||
)
|
||||
})
|
||||
setUpdatedPositions()
|
||||
},
|
||||
})
|
||||
}
|
||||
}, [view, aggregatedRanges, addCommentRanges])
|
||||
}, [view, aggregatedRanges, addCommentRanges, setUpdatedPositions])
|
||||
|
||||
useEffect(positionsMeasureRequest, [positionsMeasureRequest])
|
||||
useEventListener('editor:geometry-change', positionsMeasureRequest)
|
||||
|
||||
Reference in New Issue
Block a user