Skip to content

Commit ca25fd6

Browse files
authored
⬆️ chore(deps): upgrade @base-ui/react to 1.8.0 (#644)
1.7.0 removed `store` from the public handle typings and made Root attach its store in an effect, so PopoverGroup/TooltipGroup now follow the live store through `subscribeStore` instead of capturing `handle.store` once. 1.7.0 also regressed hover handoff between detached triggers wrapping antd Buttons (mui/base-ui#5416); the fix (mui/base-ui#5442) shipped in 1.8.0. Claude-Session: https://claude.ai/code/session_01M6WjoVy32S48WjQnMsFDuB
1 parent 384b444 commit ca25fd6

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
},
157157
"dependencies": {
158158
"@ant-design/cssinjs": "^2.1.2",
159-
"@base-ui/react": "1.6.0",
159+
"@base-ui/react": "1.8.0",
160160
"@dnd-kit/core": "^6.3.1",
161161
"@dnd-kit/modifiers": "^9.0.0",
162162
"@dnd-kit/sortable": "^10.0.0",

‎src/base-ui/Popover/PopoverGroup.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type FC, type ReactNode, useCallback, useMemo, useRef, useState } from
66
import {
77
useDestroyOnInvalidActiveTriggerElement,
88
useHidePopupWhenPositionerAtOrigin,
9+
usePopupHandleStore,
910
} from '@/utils/destroyOnInvalidActiveTriggerElement';
1011
import { parseTrigger } from '@/utils/parseTrigger';
1112
import { placementMap } from '@/utils/placement';
@@ -82,10 +83,11 @@ const PopoverGroup: FC<PopoverGroupProps> = ({
8283
[],
8384
);
8485

85-
useDestroyOnInvalidActiveTriggerElement(handle.store, destroy, {
86+
const store = usePopupHandleStore(handle);
87+
useDestroyOnInvalidActiveTriggerElement(store, destroy, {
8688
enabled: !disableDestroyOnInvalidTrigger,
8789
});
88-
useHidePopupWhenPositionerAtOrigin(handle.store, { enabled: !disableZeroOriginGuard });
90+
useHidePopupWhenPositionerAtOrigin(store, { enabled: !disableZeroOriginGuard });
8991

9092
const portalContainer = usePopoverPortalContainer();
9193

‎src/base-ui/Tooltip/TooltipGroup.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useAppElement } from '@/ThemeProvider';
99
import {
1010
useDestroyOnInvalidActiveTriggerElement,
1111
useHidePopupWhenPositionerAtOrigin,
12+
usePopupHandleStore,
1213
} from '@/utils/destroyOnInvalidActiveTriggerElement';
1314
import { placementMap } from '@/utils/placement';
1415

@@ -52,10 +53,11 @@ const TooltipGroup: FC<TooltipGroupProps> = ({
5253
const floatingLayerContainer = useFloatingLayer();
5354
const portalContainer = floatingLayerContainer ?? appElement;
5455

55-
useDestroyOnInvalidActiveTriggerElement(handle.store, destroy, {
56+
const store = usePopupHandleStore(handle);
57+
useDestroyOnInvalidActiveTriggerElement(store, destroy, {
5658
enabled: !disableDestroyOnInvalidTrigger,
5759
});
58-
useHidePopupWhenPositionerAtOrigin(handle.store, { enabled: !disableZeroOriginGuard });
60+
useHidePopupWhenPositionerAtOrigin(store, { enabled: !disableZeroOriginGuard });
5961

6062
return (
6163
<TooltipGroupHandleContext value={handle}>

‎src/utils/destroyOnInvalidActiveTriggerElement.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLayoutEffect } from 'react';
1+
import { useCallback, useLayoutEffect, useSyncExternalStore } from 'react';
22

33
type PopupStoreLike = {
44
// Base UI store's `useState` has a strongly-typed key union; we keep it loose here on purpose.
@@ -10,6 +10,24 @@ type PopupStoreLike = {
1010
useState?: (...args: any[]) => unknown;
1111
};
1212

13+
// Base UI 1.7+ strips `store`/`subscribeStore` from the handle's public typings, but detached
14+
// triggers still rely on them at runtime: the handle points at an inert fallback store until a
15+
// Root attaches in an effect, so the store must be read through a subscription, not captured once.
16+
type PopupHandleLike = {
17+
store: PopupStoreLike;
18+
subscribeStore: (listener: () => void) => () => void;
19+
};
20+
21+
export const usePopupHandleStore = (handle: object): PopupStoreLike => {
22+
const typedHandle = handle as PopupHandleLike;
23+
const subscribe = useCallback(
24+
(listener: () => void) => typedHandle.subscribeStore(listener),
25+
[typedHandle],
26+
);
27+
const getSnapshot = useCallback(() => typedHandle.store, [typedHandle]);
28+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
29+
};
30+
1331
const isInvalidTriggerElement = (el: Element | null): boolean => {
1432
if (!el) return true;
1533

0 commit comments

Comments
 (0)