File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
- import { useEffect } from "react" ;
2
1
import { sendGTMEvent } from "@next/third-parties/google" ;
2
+ import { useEffect } from "react" ;
3
3
4
4
type KeyboardKey = KeyboardEvent [ "key" ] ;
5
5
@@ -28,7 +28,7 @@ export function useGlobalKeyCallback() {
28
28
if ( ! ( lowerKey in allHandlersStacks ) ) return ;
29
29
if ( shouldHandleAsNativeEvent ( event ) ) return ;
30
30
const handlersStack = allHandlersStacks [ lowerKey ] ;
31
- for ( let handler of handlersStack . reverse ( ) ) {
31
+ for ( let handler of [ ... handlersStack ] . reverse ( ) ) {
32
32
if ( handler ( ) ) {
33
33
event . preventDefault ( ) ;
34
34
event . stopPropagation ( ) ;
@@ -63,7 +63,9 @@ export const useCallbackOnKey = ({
63
63
return ( ) => {
64
64
if ( ! isDisabled ) {
65
65
const index = allHandlersStacks [ lowerKey ] . indexOf ( handler ) ;
66
- allHandlersStacks [ lowerKey ] . splice ( index , 1 ) ;
66
+ if ( index > - 1 ) {
67
+ allHandlersStacks [ lowerKey ] . splice ( index , 1 ) ;
68
+ }
67
69
}
68
70
} ;
69
71
} , [ key , handler , isDisabled ] ) ;
You can’t perform that action at this time.
0 commit comments