Skip to content

perf(Button): load the tooltip layer only on the first intent - #11570

Closed
cixzhang wants to merge 3 commits into
mainfrom
perf/button-tooltip-lazy
Closed

cixzhang wants to merge 3 commits into
mainfrom
perf/button-tooltip-lazy

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

People on a page whose Buttons and IconButtons have no tooltip download less JavaScript. Before this change, every Button carried the tooltip hook and the layer runtime, whether or not it had a tooltip. Now that code loads on the first hover, focus or press of a Button that has a tooltip.

First-load size of the public entry (esbuild over Core's Babel build with Core's package.json sideEffects list, minified ESM, every bare import external; gzip at level 9):

Entry Before (min / gzip) After (min / gzip) Change (min / gzip)
Button 146.0 KB / 50.2 KB 96.7 KB / 33.9 KB −49.3 KB / −16.3 KB
IconButton 146.1 KB / 50.3 KB 96.8 KB / 34.0 KB −49.3 KB / −16.3 KB
Banner 152.2 KB / 52.3 KB 102.9 KB / 36.0 KB −49.2 KB / −16.3 KB
ToggleButton 236.3 KB / 77.2 KB 187.6 KB / 61.1 KB −48.7 KB / −16.1 KB

17 of the 169 subpath entries drop by more than 1 KB gzip (Toast, Button, IconButton, Stepper, Banner, Calendar, ToggleButton, CodeBlock, TopNav, MobileNav, AlertDialog, SideNav, AppShell, Popover, MoreMenu, DropdownMenu, Chat).

Cost: an entry that still loads the tooltip hook through another path carries the small deferral hook on top, +0.6 to +0.9 KB gzip (for example TextInput +0.7 KB, Pagination +0.7 KB, Table +0.9 KB). The form fields are that other path; #10059 tracks them, and a follow-up pull request moves them onto the same hook, which removes this cost.

The import-boundaries check (its own build: React external, default gzip) prints Button and IconButton eager size 61.0 KB → 45.1 KB (−15.9 KB), and the Button/Button → Tooltip/useTooltip crossing is gone.

Intended invariant

architecture:component-import-boundaries INV1–INV6: a surface revealed by interaction loads on first intent; the trigger contract is complete before load; an intent made during the load is answered once; the load moves nothing; a failed load leaves the page working. component:Button FR12 (the tooltip describes the Button unless it repeats the name) and FR17 (refs) stay as they are.

Change

  • hooks/useDeferredTooltip.tsx (new, internal, not exported): the trigger contract of an optional tooltip. It returns a ref for the trigger, the id of a hidden description, and render functions for the description and the surface. Native listeners on the trigger (mouseenter, pointerenter, pointerdown, pointercancel, click, focusin, focusout) start the load and hold the latest intent. They recognize no gesture: the click after a touch or pen press is the tap. The surface mounts only after an intent on that trigger, so server and hydrating markup never hold it. It is not Button-specific; the form-field follow-up reuses it.
  • Tooltip/DeferredTooltip.tsx (new): the surface that the hook loads with import(). It runs useTooltip and hands it the held intent through the existing TooltipPresentInterestContext, the same route the truncation tooltip of Text uses.
  • Tooltip/useTooltip.tsx, Tooltip/tooltipPresentInterest.ts: a held hover carries its start time, so the show delay counts from the pointer's entry, not from the load.
  • Button/Button.tsx: uses the hook instead of useTooltip. When the tooltip describes the Button, aria-describedby names hidden text inside the Button element. It is inside, not a sibling, because a sibling would change the :nth-last-child that ButtonGroup and InputGroup use to round their last member.
  • Records: component:Button FR12 and a new PR2; architecture:component-import-boundaries loses the Button allowlist row, its INV1 gap names the remaining paths, and its owning code names the two new modules and why useTooltip cannot do their job.

