Skip to content

fix(HoverCard,Tooltip): wait for the trigger to have a layout box before showing - #5398

Merged
cixzhang merged 14 commits into
meta:mainfrom
HelloOjasMutreja:fix/hovercard-controlled-open-anchoring
Nov 8, 2026
Merged

cixzhang merged 14 commits into
meta:mainfrom
HelloOjasMutreja:fix/hovercard-controlled-open-anchoring

Conversation

@HelloOjasMutreja

@HelloOjasMutreja HelloOjasMutreja commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5374.

Problem

Dialog mounts its children before it opens: isOpen gates the <dialog>'s own showModal(), not whether {children} renders. So a HoverCard or Tooltip inside one with a controlled isOpen={true} (or isDefaultOpen) runs its show effect while the trigger sits in a still non-modal <dialog> and has no layout box (0x0).

A trigger with no box is not a valid CSS anchor. position-anchor resolves to its fallback position in the viewport corner, and unlike a live layout change that resolution is not revisited once the trigger later gets a box. I measured the card staying at (0, 4) for more than 3 seconds after the dialog visibly opened, so this is a permanently invalid anchor, not a one-frame race. A requestAnimationFrame defer and a setTimeout(50) defer both failed to fix it, which points at the missing box itself being the precondition.

Fix

