Skip to content

The agent that grows with you

fix(desktop): resolve the tooltip pane boundary when the tip opens, not at mount

teknium1bfb01087d853
diff --git a/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx
index 94a04aefa87..0dad7a75c4d 100644
--- a/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx
+++ b/apps/desktop/src/components/ui/tooltip-pane-layout.test.tsx
@@ -9,13 +9,17 @@ const rect = (x: number, y: number, width: number, height: number): 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() {
+function mockGeometry(triggerLaidOut = () => true) {
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {
if (this.hasAttribute('data-tree-group')) {
return rect(0, 0, 0, 0)
}
- return this.tagName === 'BUTTON' ? rect(100, 100, 40, 30) : rect(0, 0, 1024, 768)
+ if (this.tagName === 'BUTTON') {
+ return triggerLaidOut() ? rect(100, 100, 40, 30) : rect(0, 0, 0, 0)
+ }
+
+ return rect(0, 0, 1024, 768)
})
// floating-ui reads a boundary's inner size from clientWidth/clientHeight,
@@ -75,3 +79,40 @@ it('opens a tip whose nearest tree-group host has no layout', async () => {
expect(wrapper).not.toBeNull()
expect(wrapper?.style.visibility).not.toBe('hidden')
})
+
+// The live app mounts composer `Tip`s before their trigger has geometry (the
+// floating surface is laid out later). The pane must be resolved when the tip
+// OPENS — a once-at-mount resolution keeps the zero-rect host forever and every
+// composer tip stays visibility:hidden.
+it('resolves the pane at open time, not at mount', async () => {
+ let laidOut = false
+ mockGeometry(() => laidOut)
+
+ render(
+ <RootTooltipProvider>
+ <div data-tree-group="floating-host">
+ <Tip label="Add context">
+ <button>Trigger</button>
+ </Tip>
+ </div>
+ </RootTooltipProvider>
+ )
+
+ laidOut = true
+ 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-radix-popper-content-wrapper]')).not.toBeNull()
+ },
+ { timeout: 2000 }
+ )
+
+ await vi.waitFor(() => {
+ // eslint-disable-next-line no-restricted-globals -- the portal mounts on the live document
+ expect(document.querySelector<HTMLElement>('[data-radix-popper-content-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 5127fc8f6cb..54f8e748cd7 100644
--- a/apps/desktop/src/components/ui/tooltip.tsx
+++ b/apps/desktop/src/components/ui/tooltip.tsx
@@ -150,7 +150,20 @@ function hasLayout(element: Element | null): boolean {
return !!rect && (rect.width > 0 || rect.height > 0)
}
-function TooltipContent({
+function TooltipContent(props: TooltipContentProps) {
+ return (
+ <TooltipPrimitive.Portal>
+ <PaneClippedContent {...props} />
+ </TooltipPrimitive.Portal>
+ )
+}
+
+// Rendered inside the Portal, which Radix mounts only while the tip is open —
+// so the pane is resolved at OPEN time, on every open. Resolving it once at
+// `Tip` mount clipped composer tips against the zero-rect floating host for
+// good: the trigger had no layout yet when the effect ran, the host was kept
+// "as before", and nothing ever re-resolved it (#114602, live pass).
+function PaneClippedContent({
align,
arrowPadding = 6,
children,
@@ -195,32 +208,30 @@ function TooltipContent({
}, [anchor, boundary])
return (
- <TooltipPrimitive.Portal>
- <TooltipPrimitive.Content
- align={align ?? preferred.align}
- arrowPadding={arrowPadding}
- className={cn(
- 'tooltip-bubble pointer-events-none z-(--z-over-modal) w-fit select-none bg-foreground px-2 py-1 text-[0.6875rem] font-medium leading-[1.4] text-background',
- className
- )}
- collisionBoundary={collisionBoundary ?? pane ?? undefined}
- collisionPadding={collisionPadding}
- data-slot="tooltip-content"
- hideWhenDetached={hideWhenDetached}
- side={side ?? preferred.side}
- sideOffset={sideOffset}
- {...props}
- >
- <div className="tooltip-bubble-label" data-slot="tooltip-label">
- {children}
- </div>
- <TooltipPrimitive.Arrow asChild height={5} width={10}>
- <svg aria-hidden data-slot="tooltip-arrow" viewBox="0 0 10 5">
- <path d="M0 0h10L5.7 4.3a1 1 0 0 1-1.4 0Z" />
- </svg>
- </TooltipPrimitive.Arrow>
- </TooltipPrimitive.Content>
- </TooltipPrimitive.Portal>
+ <TooltipPrimitive.Content
+ align={align ?? preferred.align}
+ arrowPadding={arrowPadding}
+ className={cn(
+ 'tooltip-bubble pointer-events-none z-(--z-over-modal) w-fit select-none bg-foreground px-2 py-1 text-[0.6875rem] font-medium leading-[1.4] text-background',
+ className
+ )}
+ collisionBoundary={collisionBoundary ?? pane ?? undefined}
+ collisionPadding={collisionPadding}
+ data-slot="tooltip-content"
+ hideWhenDetached={hideWhenDetached}
+ side={side ?? preferred.side}
+ sideOffset={sideOffset}
+ {...props}
+ >
+ <div className="tooltip-bubble-label" data-slot="tooltip-label">
+ {children}
+ </div>
+ <TooltipPrimitive.Arrow asChild height={5} width={10}>
+ <svg aria-hidden data-slot="tooltip-arrow" viewBox="0 0 10 5">
+ <path d="M0 0h10L5.7 4.3a1 1 0 0 1-1.4 0Z" />
+ </svg>
+ </TooltipPrimitive.Arrow>
+ </TooltipPrimitive.Content>
)
}