[tooltip][preview-card] Small cleanups and comment fixes#5039
Open
atomiks wants to merge 1 commit into
Open
Conversation
- Memoize the per-trigger `safePolygon()` instance (it captures a timer, so it must not be shared) instead of allocating one per render. - Collapse TooltipProvider's two memos into one; tighten previousInstantTypeRef's type; flatten nested `if (open)` blocks. - Move/correct several comments (TooltipRoot instant-animation rationale, the PreviewCard reposition-on-open effect) and fix the PreviewCardPopup test title.
Bundle size
PerformanceTotal duration: 1,277.17 ms -177.08 ms(-12.2%) | Renders: 50 (+0) | Paint: 1,917.67 ms -266.72 ms(-12.2%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR makes small, behavior-preserving cleanups across Tooltip and Preview Card, primarily reducing per-render allocations and improving clarity in code comments/tests.
Changes:
- Memoizes
safePolygon()per trigger instance in Tooltip/Preview Card triggers to avoid allocating a new close-handler on every render. - Simplifies Tooltip provider memoization and tightens
previousInstantTypeReftyping; flattens redundant nested conditionals in Tooltip/Preview Card roots. - Fixes/moves clarifying comments and corrects the
PreviewCardPopuptest suite title.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/tooltip/trigger/TooltipTrigger.tsx | Keeps a stable per-trigger safePolygon() close handler instead of recreating it per render. |
| packages/react/src/tooltip/root/TooltipRoot.tsx | Ref typing tightened and small control-flow simplification; comment moved for clarity. |
| packages/react/src/tooltip/provider/TooltipProvider.tsx | Collapses two useMemos into one while preserving memoization behavior. |
| packages/react/src/preview-card/trigger/PreviewCardTrigger.tsx | Keeps a stable per-trigger safePolygon() close handler instead of recreating it per render. |
| packages/react/src/preview-card/root/PreviewCardRoot.tsx | Flattens nested if block when clearing payload on open without an active trigger. |
| packages/react/src/preview-card/positioner/PreviewCardPositioner.tsx | Clarifies the rationale for re-running positioning after open via comment. |
| packages/react/src/preview-card/popup/PreviewCardPopup.test.tsx | Fixes the describe label to match PreviewCard.Popup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Low-risk, behavior-preserving cleanups in Tooltip and Preview Card.
Changes
safePolygon()instance (it captures aTimeout, so it must be per-instance, not shared) instead of allocating one per render.TooltipProvider's twouseMemos into one; tightenpreviousInstantTypeRef's type; flatten nestedif (open)blocks in both roots.TooltipRootinstant-animation rationale, the Preview Card reposition-on-open effect) and fix thePreviewCardPopuptest's copy-pasteddescribetitle.Verification
pnpm typescript,pnpm eslint, jsdom Tooltip / PreviewCard all green.