Skip to content

Commit 86375d3

Browse files
antfubotSaKaNa-Y
andauthored
fix(hub-ui): observe dock sidebar size in the popup's own realm (#218)
Co-authored-by: SaKaNa-Y <185575200+SaKaNa-Y@users.noreply.github.com>
1 parent e3c6fe7 commit 86375d3

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

packages/hub-ui/src/client/components/dock/DockGroupSidebar.vue

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import type { DevframeDockEntry, DevframeViewGroup } from '@devframes/hub'
33
import type { DocksContext } from '@devframes/hub/client'
4-
import { useElementBounding, watchDebounced } from '@vueuse/core'
5-
import { computed, h, ref, useTemplateRef } from 'vue'
4+
import { watchDebounced } from '@vueuse/core'
5+
import { computed, h, ref, useTemplateRef, watch } from 'vue'
66
import { deriveSidebarCapacity, docksSplitGroupsWithCapacity, getGroupMembersGrouped } from '../../state/dock-settings'
77
import { sharedStateToRef } from '../../state/docks'
88
import { setDocksSidebarOverflowPanel, setFloatingTooltip, useDocksSidebarOverflowPanel } from '../../state/floating-tooltip'
@@ -36,7 +36,29 @@ const memberGroups = computed(() => getGroupMembersGrouped(
3636
))
3737
3838
const sidebar = useTemplateRef<HTMLDivElement>('sidebar')
39-
const { height: frameHeight } = useElementBounding(sidebar)
39+
40+
// Bind the ResizeObserver via the sidebar element's own document/window
41+
// rather than a global one: in popup dock mode the sidebar renders inside
42+
// the popup's own realm, and `useElementBounding`'s window-level resize
43+
// listener only fires for the host page, so the rail wouldn't collapse or
44+
// restore until the mouse moved back into the host page.
45+
const frameHeight = ref(0)
46+
watch(sidebar, (el, _prev, onCleanup) => {
47+
if (!el) {
48+
frameHeight.value = 0
49+
return
50+
}
51+
const ResizeObserverCtor = el.ownerDocument?.defaultView?.ResizeObserver ?? globalThis.ResizeObserver
52+
if (!ResizeObserverCtor)
53+
return
54+
const observer = new ResizeObserverCtor(([entry]) => {
55+
if (!entry)
56+
return
57+
frameHeight.value = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height
58+
})
59+
observer.observe(el)
60+
onCleanup(() => observer.disconnect())
61+
}, { immediate: true, flush: 'post' })
4062
4163
const totalItems = computed(() => memberGroups.value.reduce((acc, [, items]) => acc + items.length, 0))
4264

0 commit comments

Comments
 (0)