Declared difference

  • A Button without tooltip renders the same DOM, server and client (compared across 11 cases: variants, sizes, icon, disabled, loading, link, children, caller aria-describedby, IconButton, ButtonGroup).
  • A Button with a tooltip that describes it has a hidden span inside it that holds the tooltip text. aria-describedby names that span from the server render on, so the description no longer names an element that is missing until hydration. The accessible name and description are unchanged.
  • The closed tooltip layer is not in the document until the first hover, focus or press. A hover during the load waits the normal 200 ms delay counted from the entry, so the first show is no slower unless the load takes longer than the delay. Keyboard focus and a tap on a disabled Button open the tooltip when the module loads.
  • A test that reads the closed tooltip right after render now hovers first. A test that finds the tooltip by its text can also find the hidden description; find it by role tooltip. The Changeset says so.

Evidence

  • Failure before the change: the new Button.tooltipLoad.test.tsx fails 7 of 17 cases on the base Button: the tooltip hook and layer load for a Button and an IconButton without tooltip and before any intent, server markup names a description that is not in it, and a failed load is not handled.
  • Success after the change: all 17 pass. They cover no load without tooltip or before an intent; hidden description in server markup and unchanged after load; hover during the load shown when the delay from the entry ends (not 1 ms earlier, not later); hover that outlasts the load shown at once; leave, mouse press, blur and a touch scroll during the load drop the intent; keyboard focus and a tap on a disabled Button answered once, the tap with its outside dismissal; a tap on an enabled Button keeps its action; a failed load keeps the Button working, warns once, and the next intent loads again; a link Button that becomes a <button> keeps its tooltip; IconButton the same.
  • Product/runtime behavior verified unchanged: Button, IconButton, ButtonGroup, InputGroup, Tooltip, Layer, Text, Heading, Banner, CodeBlock, Pagination, Field, Timestamp and RichText unit tests pass (126 files, 2982 tests). Tests that read the closed layer at render now hover first: ButtonGroup trailing radius, Layer touchTriggerTargets, Tooltip roving toolbar, Banner, CodeBlock, Pagination, InputClearButton, Timestamp, RichText code block header, portal host and link toolbar.
  • CI impact: none.

Scope

Components: Button, IconButton, Tooltip (internal deferral surface), hooks (internal)

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Overlap: #11205 (touch hit areas, open) also changes Button/Button.tsx, Button.spec.md and InputClearButton.test.tsx. This change stays small in Button.tsx (the hook call, the description, and one child in each branch), so either order rebases with little work.

Merge order: this touches Tooltip and Layer modules, so it merges after #8690.

Writing rubric results

component:Button (FR12 sentence, PR2, verification rows) and architecture:component-import-boundaries (allowlist, cost note, current-state gaps, owning code):

  • R1 narration: none; each new sentence states what the system does now, in the present tense.
  • R2 research: none in the records; the size measurements are in this description only.
  • R3 evidence: the new verification rows name the test file and what it asserts, not a pull request.
  • R4 rejected alternatives: none added.
  • R5 change references: none.
  • R6 open questions: none changed.
  • R7 project status: none; the remaining tooltip crossings are stated as an INV1 gap, and its measured counts stay, marked as pending a new measurement.

Testing

  • pnpm vitest run packages/core/src/Button packages/core/src/IconButton packages/core/src/Tooltip packages/core/src/Layer packages/core/src/Text packages/core/src/Heading packages/core/src/ButtonGroup packages/core/src/InputGroup packages/core/src/Banner packages/core/src/CodeBlock packages/core/src/Pagination packages/core/src/Field packages/core/src/Timestamp packages/richtext/src: pass.
  • A full packages/core/src and packages/richtext/src run: the only other failures (CommandPalette, DateTimeInputTouch, TableLegacyIncrementalRender, TokenizerBottomSheet, MultiSelector listbox, postinstall) fail the same way on the base commit on the same machine (timeouts under load).
  • tsc --noEmit -p packages/core/tsconfig.json, ESLint on the changed files, Prettier, pnpm check:knowledge, node scripts/check-component-import-boundaries.mjs --base-ref <base>: pass.
  • Browser accessibility specs for Button and Tooltip run in this pull request's CI.