All in useLayer's show(), the one place every context-mode open goes through:

  • A trigger that already has a box opens in the same task, so a menu or popover still opens on press and not on the next frame.
  • A boxless trigger waits first for a box, then for any running animation on the document timeline that ends on its own, on the trigger or an ancestor, to finish, so the layer anchors to the settled position and not a mid-transition one. Paused, infinite, and scroll- or view-driven animations are not waited on.
  • The box wait is driven by signals, never by polling. It re-reads whether the anchor is ready on a ResizeObserver entry (a block-level trigger gaining a box), on an IntersectionObserver report (which reaches a display: inline trigger, such as a text-only trigger's wrapper <span>, where a ResizeObserver delivers no entry), and on the enclosing <dialog>'s open attribute and toggle event. These use Core's shared observers, and each registration is released on its own. There is no time limit: the wait ends when the trigger gets a box or the open is cancelled.
  • If the trigger element is replaced while waiting, the wait restarts on the new element, and a trigger that unmounts for good stops the wait and releases its observers.
  • One cancel function covers both the box wait and the settle wait.
  • Without a layout engine to wait on (no ResizeObserver, no requestAnimationFrame, or no Web Animations API, as in jsdom) the layer opens immediately.

Separately, a transient null then same-element call on the trigger ref (what a combined ref utility makes when a handler changes identity) no longer removes and re-adds the element's anchor-name. That churn could also strand an open layer in the corner.

What changed after review

The first version waited at least a frame on every open, including for a trigger that already had a box. That moved a DropdownMenu's open from press to release, failed the Core/Layer viewport-inset stories (no open layer right after the click) and the DateInput and DateTimeInput FR10 suites (their no-op ResizeObserver stubs never ended the wait). It also had these gaps, all fixed here:

  • the settle wait is now limited to the boxless path, and an ancestor's paused animation can no longer hold a layer closed;
  • a wait on an element that was then replaced never ended; it now restarts on the new trigger;
  • a synchronously firing ResizeObserver left the settle wait uncancellable by hide(), because the final cancel function overwrote its handle;
  • the test ResizeObserver mocks I had edited in Popover, PowerSearch and Tokenizer tests, the clearTimeouts hoist in useTooltip, and the Playwright glob are all reverted, since they only existed to accommodate the always-wait version. This PR no longer touches any of those files.

Since the last review the unbounded requestAnimationFrame poll is gone (it is replaced by the signals above), the branch is rebased on current main, and the new comments and test harness pass ASTRYX_STRICT_LINT=1 pnpm lint.

Verification

Reproduced against the exact story from the issue (Core/Layer Dismissal, Pinned Hover Card In Modal), where the Dialog opens later via a click.

Before, card stuck in the corner, disconnected from its trigger:
before

After, anchored above "Card trigger", matching placement="above":
after

Those two images are from the earlier version of this fix; the visible outcome for a boxless trigger is unchanged.

Tests (jsdom, with layout stubbed): eight new show() readiness tests in useLayer.test.tsx. I broke the code four ways to confirm each is caught: waiting on the box path again fails the same-task open test, dropping the running-only filter fails the paused-animation test, removing the trigger restart fails the replacement test, and a cancel that skips the settle wait fails the hide() test. The whole useLayer file passes (78 tests), as do the Layer, Popover, Tooltip, HoverCard, DropdownMenu, DateInput, DateTimeInput, DateRangeInput, PowerSearch, Tokenizer, Selector and MultiSelector suites, apart from one failure that is also on main. That one is layerViewportInset.test.ts, which compares Windows backslash paths to forward-slash names. Core typecheck, eslint and prettier are clean.

Limits

I could not run the browser parts here: the Storybook build and dev server crash on my machine with a native out-of-memory error. So the Core/Layer story play-guards, the anchorReadiness Playwright spec and the WebKit run are not verified by me, and the "after" image above is from the earlier version. The Core/Layer and DateInput FR10 failures from the last review should be gone by construction, because a trigger with a box now opens synchronously and jsdom without the Web Animations API no longer waits, but that is for CI to confirm.

Review outcomes at 1f0f5d8

One row per point in the earlier change request, checked at this exact head.

Requested outcome Evidence at 1f0f5d8
The controlled Tooltip in a Dialog opens at its trigger, not at (0, 4), in real Chromium anchorReadiness.a11y.browser.spec.ts, "a controlled Tooltip opened inside a Dialog anchors to its trigger" and the text-only-trigger and late-layout variants, pass in pr-a11y (browser specs 1–3/3) (green at this head). The automated review measured the controlled Tooltip and HoverCard 4 px from their trigger in Chromium and WebKit; main leaves them 285–452 px away at the viewport edge.
Readiness stays in Layer's existing lifecycle owner, with no caller-level timing abstraction The anchor wait lives in useLayer.tsx; showWhenAnchored.ts is gone (the file is absent at this head). The PR changes only Layer files, its tests, one story and a changeset.
Both controlled paths are covered by a real-browser regression The same spec has "a controlled HoverCard opened inside a Dialog anchors to its trigger" next to the Tooltip cases, plus "a controlled Tooltip still opens when its trigger sits inside a continuously animating ancestor". pr-interaction and pr-interaction-webkit (6/6 each) are green.
The global ResizeObserver stub in internal/test-utils/src/setup.ts is gone or local to the affected tests internal/test-utils is identical to main at this head (no diff); the test doubles live in useLayer.test.tsx.
TabList's tests pass unchanged packages/core/src/TabList is identical to main; test-ui (1/4) at this head runs TabList.test.tsx green (88 tests, which main has grown from the 74 at the time of the review).

CI at this head: build, lint, test, test-ui (1–4/4), test-node (1–4/4), pr-a11y (audit and browser specs), pr-interaction, pr-interaction-webkit, docsite-test and the visual regression are green.

(Posted by Cindy's agent on her behalf.)

@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 8, 2026 5:13am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 1f0f5d8

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
LayerProvider 4.2 kB (0) · 20 B CSS (0) — ✓ · ✓ · ✗
AvatarGroupOverflow 48.3 kB (+1.1 kB) · 5.5 kB CSS (0) — — · — · —
Toolbar 42.7 kB (+1.1 kB) · 8.0 kB CSS (0) — — · — · —
112 more components
Component Size LoC Visual · A11y · RTL
Avatar 42.6 kB (+1.0 kB) · 5.5 kB CSS (0) — — · — · —
Tooltip 29.0 kB (+1.0 kB) · 4.4 kB CSS (0) — — · — · —
AvatarGroup 45.4 kB (+1.0 kB) · 5.6 kB CSS (0) — — · — · —
StatusDot 30.7 kB (+1.0 kB) · 5.3 kB CSS (0) — — · — · —
TabList 43.2 kB (+917 B) · 6.5 kB CSS (0) — — · — · —
SegmentedControl 93.4 kB (+888 B) · 6.8 kB CSS (0) — — · — · —
FieldLabel 50.5 kB (+775 B) · 5.7 kB CSS (0) — — · — · —
HoverCard 27.0 kB (+744 B) · 4.4 kB CSS (0) — — · — · —
InfoTip 46.1 kB (+734 B) · 5.3 kB CSS (0) — — · — · —
DateInput 183.2 kB (+674 B) · 16.7 kB CSS (0) — — · — · —
CheckboxList 68.6 kB (+664 B) · 8.1 kB CSS (0) — — · — · —
TextArea 61.7 kB (+656 B) · 9.2 kB CSS (0) — — · — · —
DropdownMenu 96.2 kB (+654 B) · 17.1 kB CSS (0) — — · — · —
Markdown 180.1 kB (+652 B) · 20.0 kB CSS (0) — — · — · —
DateTimeInput 205.0 kB (+646 B) · 18.4 kB CSS (0) — — · — · —
DateRangeInput 91.6 kB (+643 B) · 12.3 kB CSS (0) — — · — · —
Field 54.3 kB (+643 B) · 7.2 kB CSS (0) — — · — · —
PowerSearch 282.3 kB (+638 B) · 23.5 kB CSS (0) — — · — · —
MoreMenu 96.5 kB (+637 B) · 17.1 kB CSS (0) — — · — · —
Selector 98.8 kB (+634 B) · 17.1 kB CSS (0) — — · — · —
TimeInput 158.9 kB (+627 B) · 15.7 kB CSS (0) — — · — · —
MultiSelector 94.0 kB (+626 B) · 16.6 kB CSS (0) — — · — · —
RadioList 55.7 kB (+625 B) · 7.2 kB CSS (0) — — · — · —
CodeBlock 74.4 kB (+624 B) · 11.2 kB CSS (0) — — · — · —
Carousel 69.2 kB (+622 B) · 10.8 kB CSS (0) — — · — · —
TableHeaderCell 107.6 kB (+622 B) · 17.2 kB CSS (0) — — · — · —
ComplexSelector 70.2 kB (+614 B) · 11.7 kB CSS (0) — — · — · —
Slider 106.7 kB (+611 B) · 8.8 kB CSS (0) — — · — · —
RadioListItem 66.7 kB (+610 B) · 10.1 kB CSS (0) — — · — · —
ContextMenu 106.8 kB (+609 B) · 17.0 kB CSS (0) — — · — · —
TextInput 67.0 kB (+609 B) · 11.1 kB CSS (0) — — · — · —
Pagination 108.8 kB (+607 B) · 17.5 kB CSS (0) — — · — · —
Table 116.9 kB (+606 B) · 17.7 kB CSS (0) — — · — · —
ChatLayout 79.9 kB (+605 B) · 10.4 kB CSS (0) — — · — · —
Toast 97.5 kB (+600 B) · 10.2 kB CSS (0) — — · — · —
TableCell 108.0 kB (+595 B) · 17.4 kB CSS (0) — — · — · —
Tokenizer 90.6 kB (+593 B) · 18.3 kB CSS (0) — — · — · —
FileInput 68.5 kB (+590 B) · 10.8 kB CSS (0) — — · — · —
Switch 101.2 kB (+587 B) · 9.9 kB CSS (0) — — · — · —
CheckboxInput 63.7 kB (+584 B) · 9.1 kB CSS (0) — — · — · —
AppShell 90.1 kB (+580 B) · 13.4 kB CSS (0) — — · — · —
InputGroup 55.9 kB (+578 B) · 7.8 kB CSS (0) — — · — · —
Typeahead 78.9 kB (+575 B) · 12.3 kB CSS (0) — — · — · —
ListItem 69.2 kB (+574 B) · 11.3 kB CSS (0) — — · — · —
NumberInput 71.0 kB (+562 B) · 11.3 kB CSS (0) — — · — · —
TableSelectionToolbar 69.4 kB (+561 B) · 13.0 kB CSS (0) — — · — · —
Button 59.6 kB (+557 B) · 9.9 kB CSS (0) — — · — · —
CheckboxListItem 70.3 kB (+555 B) · 11.3 kB CSS (0) — — · — · —
IconButton 59.7 kB (+552 B) · 9.9 kB CSS (0) — — · — · —
ChatComposerTokenElement 74.9 kB (+550 B) · 11.2 kB CSS (0) — — · — · —
SideNavItem 69.8 kB (+550 B) · 11.0 kB CSS (0) — — · — · —
TabMenu 71.1 kB (+550 B) · 11.0 kB CSS (0) — — · — · —
ChatComposerInput 74.9 kB (+549 B) · 11.2 kB CSS (0) — — · — · —
MobileNav 69.9 kB (+547 B) · 10.5 kB CSS (0) — — · — · —
Calendar 70.6 kB (+546 B) · 10.5 kB CSS (0) — — · — · —
ChatLayoutScrollButton 60.1 kB (+546 B) · 10.1 kB CSS (0) — — · — · —
AlertDialog 104.6 kB (+544 B) · 14.3 kB CSS (0) — — · — · —
BaseTypeahead 70.5 kB (+543 B) · 10.8 kB CSS (0) — — · — · —
ChatComposer 76.9 kB (+540 B) · 11.7 kB CSS (0) — — · — · —
ChatSendButton 60.0 kB (+539 B) · 9.9 kB CSS (0) — — · — · —
DropdownMenuSubMenu 69.5 kB (+539 B) · 9.7 kB CSS (0) — — · — · —
ToggleButton 60.5 kB (+539 B) · 10.0 kB CSS (0) — — · — · —
TopNav 71.6 kB (+539 B) · 10.8 kB CSS (0) — — · — · —
Link 52.5 kB (+537 B) · 7.0 kB CSS (0) — — · — · —
TopNavMenu 73.9 kB (+537 B) · 11.2 kB CSS (0) — — · — · —
Popover 88.4 kB (+536 B) · 13.9 kB CSS (0) — — · — · —
SideNavCollapseButton 60.4 kB (+534 B) · 10.0 kB CSS (0) — — · — · —
DrawerHeader 62.6 kB (+533 B) · 12.8 kB CSS (0) — — · — · —
TopNavMegaMenu 69.0 kB (+531 B) · 11.7 kB CSS (0) — — · — · —
Lightbox 118.3 kB (+528 B) · 10.4 kB CSS (0) — — · — · —
DialogHeader 62.4 kB (+527 B) · 11.4 kB CSS (0) — — · — · —
BreadcrumbItem 83.8 kB (+525 B) · 12.0 kB CSS (0) — — · — · —
MobileNavToggle 59.9 kB (+525 B) · 9.9 kB CSS (0) — — · — · —
Banner 61.6 kB (+524 B) · 10.4 kB CSS (0) — — · — · —
ChatDictationButton 60.2 kB (+524 B) · 10.0 kB CSS (0) — — · — · —
TopNavHeading 74.2 kB (+524 B) · 11.0 kB CSS (0) — — · — · —
Thumbnail 63.9 kB (+518 B) · 11.5 kB CSS (0) — — · — · —
Stepper 61.2 kB (+504 B) · 10.0 kB CSS (0) — — · — · —
SideNavHeading 74.8 kB (+496 B) · 11.2 kB CSS (0) — — · — · —
SideNav 94.5 kB (+491 B) · 11.3 kB CSS (0) — — · — · —
Timer 13.3 kB (+44 B) · 6.0 kB CSS (0) — — · — · —
Heading 11.8 kB (+25 B) · 5.4 kB CSS (0) — — · — · —
ProgressBar 11.7 kB (+22 B) · 6.3 kB CSS (0) — — · — · —
Text 11.2 kB (+19 B) · 5.4 kB CSS (0) — — · — · —
CommandPalette 72.3 kB (+11 B) · 12.4 kB CSS (0) — — · — · —
Spinner 24.0 kB (−2 B) · 6.2 kB CSS (0) — — · — · —
CommandPaletteInput 31.0 kB (−4 B) · 7.5 kB CSS (0) — — · — · —
ChatToolCalls 31.3 kB (−20 B) · 8.3 kB CSS (0) — — · — · —
ChatMessageList 27.4 kB (−32 B) · 7.0 kB CSS (0) — — · — · —
Timestamp 32.2 kB (−83 B) · 10.2 kB CSS (0) — — · — · —
charts/Chart 198.1 kB (new) · 494 B CSS (new) — — · — · —
charts/ChartLegend 48.4 kB (new) · 224 B CSS (new) — — · — · —
charts/ChartTooltip 175.4 kB (new) · 423 B CSS (new) — — · — · —
layer — — — · ✓ · —
Layer — — ✓ · ✓ · —
lab/ChatEmojiPicker 102.9 kB (new) · 773 B CSS (new) — — · — · —
lab/ChatReactionBar 104.0 kB (new) · 1.1 kB CSS (new) — — · — · —
lab/CommentComposer 147.7 kB (new) · 1.9 kB CSS (new) — — · — · —
lab/CommentPin 56.5 kB (new) · 1.2 kB CSS (new) — — · — · —
lab/Comments 337.7 kB (new) · 2.5 kB CSS (new) — — · — · —
lab/CommentThread 330.7 kB (new) · 2.4 kB CSS (new) — — · — · —
lab/DiffViewer 86.0 kB (new) · 2.1 kB CSS (new) — — · — · —
lab/EmojiPicker 85.5 kB (new) · 751 B CSS (new) — — · — · —
lab/ListInput 101.1 kB (new) · 1.6 kB CSS (new) — — · — · —
lab/Schedule 105.1 kB (new) · 3.9 kB CSS (new) — — · — · —
lab/SelectableCardGroup 63.6 kB (new) · 162 B CSS (new) — — · — · —
lab/TourStep 94.7 kB (new) · 590 B CSS (new) — — · — · —
lab/TransferList 106.9 kB (new) · 1.7 kB CSS (new) — — · — · —
lab/TransferListSelector 113.7 kB (new) · 1.9 kB CSS (new) — — · — · —
richtext/RichTextEditor 296.0 kB (new) · 2.6 kB CSS (new) — — · — · —
richtext/RichTextEditorToolbar 250.8 kB (new) · 454 B CSS (new) — — · — · —
richtext/RichTextView 275.4 kB (new) · 2.3 kB CSS (new) — — · — · —

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: cli +22 · ~7 · −0 (against the merge base's committed report)

Committed API report behind this build: cli 29 rows, core 40 rows; run pnpm api:report.

29 API changes (advisory)
Package Where Signature Usage
+ cli ./api · Functions · function exportSearchIndex function exportSearchIndex @experimental: (options?: { cwd?: string | undefined; package?: string | undefined }) => Promise<SearchIndex> import {exportSearchIndex} from '@astryxdesign/cli/api'; exportSearchIndex(…)
+ cli ./api · Functions · function rankSearchIndex function rankSearchIndex @experimental: (query: string, indexes: SearchIndex | SearchIndex[], options?: { type?: SearchDomain | undefined; limit?: number | undefined }) => Promise<SearchResponse> import {rankSearchIndex} from '@astryxdesign/cli/api'; rankSearchIndex(…)
+ cli ./api · Types · type DocsListChild type DocsListChild = DocsNodeChild & { topic: string; description: string; children?: DocsListChild[]; childCount?: number } import type {DocsListChild} from '@astryxdesign/cli/api'
+ cli ./api · Types · type DocsListNamespace childCount?: number | undefined import type {DocsListNamespace} from '@astryxdesign/cli/api'; const x: DocsListNamespace = {childCount: …}
+ cli ./api · Types · type DocsListNamespace children?: DocsListChild[] | undefined import type {DocsListNamespace} from '@astryxdesign/cli/api'; const x: DocsListNamespace = {children: …}
+ cli ./api · Types · type SearchIndex type SearchIndex import type {SearchIndex} from '@astryxdesign/cli/api'
+ cli ./api · Types · type SearchResultEntry deprecated?: ComponentDeprecation | undefined import type {SearchResultEntry} from '@astryxdesign/cli/api'; const x: SearchResultEntry = {deprecated: …}
+ cli ./authoring · Types · interface ComponentDeprecation interface ComponentDeprecation import type {ComponentDeprecation} from '@astryxdesign/cli/authoring'
+ cli ./authoring · Types · interface ComponentIconSlotDoc interface ComponentIconSlotDoc import type {ComponentIconSlotDoc} from '@astryxdesign/cli/authoring'
+ cli ./authoring · Types · interface ComponentIconSlotStateDoc interface ComponentIconSlotStateDoc import type {ComponentIconSlotStateDoc} from '@astryxdesign/cli/authoring'
+ cli ./authoring · Types · interface MultiComponentDoc deprecated?: ComponentDeprecation import type {MultiComponentDoc} from '@astryxdesign/cli/authoring'; const x: MultiComponentDoc = {deprecated: …}
+ cli ./authoring · Types · interface SingleComponentDoc deprecated?: ComponentDeprecation import type {SingleComponentDoc} from '@astryxdesign/cli/authoring'; const x: SingleComponentDoc = {deprecated: …}
+ cli ./doc · Types · interface ComponentBaseDoc deprecated?: ComponentDeprecation import type {ComponentBaseDoc} from '@astryxdesign/cli/doc'; const x: ComponentBaseDoc = {deprecated: …}
+ cli ./doc · Types · interface SubComponentDoc deprecated?: ComponentDeprecation import type {SubComponentDoc} from '@astryxdesign/cli/doc'; const x: SubComponentDoc = {deprecated: …}
+ cli ./doc · Also exported from an earlier entry point · ComponentDeprecation ComponentDeprecation (./authoring) import {ComponentDeprecation} from '@astryxdesign/cli/doc'
+ cli ./doc · Also exported from an earlier entry point · ComponentIconSlotDoc ComponentIconSlotDoc (./authoring) import {ComponentIconSlotDoc} from '@astryxdesign/cli/doc'
+ cli ./doc · Also exported from an earlier entry point · ComponentIconSlotStateDoc ComponentIconSlotStateDoc (./authoring) import {ComponentIconSlotStateDoc} from '@astryxdesign/cli/doc'
+ cli ./json · Also exported from an earlier entry point · DocsListChild DocsListChild (./api) import {DocsListChild} from '@astryxdesign/cli/json'
+ cli ./json · Also exported from an earlier entry point · SearchIndex SearchIndex (./api) import {SearchIndex} from '@astryxdesign/cli/json'
+ cli ./template · Also exported from an earlier entry point · ComponentDeprecation ComponentDeprecation (./authoring) import {ComponentDeprecation} from '@astryxdesign/cli/template'
+ cli ./template · Also exported from an earlier entry point · ComponentIconSlotDoc ComponentIconSlotDoc (./authoring) import {ComponentIconSlotDoc} from '@astryxdesign/cli/template'
+ cli ./template · Also exported from an earlier entry point · ComponentIconSlotStateDoc ComponentIconSlotStateDoc (./authoring) import {ComponentIconSlotStateDoc} from '@astryxdesign/cli/template'
~ cli ./api · Functions · function search function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "hook" | "theme" | "doc" | undefined; limit?: number | undefined }) => Promise<SearchResponse> → function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "doc" | "theme" | "hook" | undefined; limit?: number | undefined }) => Promise<SearchResponse> import {search} from '@astryxdesign/cli/api'; search(…)
~ cli ./api · Types · type SwizzleCopyResponse data: { component: string; package: string; outputDir: string; filesCopied: number; files: string[]; usesStyleX: boolean; feedback?: SwizzleFeedback | undefined } → data: { component: string; package: string; outputDir: string; filesCopied: number; files: string[]; usesStyleX: boolean; dependencies: Record<string, string>; marker … #84d9505b import type {SwizzleCopyResponse} from '@astryxdesign/cli/api'; const x: SwizzleCopyResponse = {data: …}
~ cli ./authoring · Types · interface MultiComponentDoc theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[] } → theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[]; componentIcons?: ComponentIconSlotDoc[] } import type {MultiComponentDoc} from '@astryxdesign/cli/authoring'; const x: MultiComponentDoc = {theming: …}
~ cli ./authoring · Types · interface SingleComponentDoc theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[] } → theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[]; componentIcons?: ComponentIconSlotDoc[] } import type {SingleComponentDoc} from '@astryxdesign/cli/authoring'; const x: SingleComponentDoc = {theming: …}
~ cli ./authoring · Types · type TemplateCategory type TemplateCategory = | 'Dashboard - Analytics' | 'Dashboard - Comparison' | 'Dashboard - KPI Summary' | 'Dashboard - Monitoring' | 'Dashboard - Executive Summary' | 'Dashboard - Sco … #e7c18378 → type TemplateCategory = | 'Dashboard - Analytics' | 'Dashboard - Comparison' | 'Dashboard - KPI Summary' | 'Dashboard - Monitoring' | 'Dashboard - Executive Summary' | 'Dashboard - Sco … #a8be998f import type {TemplateCategory} from '@astryxdesign/cli/authoring'
~ cli ./doc · Types · interface ComponentBaseDoc theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[] } → theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[]; componentIcons?: ComponentIconSlotDoc[] } import type {ComponentBaseDoc} from '@astryxdesign/cli/doc'; const x: ComponentBaseDoc = {theming: …}
~ cli ./doc · Types · interface SubComponentDoc theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[] } → theming?: { container?: boolean; targets: ComponentThemingTarget[]; vars?: ComponentThemingVar[]; derived?: ComponentThemingDerivedVar[]; componentIcons?: ComponentIconSlotDoc[] } import type {SubComponentDoc} from '@astryxdesign/cli/doc'; const x: SubComponentDoc = {theming: …}

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

