Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(ui): notification cards lift above a chat composer they would cover (#36233)

Neil6efdd36dcb4f
diff --git a/src/renderer/src/components/NotificationCardStack.test.tsx b/src/renderer/src/components/NotificationCardStack.test.tsx
index 11e4ad0c3a1..9368a57786d 100644
--- a/src/renderer/src/components/NotificationCardStack.test.tsx
+++ b/src/renderer/src/components/NotificationCardStack.test.tsx
@@ -1,9 +1,13 @@
// @vitest-environment happy-dom
-import { act } from 'react'
+import { act, useRef } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { NOTIFICATION_CARD_STACK_HEIGHT_VAR } from '@/lib/notification-card-stack-height'
+import {
+ NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR,
+ useNotificationCardComposerClearance
+} from '@/lib/notification-card-composer-clearance'
import { NotificationCardStack } from './NotificationCardStack'
let resize: (() => void) | null = null
@@ -12,6 +16,19 @@ let root: Root | null = null
const published = (): string =>
document.documentElement.style.getPropertyValue(NOTIFICATION_CARD_STACK_HEIGHT_VAR)
+const clearance = (): string =>
+ document.documentElement.style.getPropertyValue(NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR)
+
+type Box = { left: number; right: number; top: number; bottom: number }
+// happy-dom's viewport is 1024 x 768; the cards' column is x 648-1008 as at 1024 px in Orca.
+const CARD_COLUMN: Box = { left: 648, right: 1008, top: 0, bottom: 0 }
+const rects = new Map<string, Box>()
+
+function Composer({ id }: { id: string }): React.JSX.Element {
+ const ref = useRef<HTMLDivElement>(null)
+ useNotificationCardComposerClearance(ref, true)
+ return <div ref={ref} data-box={id} />
+}
beforeEach(() => {
height = 0
@@ -22,10 +39,22 @@ beforeEach(() => {
resize = callback
}
observe(): void {}
+ unobserve(): void {}
disconnect(): void {}
}
)
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(() => height)
+ rects.clear()
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
+ this: HTMLElement
+ ) {
+ const box = this.dataset.box ? rects.get(this.dataset.box) : CARD_COLUMN
+ return DOMRect.fromRect(
+ box
+ ? { x: box.left, y: box.top, width: box.right - box.left, height: box.bottom - box.top }
+ : {}
+ )
+ })
root = createRoot(document.body.appendChild(document.createElement('div')))
})
@@ -53,4 +82,44 @@ describe('NotificationCardStack', () => {
root = null
expect(published()).toBe('')
})
+
+ it('lifts the cards above a chat composer they would cover, and drops back when it goes', () => {
+ height = 120
+ rects.set('chat', { left: 300, right: 1010, top: 650, bottom: 740 })
+ act(() =>
+ root?.render(
+ <>
+ <Composer id="chat" />
+ <NotificationCardStack>card</NotificationCardStack>
+ </>
+ )
+ )
+ expect(clearance()).toBe('calc(118px + 0.5rem)')
+
+ act(() => root?.render(<NotificationCardStack>card</NotificationCardStack>))
+ expect(clearance()).toBe('')
+ })
+
+ it('leaves the cards in place for composers beside them, above them, hidden, or with no cards', () => {
+ height = 120
+ rects.set('beside', { left: 0, right: 600, top: 650, bottom: 740 })
+ rects.set('above', { left: 300, right: 1010, top: 300, bottom: 400 })
+ rects.set('hidden', { left: 0, right: 0, top: 0, bottom: 0 })
+ act(() =>
+ root?.render(
+ <>
+ <Composer id="beside" />
+ <Composer id="above" />
+ <Composer id="hidden" />
+ <NotificationCardStack>card</NotificationCardStack>
+ </>
+ )
+ )
+ expect(clearance()).toBe('')
+
+ rects.set('beside', { left: 300, right: 1010, top: 650, bottom: 740 })
+ height = 0
+ act(() => resize?.())
+ expect(clearance()).toBe('')
+ })
})
diff --git a/src/renderer/src/components/NotificationCardStack.tsx b/src/renderer/src/components/NotificationCardStack.tsx
index 3349170ac2f..573e3027628 100644
--- a/src/renderer/src/components/NotificationCardStack.tsx
+++ b/src/renderer/src/components/NotificationCardStack.tsx
@@ -1,5 +1,16 @@
import { useEffect, useRef, type ReactNode } from 'react'
import { NOTIFICATION_CARD_STACK_HEIGHT_VAR } from '@/lib/notification-card-stack-height'
+import {
+ measureComposerClearance,
+ NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR,
+ NOTIFICATION_CARD_STACK_BOTTOM,
+ subscribeToComposerLayout
+} from '@/lib/notification-card-composer-clearance'
+
+const STACK_STYLE = {
+ bottom: NOTIFICATION_CARD_STACK_BOTTOM,
+ maxHeight: `calc(100vh - 2.5rem - ${NOTIFICATION_CARD_STACK_BOTTOM})`
+}
export function NotificationCardStack({ children }: { children: ReactNode }): React.JSX.Element {
const stackRef = useRef<HTMLDivElement>(null)
@@ -13,25 +24,49 @@ export function NotificationCardStack({ children }: { children: ReactNode }): Re
// Why publish: toasts share this corner and would otherwise render behind the cards (z-50).
const publish = (): void => {
const height = stack.offsetHeight
+ // Why clear a composer: with the right sidebar closed the cards cover its Send and Stop.
+ const restingBottom = 2.5 * Number.parseFloat(getComputedStyle(root).fontSize)
+ const clearance =
+ height > 0
+ ? measureComposerClearance(
+ stack.getBoundingClientRect(),
+ window.innerHeight - restingBottom - height,
+ window.innerHeight
+ )
+ : 0
if (height > 0) {
root.style.setProperty(NOTIFICATION_CARD_STACK_HEIGHT_VAR, `calc(${height}px + 0.5rem)`)
} else {
root.style.removeProperty(NOTIFICATION_CARD_STACK_HEIGHT_VAR)
}
+ if (clearance > 0) {
+ root.style.setProperty(
+ NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR,
+ `calc(${clearance}px + 0.5rem)`
+ )
+ } else {
+ root.style.removeProperty(NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR)
+ }
}
publish()
const observer = new ResizeObserver(publish)
observer.observe(stack)
+ const unsubscribe = subscribeToComposerLayout(publish)
+ window.addEventListener('resize', publish)
return () => {
observer.disconnect()
+ unsubscribe()
+ window.removeEventListener('resize', publish)
root.style.removeProperty(NOTIFICATION_CARD_STACK_HEIGHT_VAR)
+ root.style.removeProperty(NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR)
}
}, [])
return (
<div
ref={stackRef}
- className="pointer-events-none fixed bottom-10 right-4 z-50 flex max-h-[calc(100vh-80px)] w-[360px] max-w-[calc(100vw-32px)] flex-col-reverse gap-2 overflow-y-auto scrollbar-sleek [&>*]:pointer-events-auto [&>*]:shrink-0 max-[480px]:left-4 max-[480px]:right-4 max-[480px]:w-auto"
+ style={STACK_STYLE}
+ className="pointer-events-none fixed right-4 z-50 flex w-[360px] max-w-[calc(100vw-32px)] flex-col-reverse gap-2 overflow-y-auto scrollbar-sleek [&>*]:pointer-events-auto [&>*]:shrink-0 max-[480px]:left-4 max-[480px]:right-4 max-[480px]:w-auto"
>
{children}
</div>
diff --git a/src/renderer/src/components/native-chat/NativeChatComposerPane.tsx b/src/renderer/src/components/native-chat/NativeChatComposerPane.tsx
index 2f9bb971cb8..a15be97c3cb 100644
--- a/src/renderer/src/components/native-chat/NativeChatComposerPane.tsx
+++ b/src/renderer/src/components/native-chat/NativeChatComposerPane.tsx
@@ -29,6 +29,7 @@ import { useImeEnterGestureOwnership } from '@/lib/ime-composition-keyboard-even
import { useNativeChatComposerAppMenuSelection } from './use-native-chat-composer-app-menu-selection'
import { useNativeChatComposerSubmit } from './use-native-chat-composer-submit'
import { useNativeChatComposerCommandPicker } from './use-native-chat-composer-command-picker'
+import { useNotificationCardComposerClearance } from '@/lib/notification-card-composer-clearance'
/** Send through the chat’s structured transport or verified PTY route, with agent-aware autocomplete and image handling. */
export const NativeChatComposerPane = forwardRef<NativeChatComposerHandle, NativeChatComposerProps>(
@@ -192,6 +193,7 @@ export const NativeChatComposerPane = forwardRef<NativeChatComposerHandle, Nativ
const localHandle = useRef<NativeChatComposerHandle>(null)
const root = useRef<HTMLDivElement>(null)
+ useNotificationCardComposerClearance(root, editSession === undefined)
const handlePasteEvent = useNativeChatComposerHandle(localHandle, {
attachmentScopeKey: draftScopeKey,
textareaRef,
diff --git a/src/renderer/src/components/ui/sonner.tsx b/src/renderer/src/components/ui/sonner.tsx
index fe9d346c452..7f3bbe275b2 100644
--- a/src/renderer/src/components/ui/sonner.tsx
+++ b/src/renderer/src/components/ui/sonner.tsx
@@ -10,6 +10,7 @@ import { Toaster as Sonner, type ToasterProps } from 'sonner'
import { useAppStore } from '@/store'
import { MODAL_OVERLAY_CHILD_SELECTOR } from '@/lib/body-overlay-attributes'
import { NOTIFICATION_CARD_STACK_HEIGHT_VAR } from '@/lib/notification-card-stack-height'
+import { NOTIFICATION_CARD_STACK_BOTTOM } from '@/lib/notification-card-composer-clearance'
// Why: a short outcome reads best with its action beside it; the toaster's default wraps actions below.
export const INLINE_ACTION_CLASS_NAMES = {
@@ -36,7 +37,7 @@ function blockModalToastInteraction(event: SyntheticEvent): void {
}
const TOASTER_OFFSET = {
- bottom: `calc(2.5rem + env(safe-area-inset-bottom, 0px) + var(${NOTIFICATION_CARD_STACK_HEIGHT_VAR}, 0px))`,
+ bottom: `calc(${NOTIFICATION_CARD_STACK_BOTTOM} + env(safe-area-inset-bottom, 0px) + var(${NOTIFICATION_CARD_STACK_HEIGHT_VAR}, 0px))`,
// Why 1rem: the cards' right edge, so a toast above them lines up instead of jutting left.
right: '1rem'
}
diff --git a/src/renderer/src/lib/notification-card-composer-clearance.ts b/src/renderer/src/lib/notification-card-composer-clearance.ts
new file mode 100644
index 00000000000..6f0afd7d3a3
--- /dev/null
+++ b/src/renderer/src/lib/notification-card-composer-clearance.ts
@@ -0,0 +1,77 @@
+import { useEffect, type RefObject } from 'react'
+
+/** How far above the viewport bottom the cards must sit to clear a chat composer, unset otherwise. */
+export const NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR = '--notification-card-composer-clearance'
+
+/** The cards' bottom offset: their usual 2.5rem, or above a composer they would cover. */
+export const NOTIFICATION_CARD_STACK_BOTTOM = `max(2.5rem, var(${NOTIFICATION_CARD_COMPOSER_CLEARANCE_VAR}, 0px))`
+
+const composers = new Set<HTMLElement>()
+const listeners = new Set<() => void>()
+let composerResizes: ResizeObserver | null = null
+
+function notifyListeners(): void {
+ for (const listener of listeners) {
+ listener()
+ }
+}
+
+function registerComposer(composer: HTMLElement): () => void {
+ composers.add(composer)
+ composerResizes ??= new ResizeObserver(notifyListeners)
+ composerResizes.observe(composer)
+ notifyListeners()
+ return () => {
+ composers.delete(composer)
+ composerResizes?.unobserve(composer)
+ notifyListeners()
+ }
+}
+
+/** Re-measure when a composer mounts, unmounts or resizes (a sidebar toggle resizes it). */
+export function subscribeToComposerLayout(listener: () => void): () => void {
+ listeners.add(listener)
+ return () => {
+ listeners.delete(listener)
+ }
+}
+
+/**
+ * Px between the viewport bottom and the top of the highest composer the cards would cover where
+ * they normally rest (`restingTop` down), so a lifted stack never re-measures against its own lift.
+ */
+export function measureComposerClearance(
+ column: { left: number; right: number },
+ restingTop: number,
+ viewportHeight: number
+): number {
+ let clearance = 0
+ for (const composer of composers) {
+ const rect = composer.getBoundingClientRect()
+ // Zero size: the composer's tab is hidden.
+ if (
+ rect.width === 0 ||
+ rect.right <= column.left ||
+ rect.left >= column.right ||
+ rect.bottom <= restingTop
+ ) {
+ continue
+ }
+ clearance = Math.max(clearance, viewportHeight - rect.top)
+ }
+ return clearance
+}
+
+/** Keeps the notification cards off this composer's Send and Stop buttons. */
+export function useNotificationCardComposerClearance(
+ composerRef: RefObject<HTMLElement | null>,
+ enabled: boolean
+): void {
+ useEffect(() => {
+ const composer = composerRef.current
+ if (!enabled || !composer) {
+ return
+ }
+ return registerComposer(composer)
+ }, [composerRef, enabled])
+}