Button and IconButton reached the tooltip hook and the layer runtime
statically, with or without a tooltip prop. The tooltip surface now loads
with import() on the first hover, focus or press of a Button with tooltip.
An intent made during the load is held and answered once; the hover delay
counts from the entry. The Button is described by hidden text inside it,
in server markup too, so the description does not change when the surface
loads.

The mechanism is an internal hook, useDeferredTooltip, for reuse by other
components with an optional tooltip.
@vercel

vercel Bot commented Nov 13, 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 13, 2026 7:34pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 13, 2026
@astracat-bot

astracat-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 13, 2026, 7:52 PM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 13, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 95f2ac4

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded skipped. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@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 requested. The deferral works and the record changes carry an engineering owner's approval, but five fixes remain before approval:

  • A held keyboard focus or hover survives a page scroll during the load and opens the tooltip when the code arrives, while the import-boundaries record's INV4 drops it; drop a held intent on a scroll and add that case to Button.tooltipLoad.test.tsx (packages/core/src/hooks/useDeferredTooltip.tsx:173-217).
  • createDeferredTrigger re-implements the held-intent tracker that useTruncationTooltipInterest in packages/core/src/Text/TruncationTooltip.tsx already owns, and the two have already drifted (only the new one records the hover start), so share one tracker or state in the record why the truncation tracker cannot serve Button.
  • The allowlist row for Text/TruncationTooltip to Layer/useTouchTrigger still lists a cost for Text and Heading only, but with Button's useTooltip crossing gone the check prints 4.2 KB for Button and IconButton too, so add them.
  • The changeset says a Button with a tooltip "shows it with the same delays", but the first tooltip waits for its code when the load outlasts the 200 ms delay (the test at Button.tooltipLoad.test.tsx:273 shows this), so qualify that sentence.
  • The description's counts do not reproduce: the new suite fails 5 of 17 on the base Button once Tooltip/DeferredTooltip exists there (as committed it does not load), and the listed suites pass with 131 files and 3,082 tests, so correct both.

Two optional cleanups: drop "these counts are pending a new measurement" from the INV1 gap, and drop the attachTo doc comment that restates its signature.

Claims and files checked

