Skip to content

Commit 83fa90e

Browse files
committed
fix: improved component search, closes #1652
1 parent 930e42d commit 83fa90e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/app-backend-core/src/component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ export function getComponentInstance (appRecord: AppRecord, instanceId: string,
125125
}
126126
return instance
127127
}
128+
129+
export async function refreshComponentTreeSearch (ctx: BackendContext) {
130+
if (!ctx.currentAppRecord.componentFilter) return
131+
await sendComponentTreeData(ctx.currentAppRecord, '_root', ctx.currentAppRecord.componentFilter, null, ctx)
132+
}

packages/app-backend-core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getComponentId,
3232
editComponentState,
3333
getComponentInstance,
34+
refreshComponentTreeSearch,
3435
} from './component'
3536
import { addQueuedPlugins, addPlugin, sendPluginList, addPreviouslyRegisteredPlugins } from './plugin'
3637
import { PluginDescriptor, SetupFunction, TimelineLayerOptions, TimelineEventOptions, CustomInspectorOptions, Hooks } from '@vue/devtools-api'
@@ -167,6 +168,8 @@ async function connect () {
167168
if (ctx.currentInspectedComponentId === id) {
168169
sendSelectedComponentData(appRecord, id, ctx)
169170
}
171+
172+
await refreshComponentTreeSearch(ctx)
170173
} catch (e) {
171174
if (SharedData.debugInfo) {
172175
console.error(e)
@@ -200,6 +203,8 @@ async function connect () {
200203
sendEmptyComponentData(id, ctx)
201204
}
202205
appRecord.instanceMap.delete(id)
206+
207+
await refreshComponentTreeSearch(ctx)
203208
} catch (e) {
204209
if (SharedData.debugInfo) {
205210
console.error(e)

packages/app-backend-vue3/src/components/tree.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export class ComponentWalker {
5050
return [await this.capture(instance, null, depth)]
5151
} else if (instance.subTree) {
5252
// TODO functional components
53-
return this.findQualifiedChildrenFromList(this.getInternalInstanceChildren(instance.subTree), depth)
53+
const list = this.isKeepAlive(instance)
54+
? this.getKeepAliveCachedInstances(instance)
55+
: this.getInternalInstanceChildren(instance.subTree)
56+
return this.findQualifiedChildrenFromList(list, depth)
5457
} else {
5558
return []
5659
}
@@ -164,8 +167,8 @@ export class ComponentWalker {
164167
}
165168

166169
// keep-alive
167-
if (instance.type.__isKeepAlive && instance.__v_cache) {
168-
const cachedComponents = Array.from(instance.__v_cache.values()).map((vnode: any) => vnode.component).filter(Boolean)
170+
if (this.isKeepAlive(instance)) {
171+
const cachedComponents = this.getKeepAliveCachedInstances(instance)
169172
const childrenIds = children.map(child => child.__VUE_DEVTOOLS_UID__)
170173
for (const cachedChild of cachedComponents) {
171174
if (!childrenIds.includes(cachedChild.__VUE_DEVTOOLS_UID__)) {
@@ -218,4 +221,12 @@ export class ComponentWalker {
218221
instanceMap.set(instance.__VUE_DEVTOOLS_UID__, instance)
219222
}
220223
}
224+
225+
private isKeepAlive (instance) {
226+
return instance.type.__isKeepAlive && instance.__v_cache
227+
}
228+
229+
private getKeepAliveCachedInstances (instance) {
230+
return Array.from(instance.__v_cache.values()).map((vnode: any) => vnode.component).filter(Boolean)
231+
}
221232
}

0 commit comments

Comments
 (0)