From db5d9241aa8ebceb78b9c6e3b14ece4fc81228a2 Mon Sep 17 00:00:00 2001 From: arlo Date: Wed, 19 Jun 2024 13:03:55 +0800 Subject: [PATCH] fix(applet): prevent state update when data is empty --- packages/applet/src/modules/components/index.vue | 5 ++++- .../src/modules/custom-inspector/components/state/Index.vue | 5 ++++- packages/applet/src/modules/pinia/components/store/Index.vue | 5 ++++- .../applet/src/modules/router/components/routes/Index.vue | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/applet/src/modules/components/index.vue b/packages/applet/src/modules/components/index.vue index 42e6e814..06160f7c 100644 --- a/packages/applet/src/modules/components/index.vue +++ b/packages/applet/src/modules/components/index.vue @@ -150,7 +150,10 @@ function normalizeComponentState(data: { state?: any[] }) { function getComponentState(id: string) { rpc.value.getInspectorState({ inspectorId, nodeId: id }).then((data) => { - activeComponentState.value = normalizeComponentState(parse(data!)) + const parsedData = parse(data!) + if (!parsedData) + return + activeComponentState.value = normalizeComponentState(parsedData) expandedStateNodes.value = Array.from({ length: Object.keys(activeComponentState.value).length }, (_, i) => `${i}`) }) } diff --git a/packages/applet/src/modules/custom-inspector/components/state/Index.vue b/packages/applet/src/modules/custom-inspector/components/state/Index.vue index bb601fea..03f091e6 100644 --- a/packages/applet/src/modules/custom-inspector/components/state/Index.vue +++ b/packages/applet/src/modules/custom-inspector/components/state/Index.vue @@ -99,7 +99,10 @@ function filterEmptyState(data: Record) { function getInspectorState(nodeId: string) { rpc.value.getInspectorState({ inspectorId: inspectorId.value, nodeId }).then((data) => { - state.value = filterEmptyState(parse(data!)) + const parsedData = parse(data!) + if (!parsedData) + return + state.value = filterEmptyState(parsedData) expandedStateNodes.value = Array.from({ length: Object.keys(state.value).length }, (_, i) => `${i}`) }) } diff --git a/packages/applet/src/modules/pinia/components/store/Index.vue b/packages/applet/src/modules/pinia/components/store/Index.vue index f813f5a1..754cd623 100644 --- a/packages/applet/src/modules/pinia/components/store/Index.vue +++ b/packages/applet/src/modules/pinia/components/store/Index.vue @@ -70,8 +70,11 @@ function filterEmptyState(data: Record) { function getPiniaState(nodeId: string) { rpc.value.getInspectorState({ inspectorId, nodeId }).then((data) => { + const parsedData = parse(data!) + if (!parsedData) + return // @ts-expect-error skip type check - state.value = filterEmptyState(parse(data!)) + state.value = filterEmptyState(parsedData) expandedStateNodes.value = Array.from({ length: Object.keys(state.value).length }, (_, i) => `${i}`) }) } diff --git a/packages/applet/src/modules/router/components/routes/Index.vue b/packages/applet/src/modules/router/components/routes/Index.vue index ff65e191..1cad0f29 100644 --- a/packages/applet/src/modules/router/components/routes/Index.vue +++ b/packages/applet/src/modules/router/components/routes/Index.vue @@ -70,8 +70,11 @@ function filterEmptyState(data: Record) function getRoutesState(nodeId: string) { rpc.value.getInspectorState({ inspectorId: inspectorId.value, nodeId }).then((data) => { + const parsedData = parse(data!) + if (!parsedData) + return // @ts-expect-error skip type check - state.value = filterEmptyState(parse(data!)) + state.value = filterEmptyState(parsedData) expandedStateNodes.value = Array.from({ length: Object.keys(state.value).length }, (_, i) => `${i}`) }) }