@@ -542,11 +542,10 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
542
542
// If children is not provided or is a render function, return it as-is
543
543
if ( ! children || typeof children === 'function' ) return children ;
544
544
545
- // When the popover is **closed**, reuse the cached order if we have it to
546
- // avoid unnecessary reflows. If we don't have a cache yet (first open),
547
- // fall through to compute the sorted order so the very first render is
548
- // already correct.
549
- if ( ! isPopoverOpen && cachedChildrenOrder . current ) {
545
+ // Reuse the cached order if we have it. We only want to compute the sorted
546
+ // order once per pop-over opening session. The cache is cleared when the
547
+ // pop-over closes so the next opening can recompute.
548
+ if ( cachedChildrenOrder . current ) {
550
549
return cachedChildrenOrder . current ;
551
550
}
552
551
@@ -695,8 +694,9 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
695
694
const getSortedItems = useCallback ( ( ) => {
696
695
if ( ! items ) return items ;
697
696
698
- // Reuse cached order when popover is closed to avoid needless re-renders
699
- if ( ! isPopoverOpen && cachedItemsOrder . current ) {
697
+ // Reuse the cached order if we have it. We only compute the sorted array
698
+ // once when the pop-over is opened. Cache is cleared on close.
699
+ if ( cachedItemsOrder . current ) {
700
700
return cachedItemsOrder . current ;
701
701
}
702
702
@@ -836,10 +836,11 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
836
836
if ( state . isOpen !== isPopoverOpen ) {
837
837
setIsPopoverOpen ( state . isOpen ) ;
838
838
if ( ! state . isOpen ) {
839
- // Popover just closed – preserve the current sorted order so the
840
- // fade-out animation keeps its layout unchanged. We only need to
841
- // record the latest selection for the next session.
839
+ // Popover just closed – record the latest selection for the next opening
840
+ // and clear the cached order so the next session can compute afresh.
842
841
selectionsWhenClosed . current = { ...latestSelectionRef . current } ;
842
+ cachedChildrenOrder . current = null ;
843
+ cachedItemsOrder . current = null ;
843
844
}
844
845
}
845
846
} , [ state . isOpen , isPopoverOpen ] ) ;
0 commit comments