Skip to content

Commit 486db15

Browse files
committed
fix: reactivity life cycle
1 parent 57f8e4c commit 486db15

File tree

7 files changed

+21
-22
lines changed

7 files changed

+21
-22
lines changed

packages/devtools-kit/src/_types/custom-tabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { VNode } from 'vue'
1+
import type { MaybeRefOrGetter, VNode } from 'vue'
22
import type { TabCategory } from './common'
33

44
export interface ModuleCustomTab {
@@ -112,7 +112,7 @@ export interface ModuleBuiltinTab {
112112
title?: string
113113
path?: string
114114
category?: TabCategory
115-
show?: () => any
115+
show?: () => MaybeRefOrGetter<any>
116116
badge?: () => number | string | undefined
117117
onClick?: () => void
118118
}

packages/devtools/client/components/docs/modules.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
Nuxt provides a module system to extend the framework core and simplify integrations. You don't need to develop everything from scratch or maintain boilerplate if there is already a Nuxt module for it. Adding Nuxt modules is possible using `nuxt.config`.
44

5+
You can explore the list of modules on [nuxt.com/modules](https://nuxt.com/modules) or install them directly inside the DevTools.
6+
57
[Learn more on the documentation](https://nuxt.com/docs/guide/concepts/modules)

packages/devtools/client/composables/state.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Component } from 'nuxt/schema'
22
import { $fetch } from 'ofetch'
3-
import { unref } from 'vue'
43
import type { Ref } from 'vue'
54
import type { MaybeRef } from '@vueuse/core'
65
import { objectPick } from '@antfu/utils'
@@ -31,6 +30,10 @@ export function useInstalledModules() {
3130

3231
return computed(() => (config.value?._installedModules || [])
3332
.map((mod): InstalledModuleInfo => {
33+
// hide inline modules
34+
if (!mod.entryPath)
35+
return undefined!
36+
3437
const isPackageModule = mod.entryPath && isNodeModulePath(mod.entryPath)
3538
const name = mod.meta?.name
3639
? mod.meta?.name
@@ -53,7 +56,7 @@ export function useInstalledModules() {
5356
...mod,
5457
}
5558
})
56-
.filter(i => !i.name || !ignoredModules.includes(i.name)),
59+
.filter(i => i && (!i.name || !ignoredModules.includes(i.name))),
5760
)
5861
})
5962
}
@@ -114,9 +117,7 @@ export function useComponentsRelationships() {
114117
}
115118

116119
export function useServerHooks() {
117-
return useAsyncState('getServerHooks', () => rpc.getServerHooks(), {
118-
default: () => [],
119-
}) as Ref<HookInfo[]>
120+
return useAsyncState('getServerHooks', () => rpc.getServerHooks()) as Ref<HookInfo[] | undefined>
120121
}
121122

122123
export function useLayouts() {
@@ -175,7 +176,7 @@ export function useAllTabs() {
175176
icon: 'i-carbon-select-window',
176177
category: 'app',
177178
show() {
178-
return !!client.value?.inspector?.instance
179+
return () => !!client.value?.inspector?.instance
179180
},
180181
onClick() {
181182
if (!client.value?.inspector?.instance)
@@ -227,23 +228,16 @@ export function getCategorizedTabs(tabs: MaybeRef<(ModuleCustomTab | ModuleBuilt
227228
})
228229
}
229230

230-
export function useCategorizedTabs(enabledOnly = true) {
231-
const tabs = enabledOnly
232-
? useEnabledTabs()
233-
: useAllTabs()
234-
235-
return getCategorizedTabs(tabs)
236-
}
237-
238231
export function useEnabledTabs() {
239232
const tabs = useAllTabs()
240233
const settings = useDevToolsOptions()
241234
const categoryOrder = Object.keys(getCategorizedRecord())
235+
const tabShows = tabs.value.map(tab => (tab as ModuleBuiltinTab)?.show?.())
242236

243237
return computed(() => tabs.value
244-
.filter((tab) => {
238+
.filter((tab, idx) => {
245239
const _tab = tab as ModuleBuiltinTab
246-
if (_tab.show && !_tab.show())
240+
if (tabShows[idx] && !toValue(tabShows[idx]))
247241
return false
248242
if (settings.hiddenTabs.value.includes(_tab.name))
249243
return false

packages/devtools/client/pages/modules/hooks.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const clientHooks = computed(() => client.value?.getClientHooksMetrics())
2222
<HooksTable :hooks="clientHooks" />
2323
</NSectionBlock>
2424
<NSectionBlock
25+
v-if="serverHooks?.length"
2526
icon="carbon-ibm-cloud-direct-link-2-dedicated"
2627
text="Server Hooks"
27-
:description="`Total hooks: ${serverHooks.length}`"
28+
:description="`Total hooks: ${serverHooks?.length}`"
2829
padding="pl4 pr6"
2930
>
3031
<HooksTable :hooks="serverHooks" />

packages/devtools/client/pages/modules/server-routes.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ definePageMeta({
77
layout: 'full',
88
category: 'server',
99
show() {
10-
return useServerRoutes().value?.length
10+
const routes = useServerRoutes()
11+
return () => routes.value?.length
1112
},
1213
})
1314

packages/devtools/client/pages/modules/terminals.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ definePageMeta({
44
title: 'Terminals',
55
layout: 'full',
66
show() {
7-
return !!useTerminals().value?.length
7+
const terminals = useTerminals()
8+
return () => !!terminals.value?.length
89
},
910
badge() {
1011
return useTerminals().value?.filter(i => !i.isTerminated).length

packages/devtools/client/pages/settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const scaleOptions = [
2020
['Huge', 18 / 15],
2121
]
2222
23-
const categories = useCategorizedTabs(false)
23+
const categories = getCategorizedTabs(useAllTabs())
2424
2525
function toggleTab(name: string, v: boolean) {
2626
if (v)

0 commit comments

Comments
 (0)