diff --git a/src/PageManager.tsx b/src/PageManager.tsx
index 47e29b55..126e3a42 100644
--- a/src/PageManager.tsx
+++ b/src/PageManager.tsx
@@ -6,6 +6,7 @@ import { RefreshButton } from '@/components/RefreshButton'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import logger from '@/lib/logger'
+import { preventRadixSheetCloseForPortaledOverlay } from '@/lib/sheet-dismiss-guard'
import { ChevronLeft } from 'lucide-react'
import { NavigationService } from '@/services/navigation.service'
// Page imports needed for primary note view
@@ -2254,6 +2255,8 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
side="right"
className="w-full sm:max-w-[1042px] overflow-y-auto p-0"
hideClose
+ onPointerDownOutside={(e) => preventRadixSheetCloseForPortaledOverlay(e)}
+ onInteractOutside={(e) => preventRadixSheetCloseForPortaledOverlay(e)}
>
{secondaryStack.map((item, index) => {
diff --git a/src/components/NoteDrawer/index.tsx b/src/components/NoteDrawer/index.tsx
index 56a93d1c..91a5339b 100644
--- a/src/components/NoteDrawer/index.tsx
+++ b/src/components/NoteDrawer/index.tsx
@@ -1,4 +1,5 @@
import { useState, useEffect, useRef } from 'react'
+import { preventRadixSheetCloseForPortaledOverlay } from '@/lib/sheet-dismiss-guard'
import { Sheet, SheetContent } from '@/components/ui/sheet'
import NotePage from '@/pages/secondary/NotePage'
import { useSecondaryPage } from '@/PageManager'
@@ -53,19 +54,8 @@ export default function NoteDrawer({ open, onOpenChange, noteId, initialEvent }:
side="right"
className="w-full sm:max-w-[1042px] overflow-y-auto p-0"
hideClose
- onPointerDownOutside={(e) => {
- // Prevent the drawer from closing when the user interacts with a lightbox portal.
- // The lightbox renders into document.body (outside the Sheet DOM) so Radix UI
- // would otherwise treat every click inside the lightbox as "outside" the drawer.
- if (document.body.classList.contains('yarl__no_scroll')) {
- e.preventDefault()
- }
- }}
- onInteractOutside={(e) => {
- if (document.body.classList.contains('yarl__no_scroll')) {
- e.preventDefault()
- }
- }}
+ onPointerDownOutside={(e) => preventRadixSheetCloseForPortaledOverlay(e)}
+ onInteractOutside={(e) => preventRadixSheetCloseForPortaledOverlay(e)}
>
void
+ detail?: { originalEvent?: Event }
+}
+
+function eventComposedPath(e: RadixOutsideEvent): EventTarget[] {
+ const orig = e.detail?.originalEvent
+ if (orig && typeof orig.composedPath === 'function') {
+ return orig.composedPath()
+ }
+ return []
+}
+
+export function preventRadixSheetCloseForPortaledOverlay(e: RadixOutsideEvent): void {
+ if (typeof document === 'undefined') return
+ if (document.body.classList.contains('yarl__no_scroll')) {
+ e.preventDefault()
+ return
+ }
+ const path = eventComposedPath(e)
+ const inBitcoinConnectModal = path.some(
+ (node) => node instanceof HTMLElement && node.tagName.toLowerCase() === 'bc-modal'
+ )
+ if (inBitcoinConnectModal) {
+ e.preventDefault()
+ }
+}