Skip to content

Commit e11e87a

Browse files
authored
[backport] fix: error overlay not closing when backdrop clicked (#83981) (#83992)
Backports #83981
1 parent 0a29888 commit e11e87a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

packages/next/src/next-devtools/dev-overlay/components/dialog/dialog.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const Dialog: React.FC<DialogProps> = function Dialog({
3737
)
3838

3939
useOnClickOutside(
40-
// eslint-disable-next-line react-hooks/react-compiler -- TODO
41-
dialogRef.current,
40+
dialogRef,
4241
CSS_SELECTORS_TO_EXCLUDE_ON_CLICK_OUTSIDE,
4342
(e) => {
4443
e.preventDefault()

packages/next/src/next-devtools/dev-overlay/hooks/use-on-click-outside.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import * as React from 'react'
22

33
export function useOnClickOutside(
4-
el: Node | null,
4+
el: Node | React.RefObject<Node | null> | null,
55
cssSelectorsToExclude: string[],
66
handler: ((e: MouseEvent | TouchEvent) => void) | undefined
77
) {
88
React.useEffect(() => {
9-
if (el == null || handler == null) {
9+
// Support both direct nodes and ref objects
10+
const element = el && 'current' in el ? el.current : el
11+
if (element == null || handler == null) {
1012
return
1113
}
1214

1315
const listener = (e: MouseEvent | TouchEvent) => {
1416
// Do nothing if clicking ref's element or descendent elements
15-
if (!el || el.contains(e.target as Element)) {
17+
if (!element || element.contains(e.target as Element)) {
1618
return
1719
}
1820

@@ -28,7 +30,7 @@ export function useOnClickOutside(
2830
handler(e)
2931
}
3032

31-
const root = el.getRootNode()
33+
const root = element.getRootNode()
3234
root.addEventListener('mouseup', listener as EventListener)
3335
root.addEventListener('touchend', listener as EventListener, {
3436
passive: false,

0 commit comments

Comments
 (0)