Claims:

  • Changeset: Button and IconButton load tooltip code only on the first hover, focus or press of a Button with a tooltip: verified (hooks/useDeferredTooltip.tsx:210-217; load tests).
  • Changeset: about 16.5 KB less gzipped JavaScript for Button: verified as an approximation (the boundaries check measures 61.2 KB to 45.3 KB at default gzip).
  • Changeset: a Button with a tooltip shows it with the same delays: false when the code loads slower than the delay (Button.tooltipLoad.test.tsx:273).
  • Changeset: the description is hidden text inside the Button from the first render: verified (server markup test).
  • Changeset: tests should find the tooltip by role: verified (Button.tsx:1114-1115).
  • Description: before this change every Button carried the tooltip hook and layer runtime: verified (base Button.tsx imports useTooltip; the base check prints the crossing).
  • Description: size table: Button, IconButton, Banner and ToggleButton drops are consistent with the check (15.7 to 16.0 KB); the Dialog row and the count of 17 entries over 1 KB were not reproduced.
  • Description: entries that still reach the tooltip hook pay 0.6 to 1.0 KB: verified (TextInput +0.8, Pagination +0.9, Table +0.8 KB).
  • Description: the check prints Button and IconButton about 61 KB to 45 KB and the Button crossing is gone: verified.
  • Description: the change keeps import-boundaries INV1 to INV6: false for INV4's scroll clause (probe).
  • Description: Button FR12 and FR17 stay as they are: verified (FR12's describing rule is unchanged; FR17 is untouched).
  • Description: native listeners recognize no gesture and the surface mounts only after an intent: verified (hooks/useDeferredTooltip.tsx:81-89, :164-217).
  • Description: the loaded surface runs the tooltip hook and replays the held intent through the existing interest context: verified (Tooltip/DeferredTooltip.tsx:48-80).
  • Description: a held hover's delay counts from the entry: verified (Tooltip/useTooltip.tsx:478-498, :824-827; test :258).
  • Description: the description sits inside the Button so the group's last-member rule holds: verified (Button.tsx:582, :1152, :1178).
  • Description: record edits to Button FR12, PR2 and the boundaries allowlist, gap and owning code: verified (diff).
  • Description: a Button without a tooltip renders the same DOM: verified (Button.tsx:1106-1123, :1184-1192).
  • Description: the closed layer is absent until the first intent; keyboard focus and a tap on a disabled Button open at load: verified (tests :216, :312, :338).
  • Description: tests that read the closed layer now hover first: verified (diff).
  • Description: the new suite fails 7 of 17 on the base Button: false (5 of 17 once the surface module exists there; it does not load as committed).
  • Description: all 17 pass after the change: verified.
  • Description: the listed suites pass as 126 files and 2,982 tests: they pass; the counts are false (131 files, 3,082 tests).
  • Description: type check, ESLint, Prettier, the knowledge check and the boundaries check pass: verified.
  • Description: no CI impact: verified (no workflow changes).
  • Description: the overlapping open pull request touches the same three files: verified.

Files:

  • .changeset/button-tooltip-loads-on-intent.md: finding (timing sentence).
  • docs/architecture/component-import-boundaries.md: finding (allowlist cost); optional cleanup (measurement status).
  • docs/specs/components/Button/Button.spec.md: clear.
  • packages/core/src/Banner/Banner.test.tsx: clear.
  • packages/core/src/Button/Button.tooltipLoad.test.tsx: clear (needs the scroll case from the first finding).
  • packages/core/src/Button/Button.tsx: clear.
  • packages/core/src/ButtonGroup/ButtonGroup.test.tsx: clear.
  • packages/core/src/CodeBlock/CodeBlock.test.tsx: clear.
  • packages/core/src/Field/InputClearButton.test.tsx: clear.
  • packages/core/src/Layer/touchTriggerTargets.test.tsx: clear.
  • packages/core/src/Pagination/Pagination.test.tsx: clear.
  • packages/core/src/Timestamp/Timestamp.test.tsx: clear.
  • packages/core/src/Tooltip/DeferredTooltip.tsx: clear.
  • packages/core/src/Tooltip/Tooltip.test.tsx: clear.
  • packages/core/src/Tooltip/tooltipPresentInterest.ts: clear.
  • packages/core/src/Tooltip/useTooltip.tsx: clear.
  • packages/core/src/__tests__/deferredTooltip.ts: clear.
  • packages/core/src/hooks/useDeferredTooltip.tsx: findings (scroll, shared tracker); optional cleanup (doc comment).
  • packages/richtext/src/CodeBlockHeaderPlugin.test.tsx: clear.
  • packages/richtext/src/RichTextEditor.portalHost.test.tsx: clear.
  • packages/richtext/src/RichTextEditorToolbarLink.test.tsx: clear.

Automated review (maintainer link)

Comment on lines +210 to +217
el.addEventListener('pointerenter', handlePointerEnter);
el.addEventListener('mouseenter', handleMouseEnter);
el.addEventListener('mouseleave', handleMouseLeave);
el.addEventListener('pointerdown', handlePointerDown);
el.addEventListener('pointercancel', handlePointerCancel);
el.addEventListener('click', handleClick);
el.addEventListener('focusin', handleFocusIn);
el.addEventListener('focusout', handleFocusOut);

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.

INV4 in docs/architecture/component-import-boundaries.md says "Leaving, blurring, a scroll, or a press elsewhere before load drops a held hover or focus." These listeners drop a held intent on mouseleave, a press on the trigger and focusout, but nothing drops it on a scroll: keyboard focus (or a hover) followed by a page scroll while the load is pending still opens the tooltip once the module arrives. Suggest dropping the held intent on a scroll of the trigger's document while one is held (a passive capture listener added in want() and removed when the surface reads the intent or the load fails), with a test beside the touch-scroll case.

Comment on lines +142 to +162
const want = (
interest: 'hover' | 'tap' | 'focus',
tapEvent: Event | null = null,
) => {
const state = interestRef.current;
if (state.isRead) {
return;
}
state.interest = interest;
state.tapEvent = tapEvent;
state.hoverStartedAt = interest === 'hover' ? performance.now() : undefined;
onWant();
load();
};

const forget = (interest: 'hover' | 'focus') => {
const state = interestRef.current;
if (!state.isRead && state.interest === interest) {
state.interest = null;
}
};

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.

This want/forget pair, the :focus-visible focus intent and the press that drops a held hover repeat useTruncationTooltipInterest in Text/TruncationTooltip.tsx (lines 98-157), which already holds intents for the same TooltipPresentInterestContext. They have already drifted: only this path sets hoverStartedAt. One tracker that both call keeps INV4 fixes in one place; otherwise the record should say why the truncation tracker cannot serve Button.

@@ -180,17 +180,16 @@ one pending load per module, caches a success, and resets after a failure.
| Crossing (base module → module it imports statically) | Entries that reach it | Cost, gzip | Invariant | Row leaves when |
| ----------------------------------------------------------------- | ---------------------------------------------- | ---------------------- | ---------- | ------------------------------------------------------------------------ |
| `Text/TruncationTooltip` → `Layer/useTouchTrigger` | Text, Heading, Button, IconButton, Link, Table | 4.6 KB (Text, Heading) | INV1, INV8 | the truncation tooltip's eager code carries no touch tap recognizer |

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.

With Button's useTooltip crossing gone, this crossing is now Button's and IconButton's own cost: the check prints 0.0 KB for both on the base and 4.2 KB each on the head. The note below now says only Link and Table pay nothing, so this cell should add Button and IconButton with the cost CI prints.

Comment on lines +208 to +211
status icon of TextInput, TextArea, and CheckboxList. Measured while Button
also reached it, 32 of Core's 95 component imports that are not surfaces
carried 17–24 KB of tooltip code, and 52 carried at least 1 KB; these counts
are pending a new measurement.

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: "Measured while Button also reached it ... these counts are pending a new measurement" is temporary project status. The gap's first sentence already states which imports reach the tooltip code; the measurement status can go.

return {ref, connect, interestRef};
}