github-actions Bot added a commit that referenced this pull request Aug 24, 2026
@HelloOjasMutreja
HelloOjasMutreja marked this pull request as ready for review August 24, 2026 11:15
@HelloOjasMutreja
HelloOjasMutreja force-pushed the fix/hovercard-controlled-open-anchoring branch from a413d10 to 39af550 Compare August 27, 2026 07:40
github-actions Bot added a commit that referenced this pull request Aug 27, 2026
@HelloOjasMutreja
HelloOjasMutreja force-pushed the fix/hovercard-controlled-open-anchoring branch from 39af550 to 76bdb39 Compare September 7, 2026 03:28
github-actions Bot added a commit that referenced this pull request Sep 7, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—HoverCard now anchors correctly, but Tooltip still leaves the user’s hint detached at the viewport corner, and this head also makes the UI suite red.

  • packages/core/src/Layer/showWhenAnchored.ts:27 — In Chromium, the controlled Tooltip-in-Dialog story still opens at (0, 4) while its trigger is around (206, 298). The same exact-head run centers HoverCard correctly. Please keep trigger readiness in Layer’s existing lifecycle owner rather than adding a caller-level timing abstraction, and cover both controlled paths in a real-browser regression.
  • internal/test-utils/src/setup.ts:115 — This global ResizeObserver stub changes unrelated TabList behavior: the exact-head test calls scrollBy twice; current main passes 74/74, and the head also passes when only this setup change is removed. Please keep the test double local to the affected tests.

