Repository navigation
Description
Problem
XDSText imports useXDSTooltip at the module level for truncation tooltips (hasTruncateTooltip prop). This pulls in the entire layer/popover system:
XDSText → useXDSTooltip → useXDSLayer → useXDSPopover
Cost: ~12.2 KB minified (9.6KB shared layer hooks + 2.6KB XDSTooltip component). This is 34% of the component chunk, loaded on every page that uses XDSText — even if no text is truncated.
How we measured
Built the theme builder app in xds_sandbox and analyzed the webpack chunks:
Chunk 585 (28KB total):
Layer/popover preamble: ~9,585 bytes (34% of chunk)
XDSTooltip: ~2,624 bytes
XDSText: ~3,367 bytes
XDSButton: ~2,309 bytes
XDSSpinner: ~2,668 bytes
...rest (stacks, badge, divider, heading)
Options
Option A: Native title attribute (simplest, not styleable)
<span title={isTruncated ? fullText : undefined}>
{children}
</span>Zero bundle cost but the tooltip is browser-styled and can't be themed. For "see the full string" this is arguably fine, but it looks out of place in a polished UI.
Option B: Lazy-load the styled tooltip
const TruncationTooltip = React.lazy(
() => import('./TruncationTooltip')
);
// Only loads the 12KB layer system when text actually overflows
{isTruncated ? (
<Suspense fallback={<span title={fullText}>{children}</span>}>
<TruncationTooltip text={fullText}>{children}</TruncationTooltip>
</Suspense>
) : children}Keeps the styled tooltip, defers the cost until needed. The fallback uses native title so there's no gap. But still loads 12KB when any text truncates.
Option C: Move truncation tooltip to composition (cleanest)
Remove the built-in truncation tooltip from XDSText entirely. Consumers opt in via composition:
// No tooltip (default — zero cost)
<XDSText maxLines={1}>{longText}</XDSText>
// With tooltip (consumer explicitly imports XDSTooltip)
<XDSTooltip content={longText}>
<XDSText maxLines={1}>{longText}</XDSText>
</XDSTooltip>This is the cleanest for bundle size — XDSText never imports the layer system. The cost is only paid by consumers who actually want styled truncation tooltips. But it changes the API and removes a convenience feature.
Option D: Hybrid — title by default, opt-in styled
// Default: native title (zero bundle cost)
<XDSText maxLines={1}>Long text...</XDSText>
// Opt-in: consumer wraps with XDSTooltip
<XDSTooltip content={fullText}>
<XDSText maxLines={1} hasTruncateTooltip={false}>
{longText}
</XDSText>
</XDSTooltip>Other lazy-loading opportunities
| Component | Dependency | Size | Trigger |
|---|---|---|---|
| XDSButton | XDSSpinner | ~2.7 KB | isLoading prop |
| XDSCheckboxInput | XDSIcon | ~3.1 KB | Always (check mark) |
| XDSTextInput | XDSField system | ~8.0 KB | Always (field wrapper) |
Total lazifiable: ~26 KB out of ~59 KB (44% of XDS component JS).
Context
Discovered while comparing bundle sizes between an XDS-based theme builder (~59KB component JS) and an identical raw HTML + StyleX version (~34KB). See discussion in #155.
Activity
cixzhang commentedon Feb 19, 2026
Preferred approach: React.lazy with ref-based anchoring
The concern with wrapping
XDSTooltiparound children insideSuspenseis that when the lazy component resolves, React remounts the children (the text content). This causes a visible flash and loses any DOM state.Solution: Modify
XDSTooltipto support a ref-based anchor mode where it renders as a sibling rather than wrapping children:This way:
fallback={null}just means no tooltip for ~100ms while the chunk loads (imperceptible)useXDSTooltipalready supports ref-based anchoring internally — it just needs to be exposed as a prop onXDSTooltipalongside the existing children-based mode.perf(text): lazy-load truncation tooltip to reduce bundle size
perf(text): lazy-load truncation tooltip to reduce bundle size (#158)
perf(text): lazy-load truncation tooltip to reduce bundle size (#158)
perf(text): lazy-load truncation tooltip to reduce bundle size (#158)