Skip to content

Commit 11c0f41

Browse files
committed
fix: 🐛 Performance and regression
1 parent 2777107 commit 11c0f41

4 files changed

Lines changed: 10 additions & 21 deletions

File tree

src/components/transform-component/transform-component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const TransformComponent: React.FC<Props> = ({
2424
wrapperProps = {},
2525
contentProps = {},
2626
}: Props) => {
27-
const { init } = useContext(Context);
27+
const { init, cleanupWindowEvents } = useContext(Context);
2828

2929
const wrapperRef = useRef<HTMLDivElement | null>(null);
3030
const contentRef = useRef<HTMLDivElement | null>(null);
@@ -33,9 +33,12 @@ export const TransformComponent: React.FC<Props> = ({
3333
const wrapper = wrapperRef.current;
3434
const content = contentRef.current;
3535
if (wrapper !== null && content !== null && init) {
36-
init(wrapper, content);
36+
init?.(wrapper, content);
3737
}
3838
// eslint-disable-next-line react-hooks/exhaustive-deps
39+
return () => {
40+
cleanupWindowEvents?.();
41+
};
3942
}, []);
4043

4144
return (

src/components/transform-wrapper/transform-wrapper.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export const TransformWrapper = React.forwardRef(
3232

3333
useEffect(() => {
3434
instance.update(props);
35-
return () => {
36-
instance.cleanupWindowEvents();
37-
};
3835
}, [instance, props]);
3936

4037
return <Context.Provider value={instance}>{content}</Context.Provider>;

src/core/bounds/bounds.utils.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,15 @@ export function getMouseBoundedPosition(
170170
paddingY = paddingValueY;
171171
}
172172

173-
const rubberbandX = rubberbandIfOutOfBounds(
174-
positionX,
175-
minPositionX,
176-
maxPositionX,
177-
);
178-
const rubberbandY = rubberbandIfOutOfBounds(
179-
positionY,
180-
minPositionY,
181-
maxPositionY,
182-
);
183-
184173
const x = boundLimiter(
185-
rubberbandX,
174+
positionX,
186175
minPositionX - paddingX,
187176
maxPositionX + paddingX,
188177
limitToBounds,
189178
);
190179

191180
const y = boundLimiter(
192-
rubberbandY,
181+
positionY,
193182
minPositionY - paddingY,
194183
maxPositionY + paddingY,
195184
limitToBounds,

src/core/instance.core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ export class ZoomPanPinch {
208208
const keysPressed = this.isPressingKeys(this.setup.panning.activationKeys);
209209
if (!keysPressed) return;
210210

211-
if(event.button == 0 && !this.setup.panning.allowLeftClickPan) return;
212-
if(event.button == 1 && !this.setup.panning.allowMiddleClickPan) return;
213-
if(event.button == 2 && !this.setup.panning.allowRightClickPan) return;
211+
if (event.button === 0 && !this.setup.panning.allowLeftClickPan) return;
212+
if (event.button === 1 && !this.setup.panning.allowMiddleClickPan) return;
213+
if (event.button === 2 && !this.setup.panning.allowRightClickPan) return;
214214

215215
event.preventDefault();
216216
event.stopPropagation();

0 commit comments

Comments
 (0)