Skip to content

Commit 242afaf

Browse files
antfuclaude
andcommitted
feat(self-inspect): on-demand RPC fetching with refresh button
- Fetch data lazily when switching tabs instead of all upfront - Add refresh button in the tab bar to re-fetch current tab data - Merge with latest main Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a366e1a commit 242afaf

File tree

1 file changed

+65
-16
lines changed

1 file changed

+65
-16
lines changed
Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
2+
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
3+
import type { ClientScriptInfo, DevtoolsPluginInfo } from '~~/types'
24
import { useRpc } from '#imports'
3-
import { ref } from 'vue'
5+
import { ref, shallowRef, watch } from 'vue'
46
57
const rpc = useRpc()
68
@@ -13,15 +15,53 @@ const tabs = [
1315
{ label: 'DevTools Plugins', value: 'plugins' as const, icon: 'i-ph-puzzle-piece-duotone' },
1416
] as const
1517
16-
const rpcFunctions = await rpc.value.call('devtoolskit:self-inspect:get-rpc-functions')
17-
const docks = await rpc.value.call('devtoolskit:self-inspect:get-docks')
18-
const clientScripts = await rpc.value.call('devtoolskit:self-inspect:get-client-scripts')
19-
const devtoolsPlugins = await rpc.value.call('devtoolskit:self-inspect:get-devtools-plugins')
18+
interface RpcFunctionInfo {
19+
name: string
20+
type: string
21+
cacheable: boolean
22+
hasArgs: boolean
23+
hasReturns: boolean
24+
hasDump: boolean
25+
hasSetup: boolean
26+
hasHandler: boolean
27+
}
28+
29+
const rpcFunctions = shallowRef<RpcFunctionInfo[]>()
30+
const docks = shallowRef<DevToolsDockEntry[]>()
31+
const clientScripts = shallowRef<ClientScriptInfo[]>()
32+
const devtoolsPlugins = shallowRef<DevtoolsPluginInfo[]>()
33+
34+
const loading = ref(false)
35+
36+
async function fetchCurrentTab() {
37+
loading.value = true
38+
try {
39+
switch (currentTab.value) {
40+
case 'rpc':
41+
rpcFunctions.value = await rpc.value.call('devtoolskit:self-inspect:get-rpc-functions')
42+
break
43+
case 'docks':
44+
docks.value = await rpc.value.call('devtoolskit:self-inspect:get-docks')
45+
break
46+
case 'scripts':
47+
clientScripts.value = await rpc.value.call('devtoolskit:self-inspect:get-client-scripts')
48+
break
49+
case 'plugins':
50+
devtoolsPlugins.value = await rpc.value.call('devtoolskit:self-inspect:get-devtools-plugins')
51+
break
52+
}
53+
}
54+
finally {
55+
loading.value = false
56+
}
57+
}
58+
59+
watch(currentTab, () => fetchCurrentTab(), { immediate: true })
2060
</script>
2161

2262
<template>
2363
<div flex="~ col" h-full>
24-
<div flex="~ row" border="b base" bg-base>
64+
<div flex="~ row items-center" border="b base" bg-base>
2565
<button
2666
v-for="tab in tabs"
2767
:key="tab.value"
@@ -34,19 +74,28 @@ const devtoolsPlugins = await rpc.value.call('devtoolskit:self-inspect:get-devto
3474
>
3575
<span :class="tab.icon" />
3676
{{ tab.label }}
37-
<DisplayNumberBadge
38-
:value="tab.value === 'rpc' ? rpcFunctions.length
39-
: tab.value === 'docks' ? docks.length
40-
: tab.value === 'scripts' ? clientScripts.length
41-
: devtoolsPlugins.filter(p => p.hasDevtools).length"
42-
/>
77+
</button>
78+
<div flex-1 />
79+
<button
80+
mr2 p1.5 rounded
81+
hover:bg-active
82+
op50 hover:op100
83+
transition-colors
84+
title="Refresh"
85+
:disabled="loading"
86+
@click="fetchCurrentTab"
87+
>
88+
<span i-ph-arrow-clockwise :class="loading ? 'animate-spin' : ''" />
4389
</button>
4490
</div>
4591
<div flex-1 of-auto p4>
46-
<RpcFunctionsList v-if="currentTab === 'rpc'" :functions="rpcFunctions" />
47-
<DocksList v-else-if="currentTab === 'docks'" :docks="docks" />
48-
<ClientScriptsList v-else-if="currentTab === 'scripts'" :scripts="clientScripts" />
49-
<DevtoolsPluginsList v-else-if="currentTab === 'plugins'" :plugins="devtoolsPlugins" />
92+
<div v-if="loading && !rpcFunctions && !docks && !clientScripts && !devtoolsPlugins" flex="~ items-center justify-center" h-full op50>
93+
Loading...
94+
</div>
95+
<RpcFunctionsList v-else-if="currentTab === 'rpc' && rpcFunctions" :functions="rpcFunctions" />
96+
<DocksList v-else-if="currentTab === 'docks' && docks" :docks="docks" />
97+
<ClientScriptsList v-else-if="currentTab === 'scripts' && clientScripts" :scripts="clientScripts" />
98+
<DevtoolsPluginsList v-else-if="currentTab === 'plugins' && devtoolsPlugins" :plugins="devtoolsPlugins" />
5099
</div>
51100
</div>
52101
</template>

0 commit comments

Comments
 (0)