Skip to content

Commit

Permalink
fix(applet): prevent state update when data is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Jun 19, 2024
1 parent f7a52a6 commit db5d924
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/applet/src/modules/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ function filterEmptyState(data: Record<string, CustomInspectorState[]>) {
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}`)
})
}
Expand Down
5 changes: 4 additions & 1 deletion packages/applet/src/modules/pinia/components/store/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ function filterEmptyState(data: Record<string, unknown[] | undefined>) {
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}`)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ function filterEmptyState(data: Record<string, unknown[] | string | undefined>)
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}`)
})
}
Expand Down

0 comments on commit db5d924

Please sign in to comment.