[tooltip][preview-card] Deduplicate popup store open-change logic#5038
Draft
atomiks wants to merge 1 commit into
Draft
[tooltip][preview-card] Deduplicate popup store open-change logic#5038atomiks wants to merge 1 commit into
atomiks wants to merge 1 commit into
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,311.00 ms -143.24 ms(-9.8%) | Renders: 50 (+0) | Paint: 1,986.56 ms -197.83 ms(-9.1%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
5156026 to
25df288
Compare
✅ 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 deduplicates the nearly identical setOpen logic in TooltipStore and PreviewCardStore by extracting the shared open-change sequence into a reusable applyPopupOpenChange helper in the popup store utilities.
Changes:
- Added
applyPopupOpenChangeto centralize:onOpenChangenotification + cancellation, floating-root dispatch,reason→instantTypemapping,setPopupOpenState, and hoverflushSync. - Updated
TooltipStore.setOpenandPreviewCardStore.setOpento delegate toapplyPopupOpenChange, passing store-specific differences viaextraStateandonBeforeDispatch. - Hardened PreviewCard hover inline-rect capture by guarding against a missing
event.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react/src/utils/popups/popupStoreUtils.ts | Introduces shared applyPopupOpenChange helper and moves flushSync dependency into popup utilities. |
| packages/react/src/tooltip/store/TooltipStore.ts | Replaces duplicated setOpen sequence with applyPopupOpenChange + tooltip-specific openChangeReason state. |
| packages/react/src/preview-card/store/PreviewCardStore.ts | Replaces duplicated setOpen sequence with applyPopupOpenChange + preview-card inline-rect capture hook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Extract the shared `setOpen` sequence (reason classification, instantType mapping, prevent-unmount handling, floating dispatch, synchronous hover flush) into `applyPopupOpenChange`. TooltipStore and PreviewCardStore now supply only their differences via `extraState` (last change reason) and `onBeforeDispatch` (inline-rect capture, with a guard against a missing event).
25df288 to
c747e8f
Compare
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.
TooltipStore.setOpenandPreviewCardStore.setOpenwere ~85% identical. This extracts the shared sequence —onOpenChangenotification, cancellation, floating-root dispatch, reason →instantTypemapping,setPopupOpenState, and the synchronous hoverflushSync— intoapplyPopupOpenChange. Each store supplies only its differences viaextraState(Tooltip's last change reason) andonBeforeDispatch(PreviewCard's inline-rect capture, guarded against a missing event). Behavior is preserved, and the duplicated runtime logic is removed from the bundle.Verification
pnpm typescript,pnpm eslint, and the jsdom Tooltip / PreviewCard / popupStoreUtils suites all green.