The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): clip tooltips against the nearest tree-group that has layout
teknium18c60b84a6b08
diff --git a/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsxindex 04c32bc2c1a..94a04aefa87 100644--- a/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx+++ b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx@@ -1,47 +1,62 @@import { cleanup, fireEvent, render, screen } from '@testing-library/react'-import { afterEach, describe, expect, it, vi } from 'vitest'+import { afterEach, expect, it, vi } from 'vitest'import { RootTooltipProvider, Tip } from './tooltip'-const zeroRect = (): DOMRect =>- ({ top: 0, left: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect+const rect = (x: number, y: number, width: number, height: number): DOMRect =>+ ({ top: y, left: x, right: x + width, bottom: y + height, width, height, x, y, toJSON: () => ({}) }) as DOMRect-const triggerRect = (): DOMRect =>- ({ top: 100, left: 100, right: 140, bottom: 130, width: 40, height: 30, x: 100, y: 100, toJSON: () => ({}) }) as DOMRect--const paneRect = (): DOMRect =>- ({ top: 0, left: 0, right: 1024, bottom: 768, width: 1024, height: 768, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect--/** Install geometry BEFORE render: the boundary-resolving layout effect runs- * during the mount commit, so it must already see Chromium-like rects. The- * pane host is the [data-tree-group] element itself; the trigger is the- * button inside it; everything else is a full-viewport ancestor. */-function mockGeometry(hostRect: () => DOMRect) {+/** Chromium-like geometry, installed BEFORE render because the boundary is+ * resolved in a layout effect during the mount commit: a zero-rect+ * [data-tree-group] host, a real trigger inside it, a full viewport around. */+function mockGeometry() {vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {- if (this.closest('[data-tree-group]') === this) {- return hostRect()+ if (this.hasAttribute('data-tree-group')) {+ return rect(0, 0, 0, 0)}- return this.tagName === 'BUTTON' ? triggerRect() : paneRect()+ return this.tagName === 'BUTTON' ? rect(100, 100, 40, 30) : rect(0, 0, 1024, 768)})- // floating-ui reads a boundary's inner rect from clientWidth/clientHeight,- // which jsdom always reports as 0 — mirror the mocked rect there too.- Object.defineProperty(Element.prototype, 'clientWidth', {- configurable: true,- get(this: Element) {- return this.closest('[data-tree-group]') === this ? hostRect().width : 1024- }- })- Object.defineProperty(Element.prototype, 'clientHeight', {- configurable: true,- get(this: Element) {- return this.closest('[data-tree-group]') === this ? hostRect().height : 768- }- })+ // floating-ui reads a boundary's inner size from clientWidth/clientHeight,+ // which jsdom always reports as 0 — mirror the mocked rects there too.+ for (const [name, size] of [+ ['clientWidth', 1024],+ ['clientHeight', 768]+ ] as const) {+ Object.defineProperty(Element.prototype, name, {+ configurable: true,+ get(this: Element) {+ return this.hasAttribute('data-tree-group') ? 0 : size+ }+ })+ }}-async function hoverOpen() {+afterEach(() => {+ cleanup()+ vi.restoreAllMocks()+ delete (Element.prototype as { clientWidth?: number }).clientWidth+ delete (Element.prototype as { clientHeight?: number }).clientHeight+})++// The floating-composer host (floating-surface.tsx) carries a data-tree-group+// of its own while being display:contents, so composer controls resolve it as+// their pane. A zero-rect boundary clips every side of a fully visible+// trigger and the tip mounts straight into visibility:hidden.+it('opens a tip whose nearest tree-group host has no layout', async () => {+ mockGeometry()++ render(+ <RootTooltipProvider>+ <div data-tree-group="floating-host">+ <Tip label="Model · custom:test: model-x">+ <button>Trigger</button>+ </Tip>+ </div>+ </RootTooltipProvider>+ )+const trigger = screen.getByRole('button')fireEvent.pointerEnter(trigger)fireEvent.pointerMove(trigger, { pointerType: 'mouse' })@@ -55,56 +70,8 @@ async function hoverOpen() {)// eslint-disable-next-line no-restricted-globals -- the portal mounts on the live document- return document.querySelector<HTMLElement>('[data-radix-popper-content-wrapper]')-}+ const wrapper = document.querySelector<HTMLElement>('[data-radix-popper-content-wrapper]')-afterEach(() => {- cleanup()- vi.restoreAllMocks()- delete (Element.prototype as any).clientWidth- delete (Element.prototype as any).clientHeight-})--// The floating-composer host (floating-surface.tsx) carries a data-tree-group-// of its own while being display:contents, so composer controls resolve it as-// their pane. A zero-rect boundary clips every side of a fully visible-// trigger and the tip mounts straight into visibility:hidden (#114602).-describe('Tip collision boundary resolution', () => {- it('ignores a pane without layout instead of hiding the bubble', async () => {- mockGeometry(zeroRect)-- render(- <RootTooltipProvider>- <div data-tree-group="floating-host">- <Tip label="Model · custom:test: model-x">- <button>Trigger</button>- </Tip>- </div>- </RootTooltipProvider>- )-- const wrapper = await hoverOpen()-- expect(wrapper).not.toBeNull()- expect(wrapper?.style.visibility).not.toBe('hidden')- })-- it('still clips against a pane that has layout', async () => {- mockGeometry(paneRect)-- render(- <RootTooltipProvider>- <div data-tree-group="pane">- <Tip label="Details">- <button>Trigger</button>- </Tip>- </div>- </RootTooltipProvider>- )-- const wrapper = await hoverOpen()-- expect(wrapper).not.toBeNull()- expect(wrapper?.style.visibility).not.toBe('hidden')- })+ expect(wrapper).not.toBeNull()+ expect(wrapper?.style.visibility).not.toBe('hidden')})diff --git a/apps/desktop/src/components/ui/tooltip-placement.test.tsx b/apps/desktop/src/components/ui/tooltip-placement.test.tsxindex 54fc95ea755..2233e0eb5f2 100644--- a/apps/desktop/src/components/ui/tooltip-placement.test.tsx+++ b/apps/desktop/src/components/ui/tooltip-placement.test.tsx@@ -34,6 +34,7 @@ vi.mock('radix-ui', async () => {afterEach(() => {cleanup()contentProps.mockClear()+ vi.restoreAllMocks()})const latestContent = () => contentProps.mock.calls.at(-1)?.[0]@@ -79,6 +80,29 @@ describe('tooltip placement', () => {expect(screen.getByRole('button').parentElement).toBe(screen.getByTestId('pane'))})+ it('skips a tree-group host without layout and clips against the enclosing pane', () => {+ // The floating-composer host carries its own data-tree-group while being+ // `display: contents`; a zero-rect boundary would hide every composer tip.+ const rect = (width: number, height: number) =>+ ({ top: 0, left: 0, right: width, bottom: height, width, height, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect++ vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {+ return (this as HTMLElement).dataset.treeGroup === 'floating-host' ? rect(0, 0) : rect(40, 30)+ })++ render(+ <div data-testid="pane" data-tree-group="test-pane">+ <div data-tree-group="floating-host">+ <Tip label="Details">+ <button>Trigger</button>+ </Tip>+ </div>+ </div>+ )++ expect(latestContent().collisionBoundary).toBe(screen.getByTestId('pane'))+ })+it.each(['row', 'left-rail', 'right-rail'] as const)('lets %s escape the pane', placement => {render(<div data-tree-group="test-pane">diff --git a/apps/desktop/src/components/ui/tooltip.tsx b/apps/desktop/src/components/ui/tooltip.tsxindex f2fbfaa5d83..5127fc8f6cb 100644--- a/apps/desktop/src/components/ui/tooltip.tsx+++ b/apps/desktop/src/components/ui/tooltip.tsx@@ -143,6 +143,13 @@ interface TooltipContentProps extends React.ComponentProps<typeof TooltipPrimitiboundary?: 'pane' | 'viewport'}+/** `display: contents` (and detached) elements report an all-zero rect. */+function hasLayout(element: Element | null): boolean {+ const rect = element?.getBoundingClientRect()++ return !!rect && (rect.width > 0 || rect.height > 0)+}+function TooltipContent({align,arrowPadding = 6,@@ -171,15 +178,20 @@ function TooltipContent({// A boundary without geometry (a `display: contents` host, e.g. the// floating-composer tree-group) zeroes every clipping rect, so `hide()`// detaches a fully visible trigger and the tip mounts straight into- // `visibility: hidden`. Only a pane that has layout of its own may clip;- // when nothing does (a DOM without geometry), the pane stands as before.- const candidate = anchor?.current?.closest('[data-tree-group]') ?? null- const paneRect = candidate?.getBoundingClientRect()- const anchorRect = anchor?.current?.getBoundingClientRect()- const measurable = !!anchorRect && (anchorRect.width > 0 || anchorRect.height > 0)- const paneHasLayout = !!paneRect && (paneRect.width > 0 || paneRect.height > 0)-- setPane(!measurable || paneHasLayout ? candidate : null)+ // `visibility: hidden`. Only a pane that has layout of its own may clip:+ // skip layout-less hosts up to the enclosing pane, or the viewport when+ // none has layout. A trigger without geometry cannot be judged (jsdom),+ // so the nearest pane stands as before.+ const trigger = anchor?.current ?? null+ let candidate = trigger?.closest('[data-tree-group]') ?? null++ if (hasLayout(trigger)) {+ while (candidate && !hasLayout(candidate)) {+ candidate = candidate.parentElement?.closest('[data-tree-group]') ?? null+ }+ }++ setPane(candidate)}, [anchor, boundary])return (