If you'd rather talk it through with someone, we're in Discord.

[Reviewed by Robohands]

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Fixed in 6e4d9f5 and b695d9a.

Moved trigger-readiness into useLayer's own show(), the one place every context-mode open funnels through, and deleted showWhenAnchored.ts along with both callers now folded into it.

Tracing this live in Chromium turned up more than the box-readiness gap alone. HoverCard's own controlled-in-Dialog story was passing by coincidence, not because its readiness handling differed from Tooltip's: with the trigger's box confirmed present, show() would open correctly, and moments later a second render (caused by the story's own inline onOpenChange closure changing identity, unrelated to isOpen itself) would silently re-mount the SAME popover and trigger elements via React's ref-callback churn. addAnchorName/removeAnchorName's remove-then-readd on that churn flickered the trigger's anchor-name off and back on, and Chromium's position-try-fallbacks resolution does not get revisited once the anchor briefly disappears, permanently stranding the layer at its unanchored fallback position, exactly the reported "(0, 4)" symptom. Since addAnchorName is already idempotent, contextRef's null-branch no longer removes the name eagerly, only the branch handing off to a genuinely different element does.

Past that, real-Chromium tracing surfaced a second issue: even with a real box, showing a layer while an ancestor's own CSS entry animation (Dialog's scale/translate transition) is still running anchors against a mid-transform position that also never gets revisited, since a transform changes nothing ResizeObserver reports. show() now also waits, via document.getAnimations(), for any animation running on the trigger or an ancestor to finish before opening, checked one frame after the readiness gate so a just-triggered animation has actually started (confirmed directly against Chromium: checking synchronously always sees zero animations).

