Skip to content

Commit 0da47dd

Browse files
committed
Also fix possible race condition
1 parent fbe410a commit 0da47dd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/design-system/src/components/primitives/numeric-gesture-control.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ const requestPointerLock = (
439439
};
440440
});
441441

442+
let isDisposed = false;
443+
disposeOnCleanup(() => () => {
444+
isDisposed = true;
445+
});
446+
442447
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
443448

444449
// Safari supports pointer lock well, but the issue lies with the pointer lock banner.
@@ -450,6 +455,14 @@ const requestPointerLock = (
450455
requestPointerLockSafe(targetNode)
451456
.then(() => {
452457
state.pointerCaptureRequested = false;
458+
459+
if (isDisposed) {
460+
if (targetNode.ownerDocument.pointerLockElement === targetNode) {
461+
targetNode.ownerDocument.exitPointerLock();
462+
}
463+
return;
464+
}
465+
453466
const cursorNode =
454467
(targetNode.ownerDocument.querySelector(
455468
"#numeric-guesture-control-cursor"

0 commit comments

Comments
 (0)