Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): keep toasts dismissable under modal dialogs and sheets (#2387)
sarah51b7bd56f741
diff --git a/.changeset/toast-dismiss-under-modal-dialog.md b/.changeset/toast-dismiss-under-modal-dialog.mdnew file mode 100644index 000000000..4981115bc--- /dev/null+++ b/.changeset/toast-dismiss-under-modal-dialog.md@@ -0,0 +1,11 @@+---+"@inkeep/open-knowledge": patch+---++Fix toasts becoming un-dismissable and covering controls while a modal dialog or+sheet is open. Sonner renders its toaster in a portal on `<body>`, and a modal+Radix layer sets `body { pointer-events: none }`, which the toast inherited, so+it painted on top of the dialog but its close/action buttons were click-dead+(the "Added ok to your PATH" onboarding toast was the visible case). Toasts are+now kept interactive under a modal layer, and dismissing a toast no longer closes+the dialog or sheet beneath it.diff --git a/packages/app/src/components/ui/dialog.tsx b/packages/app/src/components/ui/dialog.tsxindex f4bf7231d..c6f901e1e 100644--- a/packages/app/src/components/ui/dialog.tsx+++ b/packages/app/src/components/ui/dialog.tsx@@ -3,6 +3,7 @@ import { XIcon } from 'lucide-react';import { Dialog as DialogPrimitive } from 'radix-ui';import type * as React from 'react';import { Button } from '@/components/ui/button';+import { ignoreToastInteractOutside } from '@/components/ui/toast-outside-guard';import { cn } from '@/lib/utils';function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) {@@ -43,6 +44,7 @@ function DialogContent({className,children,showCloseButton = true,+ onInteractOutside,...props}: React.ComponentProps<typeof DialogPrimitive.Content> & {showCloseButton?: boolean;@@ -52,6 +54,7 @@ function DialogContent({<DialogOverlay /><DialogPrimitive.Contentdata-slot="dialog-content"+ onInteractOutside={ignoreToastInteractOutside(onInteractOutside)}className={cn('fixed top-1/2 left-1/2 z-50 flex w-full max-w-[calc(100%-2rem)] max-h-[calc(100dvh-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-6 overflow-hidden rounded-xl bg-popover p-6 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm [-webkit-app-region:no-drag] data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 motion-reduce:data-open:animate-none motion-reduce:data-closed:animate-none motion-reduce:duration-0',className,diff --git a/packages/app/src/components/ui/sheet.tsx b/packages/app/src/components/ui/sheet.tsxindex d0b17b0d2..7f8cd1ce5 100644--- a/packages/app/src/components/ui/sheet.tsx+++ b/packages/app/src/components/ui/sheet.tsx@@ -5,6 +5,7 @@ import { XIcon } from 'lucide-react';import { Dialog as SheetPrimitive } from 'radix-ui';import type * as React from 'react';import { Button } from '@/components/ui/button';+import { ignoreToastInteractOutside } from '@/components/ui/toast-outside-guard';import { cn } from '@/lib/utils';function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {@@ -44,6 +45,7 @@ function SheetContent({children,side = 'right',showCloseButton = true,+ onInteractOutside,...props}: React.ComponentProps<typeof SheetPrimitive.Content> & {side?: 'top' | 'right' | 'bottom' | 'left';@@ -55,6 +57,7 @@ function SheetContent({<SheetPrimitive.Contentdata-slot="sheet-content"data-side={side}+ onInteractOutside={ignoreToastInteractOutside(onInteractOutside)}className={cn('fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10 motion-reduce:transition-none motion-reduce:duration-0 motion-reduce:data-open:animate-none motion-reduce:data-closed:animate-none',className,diff --git a/packages/app/src/components/ui/toast-outside-guard.test.ts b/packages/app/src/components/ui/toast-outside-guard.test.tsnew file mode 100644index 000000000..c127fd7af--- /dev/null+++ b/packages/app/src/components/ui/toast-outside-guard.test.ts@@ -0,0 +1,53 @@+import { describe, expect, mock, test } from 'bun:test';+import { ignoreToastInteractOutside } from './toast-outside-guard';++type GuardEvent = Parameters<ReturnType<typeof ignoreToastInteractOutside>>[0];++function makeEvent(insideToaster: boolean) {+ const preventDefault = mock(() => {});+ const event = {+ target: {+ closest: (selector: string) =>+ insideToaster && selector === '[data-sonner-toaster]' ? ({} as Element) : null,+ },+ preventDefault,+ } as unknown as GuardEvent;+ return { event, preventDefault };+}++describe('ignoreToastInteractOutside', () => {+ test('interaction inside the toaster is neutralized and does not reach the consumer', () => {+ const consumer = mock(() => {});+ const { event, preventDefault } = makeEvent(true);++ ignoreToastInteractOutside(consumer)(event);++ expect(preventDefault).toHaveBeenCalledTimes(1);+ expect(consumer).not.toHaveBeenCalled();+ });++ test('interaction outside the toaster falls through to the consumer untouched', () => {+ const consumer = mock(() => {});+ const { event, preventDefault } = makeEvent(false);++ ignoreToastInteractOutside(consumer)(event);++ expect(preventDefault).not.toHaveBeenCalled();+ expect(consumer).toHaveBeenCalledTimes(1);+ expect(consumer).toHaveBeenCalledWith(event);+ });++ test('a toast interaction with no consumer still prevents dismissal without throwing', () => {+ const { event, preventDefault } = makeEvent(true);++ expect(() => ignoreToastInteractOutside()(event)).not.toThrow();+ expect(preventDefault).toHaveBeenCalledTimes(1);+ });++ test('a non-toast interaction with no consumer is a no-op without throwing', () => {+ const { event, preventDefault } = makeEvent(false);++ expect(() => ignoreToastInteractOutside()(event)).not.toThrow();+ expect(preventDefault).not.toHaveBeenCalled();+ });+});diff --git a/packages/app/src/components/ui/toast-outside-guard.ts b/packages/app/src/components/ui/toast-outside-guard.tsnew file mode 100644index 000000000..ba6c82915--- /dev/null+++ b/packages/app/src/components/ui/toast-outside-guard.ts@@ -0,0 +1,19 @@+import type { Dialog as DialogPrimitive } from 'radix-ui';+import type * as React from 'react';++type InteractOutsideHandler = NonNullable<+ React.ComponentProps<typeof DialogPrimitive.Content>['onInteractOutside']+>;++export function ignoreToastInteractOutside(+ onInteractOutside?: InteractOutsideHandler,+): InteractOutsideHandler {+ return (event) => {+ const target = event.target as HTMLElement | null;+ if (target?.closest('[data-sonner-toaster]')) {+ event.preventDefault();+ return;+ }+ onInteractOutside?.(event);+ };+}diff --git a/packages/app/src/globals.css b/packages/app/src/globals.cssindex cafa2c797..5bc95765a 100644--- a/packages/app/src/globals.css+++ b/packages/app/src/globals.css@@ -5100,3 +5100,19 @@ html.electron-mode [data-slot="sidebar-inner"] {object-fit: cover;display: block;}++/* Sonner toast interactivity under a modal Radix layer.+ sonner@2 renders its toaster via appendChild onto <body> and never sets+ pointer-events: auto on the toaster/toasts (its only pointer-events rule+ is `none` on hidden toasts). When a modal Radix layer is open (Dialog /+ Sheet / any DismissableLayer with disableOutsidePointerEvents) it+ sets `body { pointer-events: none }`, which the toast then inherits — so a+ toast paints on top (z-index 999999999) but its close/action buttons are+ click-dead. Re-enable pointer events on each toast, and keep the toaster+ gutter click-through so it doesn't swallow clicks meant for UI beneath it. */+[data-sonner-toaster] {+ pointer-events: none;+}+[data-sonner-toast] {+ pointer-events: auto;+}