Skip to content

Commit

Permalink
fix: Remove abort controller from use-pointer-events, because it even…
Browse files Browse the repository at this point in the history
…ts listeners are attached to specific instances
  • Loading branch information
georgylobko committed Jan 20, 2025
1 parent 2752401 commit 8491531
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/app-layout/utils/use-pointer-events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { useCallback, useRef } from 'react';
import { useCallback } from 'react';

import {
getIsRtl,
Expand All @@ -13,8 +13,6 @@ import { SizeControlProps } from './interfaces';
import styles from '../resize/styles.css.js';

export const usePointerEvents = ({ position, panelRef, handleRef, onResize }: SizeControlProps) => {
const controller = useRef(new AbortController());

const onDocumentPointerMove = useCallback(
(event: PointerEvent) => {
if (!panelRef || !panelRef.current || !handleRef || !handleRef.current) {
Expand Down Expand Up @@ -52,8 +50,9 @@ export const usePointerEvents = ({ position, panelRef, handleRef, onResize }: Si

currentDocument.body.classList.remove(styles['resize-active']);
currentDocument.body.classList.remove(styles[`resize-${position}`]);
controller.current.abort();
}, [panelRef, position]);
currentDocument.removeEventListener('pointerup', onDocumentPointerUp);
currentDocument.removeEventListener('pointermove', onDocumentPointerMove);
}, [panelRef, onDocumentPointerMove, position]);

const onSliderPointerDown = useCallback(() => {
const panelElement = panelRef?.current;
Expand All @@ -64,8 +63,8 @@ export const usePointerEvents = ({ position, panelRef, handleRef, onResize }: Si
const currentDocument = panelElement.ownerDocument;
currentDocument.body.classList.add(styles['resize-active']);
currentDocument.body.classList.add(styles[`resize-${position}`]);
currentDocument.addEventListener('pointerup', onDocumentPointerUp, { signal: controller.current.signal });
currentDocument.addEventListener('pointermove', onDocumentPointerMove, { signal: controller.current.signal });
currentDocument.addEventListener('pointerup', onDocumentPointerUp);
currentDocument.addEventListener('pointermove', onDocumentPointerMove);
}, [panelRef, onDocumentPointerMove, onDocumentPointerUp, position]);

return onSliderPointerDown;
Expand Down

0 comments on commit 8491531

Please sign in to comment.