/** Calls `attach` with `element` and returns its detach. */

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 (INV29): this comment restates the signature; it can go.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/revoke-spec

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 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.

Approval waits on an engineering owner's decision on the record changes, and seven fixes remain.

The component:Button FR12 sentence that puts the tooltip description in hidden text inside the Button, the new PR2 with its verification rows, and the import-boundaries owning-code entries that name useDeferredTooltip and DeferredTooltip are proposed record changes with no engineering-owner approval at this head. An engineering owner records that decision by commenting /approve-spec followed by this head's full commit SHA; the author may do so as an engineering owner.

Fixes needed before approval:

  • A held keyboard focus or hover survives a page scroll during the load and opens the tooltip when the code arrives, while the import-boundaries record's INV4 drops it, so drop a held intent on a scroll and add that case to Button.tooltipLoad.test.tsx (packages/core/src/hooks/useDeferredTooltip.tsx:210-217).
  • createDeferredTrigger re-implements the held-intent tracker that useTruncationTooltipInterest in packages/core/src/Text/TruncationTooltip.tsx already owns, and the two have drifted (only the new one records the hover start), so share one tracker or state in the record why the truncation tracker cannot serve Button.
  • Regression: now that the record approval has been withdrawn, packages/core/src/hooks/useDeferredTooltip.tsx is a new internal module used by Button that no approved record names, so it needs the same owner decision on its owning-code entry.
  • The allowlist row for Text/TruncationTooltip → Layer/useTouchTrigger still lists a cost for Text and Heading only, but with Button's useTooltip crossing gone the check prints 4.2 KB for Button and IconButton, so add them (docs/architecture/component-import-boundaries.md:182).
  • The changeset says a Button with a tooltip "shows it with the same delays", but the first tooltip waits for its code when the load outlasts the 200 ms delay (Button.tooltipLoad.test.tsx:273-284), so qualify that sentence.
  • The description's counts do not reproduce: the new suite fails 5 of 17 on the base Button once Tooltip/DeferredTooltip exists there (as committed it does not load), and the listed suites pass with 131 files and 3,082 tests.
  • Miss: the description's list of entries that drop by more than 1 KB gzip includes TopNav and SideNav, which grow by about 0.8 KB because they still reach the tooltip code through Link or their own Tooltip import, and leaves out Dialog, TabList and Breadcrumbs, which drop.

