Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,29 @@ export function useModelDropdownPopup(options: UseModelDropdownPopupOptions) {

onUnmounted(() => {
disposed = true;
const closingIdentity =
activePopupId !== null
? {
popupId: activePopupId,
windowLabel: 'popup-model-dropdown-popup',
popupSessionVersion: parsePopupSessionVersion(activePopupId),
}
: null;
const shouldHidePopup = hasActivePopupSession || isOpen.value;
cleanupFn?.();
cleanupFn = null;
activePopupId = null;
hasActivePopupSession = false;
isOpen.value = false;
onPopupSessionEnd?.();

if (!shouldHidePopup || !closingIdentity) {
return;
}

void popupManager.hide(closingIdentity).catch((error) => {
console.error('[SearchView] Failed to hide model dropdown popup on unmount:', error);
});
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,31 @@ describe('useModelDropdownPopup', () => {
mounted.unmount();
});

it('hides the current popup session on unmount when the popup is still open', async () => {
const onPopupSessionEnd = vi.fn();
const mounted = await mountComposable(() =>
useModelDropdownPopup({
getAnchorElement: () => document.createElement('button'),
getPopupData: () => createPopupData(),
isModelDropdownActive: () => true,
onModelSelect: () => undefined,
onModelSearchQueryChange: () => undefined,
onClose: () => undefined,
onPopupSessionEnd,
})
);

await mounted.result.open();
mounted.unmount();

expect(popupManager.hide).toHaveBeenCalledWith({
popupId: 'popup-model-dropdown-popup:1',
popupSessionVersion: 1,
windowLabel: 'popup-model-dropdown-popup',
});
expect(onPopupSessionEnd).toHaveBeenCalledTimes(1);
});

it('closes the active popup session with the current identity', async () => {
const onPopupSessionEnd = vi.fn();
const mounted = await mountComposable(() =>
Expand Down
Loading