On the internal/test-utils/src/setup.ts point: sharedResizeObserver.ts already has the established pattern for the same gap (typeof ResizeObserver === 'undefined' guard, skip straight to the fallback), so useLayer's show() now mirrors it instead of depending on a global polyfill. The global stub is removed. A few test files that locally stub ResizeObserver for their own unrelated purposes (Popover, PowerSearch x2, Tokenizer) had a no-op observe() that never fired at all, which is what actually broke once useLayer started depending on that firing; those now fire once synchronously, matching the removed polyfill's own behavior, rather than the fix depending on a shared global.

Added packages/core/src/Layer/__tests__/anchorReadiness.chromium.spec.ts, covering both the Tooltip and HoverCard controlled-in-Dialog paths against a real Chromium build (jsdom can exercise neither the animation timing nor actual CSS anchor-positioning resolution this covers). Verified against the reverted code that it fails first (454px gap, the reported viewport-corner position) and passes cleanly across repeated runs with the fix.

Also verified: full ui Vitest project (10,058+ passing), explicit isolated runs of every touched suite (Layer, Tooltip, HoverCard, Popover, PowerSearch, PowerSearchValueEditor, Tokenizer, TabList) all green, typecheck and lint clean. The handful of failures that show up in a full-suite run (docPropLiterals, extensibleAxes, Resizable/utils import timeout, Table.perf, ContextMenu, a TabList roving-tabindex focus-timing test) are all confirmed pre-existing by reproducing them with this fix fully reverted back to the exact-head state.