Two optional cleanups: drop "these counts are pending a new measurement" from the INV1 gap, and drop the attachTo doc comment that restates its signature.

Claims and files checked

Claims:

  • Changeset: Button and IconButton load their tooltip code only on the first hover, focus or press of a Button with a tooltip: verified (hooks/useDeferredTooltip.tsx:142-217; load tests; the boundaries check no longer finds the Button crossing).
  • Changeset: a page whose Buttons have no tooltip loads about 16 KB less gzipped code for Button: verified (boundaries check 61.2 KB to 45.3 KB; a level-9 rebuild drops 16.6 KB).
  • Changeset: a Button with a tooltip shows it with the same delays: false when the code loads slower than the delay (Button.tooltipLoad.test.tsx:273-284).
  • Changeset: the Button is described by hidden text inside it from the first render: verified (server-markup test; in Chromium the description names a present span inside the button before any intent).
  • Changeset: a test that finds the tooltip by its text can also find the hidden text, so find it by role: verified (Button/Button.tsx:1114-1115, :1152, :1178).
  • Description: before this change every Button carried the tooltip hook and layer runtime: verified (base Button.tsx imports useTooltip; the base check prints that crossing at 16.4 KB).
  • Description: size table for Button, IconButton, Banner and ToggleButton: consistent (a rebuild with the stated method drops them 16.6, 16.6, 16.6 and 16.4 KB gzip against the stated 16.3, 16.3, 16.3 and 16.1).
  • Description: 17 entries drop by more than 1 KB gzip, with their names: false (TopNav and SideNav grow by about 0.8 KB; Dialog, TabList and Breadcrumbs drop; 18 entries drop by more than 1 KB).
  • Description: entries that still reach the tooltip hook another way pay 0.6 to 0.9 KB gzip: verified (TextInput +0.8, Pagination +0.8, Table +0.9 KB).
  • Description: the boundaries check prints Button and IconButton about 61 KB to 45 KB and the Button crossing is gone: verified (61.2 and 61.3 KB to 45.3 KB).
  • Description: the change keeps the import-boundaries record's INV1 to INV6: false for INV4's scroll clause (probe).
  • Description: Button FR12 and FR17 stay as they are: verified for FR12's describing rule and FR17's refs (utils/mergeRefs.ts forwards the hook's cleanup); FR12's text gains a proposed sentence.
  • Description: the new hook's native listeners recognize no gesture and the surface mounts only after an intent: verified (hooks/useDeferredTooltip.tsx:81-89, :164-217).
  • Description: the loaded surface runs the tooltip hook and hands it the held intent through the existing interest context: verified (Tooltip/DeferredTooltip.tsx:48-80).
  • Description: a held hover's delay counts from the pointer's entry: verified (Tooltip/useTooltip.tsx:476-497, :821-827; test :258-271).
  • Description: the description sits inside the Button so the group's last-member rounding holds: verified (Button/Button.tsx:1152, :1178; ButtonGroup tests pass).
  • Description: the record edits to Button FR12, PR2 and the boundaries allowlist, gap and owning code: verified (diff).
  • Description: a Button without a tooltip renders the same markup on server and client: verified (no description, ref or surface without a tooltip, Button/Button.tsx:1105-1123, :1183-1191).
  • Description: the closed layer is absent until the first intent, and keyboard focus and a tap on a disabled Button open the tooltip at load: verified (load tests; in Chromium no tooltip element exists before an intent at this head).
  • Description: tests that read the closed layer at render now hover first: verified (diff).
  • Description: the new suite fails 7 of 17 on the base Button: false (it does not load as committed; 5 of 17 fail once the surface module exists there).
  • Description: all 17 pass after the change: verified.
  • Description: the listed suites pass as 126 files and 2,982 tests: they pass; the counts are false (131 files, 3,082 tests).
  • Description: type check, ESLint, Prettier, the knowledge check and the boundaries check pass: verified (each rerun here).
  • Description: no CI impact: verified (no workflow or build configuration changes).
  • Description: an open pull request on touch hit areas also changes the Button source, the Button record and the clear-button test: verified (it is open and touches all three); the stated merge order is a process statement.

Files:

  • .changeset/button-tooltip-loads-on-intent.md: finding (timing sentence).
  • docs/architecture/component-import-boundaries.md: finding (allowlist cost); held (owning-code entries); optional cleanup (measurement status).
  • docs/specs/components/Button/Button.spec.md: held (FR12 sentence, PR2, verification rows).
  • packages/core/src/Banner/Banner.test.tsx: clear.
  • packages/core/src/Button/Button.tooltipLoad.test.tsx: clear (needs the scroll case from the first finding).
  • packages/core/src/Button/Button.tsx: clear.
  • packages/core/src/ButtonGroup/ButtonGroup.test.tsx: clear.
  • packages/core/src/CodeBlock/CodeBlock.test.tsx: clear.
  • packages/core/src/Field/InputClearButton.test.tsx: clear.
  • packages/core/src/Layer/touchTriggerTargets.test.tsx: clear.
  • packages/core/src/Pagination/Pagination.test.tsx: clear.
  • packages/core/src/Timestamp/Timestamp.test.tsx: clear.
  • packages/core/src/Tooltip/DeferredTooltip.tsx: clear (named by the held owning-code entry).
  • packages/core/src/Tooltip/Tooltip.test.tsx: clear.
  • packages/core/src/Tooltip/tooltipPresentInterest.ts: clear.
  • packages/core/src/Tooltip/useTooltip.tsx: clear.
  • packages/core/src/__tests__/deferredTooltip.ts: clear.
  • packages/core/src/hooks/useDeferredTooltip.tsx: findings (scroll, copied tracker, unnamed internal module); optional cleanup (doc comment).
  • packages/richtext/src/CodeBlockHeaderPlugin.test.tsx: clear.
  • packages/richtext/src/RichTextEditor.portalHost.test.tsx: clear.
  • packages/richtext/src/RichTextEditorToolbarLink.test.tsx: clear.

Automated review (maintainer link)

'@astryxdesign/core': patch
---

[perf] Button and IconButton load their tooltip code only when a person first hovers, focuses or presses a Button that has a `tooltip`. A page whose Buttons have no `tooltip` loads about 16 KB less gzipped JavaScript for Button. A Button with a `tooltip` shows it with the same delays. It is described by hidden text inside the Button from the first render, so screen readers hear the description before the tooltip code loads. A test that finds the tooltip by its text can now find that hidden text too; find the tooltip by its `tooltip` role.

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.

"A Button with a tooltip shows it with the same delays" holds only while the code loads within the delay: Button.tooltipLoad.test.tsx:273-284 shows the first tooltip at load, 500 ms after the entry. Suggested wording: "A Button with a tooltip keeps its delays, counted from the pointer's entry; the first tooltip waits for its code when that code loads slower than the delay."

Comment on lines +11 to +14
* @position Internal base code for components with an optional tooltip, such
* as Button. Until the first intent, such a component carries no tooltip
* layer code. The intent made while the surface loads is held, and the
* surface answers it once by its own rules.

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.

This is a new internal module that Button imports from another folder, and the only record that names it is the owning-code entry this pull request adds to docs/architecture/component-import-boundaries.md, which has no engineering-owner approval now that the earlier one was withdrawn. An engineering owner's /approve-spec of that entry (with its reason that useTooltip cannot serve) settles it.

@cixzhang

Copy link
Copy Markdown
Contributor Author

(Posted by Cindy's agent.) Superseded by #11681. The owner decided that tooltip code loads after first paint on every page (component-import-boundaries DEC-4), not on the first hover or focus, and #11681 applies that to every Tooltip importer, Button included.

@cixzhang cixzhang closed this Nov 14, 2026
@github-actions
github-actions Bot deleted the perf/button-tooltip-lazy branch November 14, 2026 06:04

This branch was successfully deployed

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review needs:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant