Skip to content

Commit 073ffb6

Browse files
authored
fix(core): hide stale panes when switching docks in popup mode (#475)
1 parent 9ab8691 commit 073ffb6

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

packages/core/src/client/webcomponents/components/dock/DockPanel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { DockLayout } from './dock-layout'
66
import { useElementBounding, useWindowSize } from '@vueuse/core'
77
import { computed, onMounted, reactive, ref, toRefs, useTemplateRef } from 'vue'
88
import { getEntryGroup } from '../../state/dock-settings'
9-
import { useIframePanes } from '../../utils/useIframePanes'
9+
import { getEntryPaneKey, useIframePanes } from '../../utils/useIframePanes'
1010
import ViewEntry from '../views/ViewEntry.vue'
1111
import { DEFAULT_DOCK_LAYOUT, resolveDockAnchor } from './dock-layout'
1212
import { openDockContextMenu } from './DockContextMenu'
@@ -36,7 +36,7 @@ const mousePosition = reactive({ x: 0, y: 0 })
3636
3737
const dockPanel = useTemplateRef<HTMLDivElement>('dockPanel')
3838
const viewsContainer = useTemplateRef<HTMLElement>('viewsContainer')
39-
const panes = useIframePanes(viewsContainer, context.panel)
39+
const panes = useIframePanes(viewsContainer, context.panel, () => getEntryPaneKey(selected.value))
4040
4141
function openContextMenu(e: MouseEvent) {
4242
if (!dockPanel.value)

packages/core/src/client/webcomponents/components/dock/DockStandalone.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { DocksContext } from '@vitejs/devtools-kit/client'
33
import { computed, useTemplateRef, watch } from 'vue'
44
import { getEntryGroup } from '../../state/dock-settings'
5-
import { useIframePanes } from '../../utils/useIframePanes'
5+
import { getEntryPaneKey, useIframePanes } from '../../utils/useIframePanes'
66
import { useIsRpcTrusted } from '../../utils/useIsRpcTrusted'
77
import CommandPalette from '../command-palette/CommandPalette.vue'
88
import Confirm from '../display/Confirm.vue'
@@ -20,7 +20,7 @@ const props = defineProps<{
2020
2121
const context = props.context
2222
const viewsContainer = useTemplateRef<HTMLElement>('viewsContainer')
23-
const panes = useIframePanes(viewsContainer, context.panel)
23+
const panes = useIframePanes(viewsContainer, context.panel, () => getEntryPaneKey(context.docks.selected))
2424
2525
const isRpcTrusted = useIsRpcTrusted(context, (isTrusted) => {
2626
if (!isTrusted) {

packages/core/src/client/webcomponents/utils/useIframePanes.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
12
import type { DocksPanelContext } from '@vitejs/devtools-kit/client'
23
import type { IframePanes } from 'iframe-pane'
34
import type { ShallowRef } from 'vue'
45
import { createIframePanes } from 'iframe-pane'
56
import { markRaw, onScopeDispose, shallowRef, watch } from 'vue'
67

8+
export function getEntryPaneKey(entry: DevToolsDockEntry | null | undefined): string | null {
9+
if (!entry)
10+
return null
11+
return entry.type === 'iframe' ? (entry.frameId ?? entry.id) : entry.id
12+
}
13+
714
/**
815
* Own an {@link IframePanes} manager for a dock shell, parking its persistent
916
* iframe/element panes in the given overlay container.
@@ -18,6 +25,7 @@ import { markRaw, onScopeDispose, shallowRef, watch } from 'vue'
1825
export function useIframePanes(
1926
container: Readonly<ShallowRef<HTMLElement | undefined | null>>,
2027
panel?: DocksPanelContext,
28+
getActiveKey?: () => string | null,
2129
): Readonly<ShallowRef<IframePanes | undefined>> {
2230
const panes = shallowRef<IframePanes>()
2331

@@ -32,6 +40,19 @@ export function useIframePanes(
3240
{ immediate: true, flush: 'post' },
3341
)
3442

43+
if (getActiveKey) {
44+
watch(
45+
getActiveKey,
46+
(activeKey) => {
47+
panes.value?.list().forEach((pane) => {
48+
if (pane.id !== activeKey)
49+
pane.hide()
50+
})
51+
},
52+
{ flush: 'post' },
53+
)
54+
}
55+
3556
if (panel) {
3657
// A panel move changes its box position without resizing the target, so the
3758
// shared ResizeObserver/scroll listeners never fire — re-sync explicitly.

0 commit comments

Comments
 (0)