Skip to content

The agent that grows with you

fix(desktop): ignore a zero-rect tree-group host as a tooltip collision boundary

Konstantin Khlopkov80fc376521d9
diff --git a/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx
new file mode 100644
index 00000000000..04c32bc2c1a
--- /dev/null
+++ b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx
@@ -0,0 +1,110 @@
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { afterEach, describe, 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 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) {
+ vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {
+ if (this.closest('[data-tree-group]') === this) {
+ return hostRect()
+ }
+
+ return this.tagName === 'BUTTON' ? triggerRect() : paneRect()
+ })
+
+ // 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
+ }
+ })
+}
+
+async function hoverOpen() {
+ const trigger = screen.getByRole('button')
+ fireEvent.pointerEnter(trigger)
+ fireEvent.pointerMove(trigger, { pointerType: 'mouse' })
+
+ await vi.waitFor(
+ () => {
+ // eslint-disable-next-line no-restricted-globals -- the portal mounts on the live document
+ expect(document.querySelector('[data-slot="tooltip-content"]')).not.toBeNull()
+ },
+ { timeout: 2000 }
+ )
+
+ // eslint-disable-next-line no-restricted-globals -- the portal mounts on the live document
+ return 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')
+ })
+})
diff --git a/apps/desktop/src/components/ui/tooltip.tsx b/apps/desktop/src/components/ui/tooltip.tsx
index 50c7f128508..f2fbfaa5d83 100644
--- a/apps/desktop/src/components/ui/tooltip.tsx
+++ b/apps/desktop/src/components/ui/tooltip.tsx
@@ -162,7 +162,24 @@ function TooltipContent({
const [pane, setPane] = React.useState<Element | null>(null)
React.useLayoutEffect(() => {
- setPane(boundary === 'pane' ? (anchor?.current?.closest('[data-tree-group]') ?? null) : null)
+ if (boundary !== 'pane') {
+ setPane(null)
+
+ return
+ }
+
+ // 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)
}, [anchor, boundary])
return (