feat: memoize highlighter rect calc

This commit is contained in:
Rohit
2025-06-12 14:15:57 +05:30
parent 50575d90e7
commit 7c5f88cf0e

View File

@@ -1,4 +1,4 @@
import React from 'react'; import React, { useMemo } from 'react';
import styled from "styled-components"; import styled from "styled-components";
import { coordinateMapper } from '../../helpers/coordinateMapper'; import { coordinateMapper } from '../../helpers/coordinateMapper';
@@ -14,16 +14,15 @@ const HighlighterComponent = ({ unmodifiedRect, displayedSelector = '', width, h
if (!unmodifiedRect) { if (!unmodifiedRect) {
return null; return null;
} else { } else {
const mappedRect = coordinateMapper.mapBrowserRectToCanvas(unmodifiedRect); const rect = useMemo(() => {
const mappedRect = coordinateMapper.mapBrowserRectToCanvas(unmodifiedRect);
const rect = { return {
top: mappedRect.top + canvasRect.top + window.scrollY, top: mappedRect.top + canvasRect.top + window.scrollY,
left: mappedRect.left + canvasRect.left + window.scrollX, left: mappedRect.left + canvasRect.left + window.scrollX,
right: mappedRect.right + canvasRect.left, width: mappedRect.width,
bottom: mappedRect.bottom + canvasRect.top, height: mappedRect.height,
width: mappedRect.width, };
height: mappedRect.height, }, [unmodifiedRect, canvasRect.top, canvasRect.left]);
};
return ( return (