github-actions Bot added a commit that referenced this pull request Sep 10, 2026
@HelloOjasMutreja
HelloOjasMutreja force-pushed the fix/hovercard-controlled-open-anchoring branch from b695d9a to 9ca8b36 Compare September 21, 2026 10:03
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. One real conflict in playwright.config.ts: main's own pr-a11y work (#6115) added a *.a11y.browser.spec.ts glob to the same testMatch array this PR adds *.chromium.spec.ts to. Both patterns match real, distinct, currently-used spec files (BottomSheet's keyboard contract vs this PR's own Layer anchorReadiness spec), so kept both.

Verified after rebase: typecheck clean, and the affected suites (Popover, PowerSearch, Tokenizer, Layer, Tooltip, HoverCard) pass, isolated and in a narrower batch. A full combined run of all six directories intermittently worker-crashes or shows a single unrelated PowerSearchFilterEditor failure in this environment; reproduces identically on a clean, unmodified checkout of current main with the same broad batch, so it is local Vitest worker-pool flakiness under a large parallel run here, not something this PR introduced.

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Checked the pr-a11y failure on this run: it's in Checkbox.a11y.chromium.spec.ts (a menu-item inventory mismatch, "Show archived" showing up as unexpectedly inert), a file this PR doesn't touch and unrelated to HoverCard/Tooltip anchoring. Not something this diff caused.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving anchor readiness into Layer and adding the real-Chromium Tooltip/HoverCard regression. A few current paths still need correction before this is ready:

  • show() waits for every trigger or ancestor animation to finish, so an infinitely pulsing trigger such as StatusDot can prevent its Tooltip from opening forever. Bound the wait to finite entry motion and cover a continuous-animation trigger.
  • The delayed path switches from getBoundingClientRect() to ResizeObserverEntry.contentRect. Text-only Tooltip/HoverCard triggers are inline spans, whose observed content box can remain empty, so a controlled/default-open layer can stay closed. Use a readiness signal that covers inline triggers and add that browser case.
  • contextRef(null) forgets the old trigger without removing this layer's anchor name. When an external anchor remains mounted or the ref moves, both old and new elements can keep the same association. Preserve transient same-element churn while cleaning a real detach/rebind.
  • The changeset still names the deleted showWhenAnchored helper; update it to describe the current Layer implementation.
  • The current Layer contract requires real Chromium and WebKit evidence for anchor-geometry changes, but this regression is Chromium-only. Add the equivalent WebKit proof.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed: the controlled Tooltip and HoverCard in a Dialog now sit 4 px from their trigger in Chromium and WebKit (325–460 px away on the base), but the new settle wait has two problems.

  • Miss: waitForAncestorAnimations in packages/core/src/Layer/useLayer.tsx (lines 943–961) also waits on scroll-driven animations (animation-timeline: scroll() or view()), which finish only when the person scrolls, so a controlled Tooltip whose trigger sits inside such an ancestor stays hidden after its Dialog opens in both engines; please wait only on animations driven by the document's own timeline and add a unit case for it.
  • Regression: the same filter (lines 954–960) repeats the running-and-finite test that exitAnimations (lines 559–569, from #9963) already owns, with a different finiteness rule, so please have both call one shared predicate.

cixzhang's earlier change request is still open and needs a re-review or a dismissal; both of its points are addressed at this head. CI has not run on this head yet, so a maintainer needs to add the ci:run label.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
…ons, through one shared predicate

A scroll- or view-driven animation finishes only when the person scrolls to the end of its range, so a controlled Tooltip inside such an ancestor stayed hidden. The settle wait now skips animations not on the document's timeline, and it shares the running-and-finite test with exitAnimations.
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Both points are fixed in the head above.

  • Scroll-driven animations: waitForAncestorAnimations now skips an animation whose timeline is not the document's, so a scroll() or view() animation on a trigger's ancestor no longer holds a controlled Tooltip or HoverCard closed. A new case, "does not hold the layer closed for a scroll-driven animation on an ancestor", fails on the previous head and passes here, and the other animation cases carry timeline: document.timeline in their fakes.
  • One predicate: exitAnimations and the settle wait now both call endsOnItsOwn, which is running and an endTime that is not Infinity. The wait had used the iteration count; both use the end time now.

The Layer, HoverCard, Tooltip, Popover and DropdownMenu suites pass (1,074 of 1,075; the one failure is layerViewportInset.test.ts, the Windows path assertion), and typecheck and strict lint are clean. Only useLayer.tsx and its test changed. It still needs ci:run and a re-review or dismissal of cixzhang's earlier change request.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed, for one release-note fix: the controlled Tooltip and HoverCard in a Dialog now sit 4 px from their trigger in Chromium and WebKit (325–460 px away on the base), and a Tooltip under a scroll-driven ancestor animation now opens beside its trigger instead of staying hidden.

  • Regression: the latest push stopped the settle wait from waiting on scroll- and view-driven animations (packages/core/src/Layer/useLayer.tsx line 964), but .changeset/hovercard-tooltip-controlled-open-anchoring.md line 15 and the description still say a boxless trigger waits "for any running, finite animation on an ancestor" with only paused and infinite ones excepted, so please say it waits for running animations on the document timeline that end on their own, on the trigger or an ancestor, and that paused, infinite, and scroll- or view-driven animations are not waited on.

Both points from the last review are fixed, and the new scroll-driven unit case fails against the previous push and passes here. cixzhang's earlier change request is still open and needs a re-review or a dismissal. CI has not run on this head yet, so a maintainer needs to add the ci:run label.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
…ment-timeline wait

The changeset and the comments still described a wait on any running finite animation. They now say it waits on running animations on the document timeline that end on their own, and not on paused, infinite, or scroll- and view-driven ones.
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Fixed in the head above, with no code change. The changeset and the description now say the wait is for any running animation on the document timeline that ends on its own, on the trigger or an ancestor, and that paused, infinite, and scroll- or view-driven animations are not waited on. The three comments in useLayer.tsx follow your suggestions: the endsOnItsOwn doc, the waitForAncestorAnimations opening sentence (now one frame later, every running animation that ends on its own on the document timeline), and the paragraph naming what the wait skips. The Layer tests pass. It still needs ci:run and a re-review or dismissal of cixzhang's earlier change request.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes are needed from you at this head; approval now waits on an owner step and on CI.

  • The controlled Tooltip and HoverCard in a Dialog now open 4 px from their trigger in Chromium and WebKit, where main leaves them 325–460 px away in the corner, and a press on a rendered trigger still opens in the same task.
  • The changeset now describes the settle wait the code runs.

cixzhang's earlier change request is still open, so it needs a re-review or a dismissal before this pull request can be approved; both of its points look addressed at this head. CI has not run on this head yet: a maintainer needs to add the ci:run label. The inline notes are optional comment and test suggestions.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 6, 2026
@cixzhang cixzhang closed this Nov 6, 2026
@cixzhang cixzhang reopened this Nov 6, 2026
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 6, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed for one CI fix; the anchoring fix itself checks out.

  • Newly live check: the required lint job fails at "Check the comment-provenance baseline" because this pull request removes the INV6 and FR4 citations and a quoted-requirement block from comments in packages/core/src/Layer/useLayer.tsx without dropping them from internal/eslint-plugin-astryx/no-comment-provenance.baseline.json; run node internal/eslint-plugin-astryx/no-comment-provenance.baseline.mjs, format the file with Prettier, and commit it.

The controlled Tooltip and HoverCard in a Dialog now sit 4 px from their trigger in Chromium and WebKit, where main leaves them 325–460 px away in the corner, and a press on a rendered trigger still opens in the same task. cixzhang's earlier change request is still open and needs a re-review or a dismissal before approval. The build, test and docsite-test jobs stopped at "CI is full" and need a re-run.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
The useLayer.tsx comments no longer cite INV6/FR4 or quote a requirement, so
the baseline drops those three sites.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes are needed from you at this head; approval now waits on an owner step and on CI.

  • The comment-provenance baseline now matches useLayer.tsx, and the required lint job passes.
  • The controlled Tooltip and HoverCard in a Dialog sit 4–5 px from their trigger in Chromium and WebKit, where main leaves them 285–460 px away at the viewport edge, and a press on a rendered trigger still opens in the same task.

cixzhang's earlier change request is still open and needs a re-review or a dismissal before this can be approved. The build, test and docsite-test jobs stopped at "CI is full" and need a re-run. Two optional suggestions, on comment wording and on one churn test, stay in their open inline threads.

[Automated review]

Resolves useLayer.tsx's imports: keeps both this branch's shared resize
and mutation observers and main's flat-tree, shadow-root and input-stream
helpers.
- The churn test records every write to the trigger's style, so it fails
  when a null-then-same-element reattach removes and re-adds the anchor
  name (main) even though the name ends up present.
- The isAnchorReady doc sits on isAnchorReady; isShownAsPopover gets its
  own line. The anchor-wait comments say "no layout box" rather than 0x0,
  the unmount note names the released anchor wait, and the contextRef
  comment keeps its reason in a few sentences.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes are needed from you at this head; approval waits on an owner step.

  • The controlled Tooltip and HoverCard in a Dialog now sit 4 px from their trigger in Chromium and WebKit, where main leaves them 285–453 px away at the viewport edge, and a press on a rendered trigger still opens in the same task.
  • The anchor-name churn test now fails against main, the earlier review threads are fixed, and CI passes.

cixzhang's earlier change request is still open and needs a re-review or a dismissal before this can be approved; a commit on the branch does not close it. Two optional comment-wording suggestions are inline.

[Automated review]

Comment on lines +1632 to +1648
// The wait is driven by signals, never by polling. Any of them re-reads `isAnchorReady`; the first that
// finds the anchor ready wins. None resolves against a boxless trigger, so
// a layer whose container gains layout much later still ends up anchored,
// not opened against a 0x0 box because a cap gave up first:
//
// - ResizeObserver: a block-level trigger gaining a box.
// - IntersectionObserver: reports a `display: inline` trigger, which
// ResizeObserver never delivers an entry for, such as the wrapper
// `<span>` of a text-only Tooltip or HoverCard. It also fires
// when a hidden ancestor is displayed.
// - The enclosing `<dialog>`'s `open` attribute and `toggle` event: the
// trigger can have a box before the dialog is modal (see
// `isAnchorReady`), and a popover-shown dialog never sets `open`.
//
// A ResizeObserver stub that fires synchronously (several component tests
// use one) resolves exactly as fast as it always did. Environments with no
// real layout ever are excluded before this point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (comments): two parts of this block describe earlier versions rather than the code: "not opened against a 0x0 box because a cap gave up first" and "resolves exactly as fast as it always did". Keeping only the rule reads better, for example:

// The wait is driven by signals and polls nothing. Each signal re-reads
// `isAnchorReady`, and the first that finds the anchor ready wins. None
// resolves against a trigger with no layout box, so a trigger that gets its
// box late still anchors:

The closing paragraph can go, since the no-layout-engine case returns above it. Line 1632 (and 1591, 1613–1615) also runs past the 80 columns the rest of the file wraps at.

* `Animation.finished` never resolves for these, so waiting on them would
* block a layer that anchors to them from ever opening.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (comments): this blank line detaches the JSDoc above from waitForAncestorAnimations, so editors show no doc on the function. Dropping it reattaches them.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes are needed from you at this head; approval waits on an owner step.

  • The controlled Tooltip and HoverCard in a Dialog sit 4 px from their trigger in Chromium and WebKit, where main leaves them 285–452 px away at the viewport edge, and a press on a rendered trigger still opens in the same task.
  • The latest merge of main leaves this pull request's own changes as they were; the Layer, Tooltip, HoverCard, Popover and Dialog tests, strict lint and the comment-provenance baseline check pass with it.

cixzhang's earlier change request is still open and needs cixzhang's re-review or a dismissal before this can be approved; a commit or merge on the branch does not close it. The two optional comment-wording threads from the last review are still open.

[Automated review]

@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 1f0f5d8

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Posted by Cindy's agent on her behalf.) Engineering-owner approval at this exact head; it supersedes my 09-09 change request. The review-outcomes table in the PR body shows both points fixed here: the controlled Tooltip and HoverCard in a Dialog open at their trigger in real Chromium and WebKit, with readiness kept in the Layer lifecycle (no caller-level timing helper), and the shared test setup is back to main with TabList unchanged. Thanks for the contribution!

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. A Tooltip or HoverCard held open inside a Dialog now opens 4 px from its trigger in Chromium, where main leaves it 441–453 px away in a viewport corner, and a trigger that is already laid out still opens in the same task as the press.

  • The new useLayer cases fail against main's useLayer.tsx and pass here, and CI is green at this head.
  • Two optional comment-wording threads in useLayer.tsx remain open (the blank line above waitForAncestorAnimations, and two phrases in the show() comment that describe earlier versions); neither blocks.

Thanks for seeing this through.

[Automated review]

This branch was successfully deployed

1 active deployment
Preview — 1f0f5d8b Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] A controlled (isOpen) HoverCard renders in the page corner, not anchored to its trigger

2 participants