Skip to content

Commit f8f457a

Browse files
committed
fix(vue2): add more null guards
1 parent 29ea4d0 commit f8f457a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/app-backend-vue2/src/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
4545

4646
api.on.getInspectorTree(payload => {
4747
if (payload.inspectorId === ROUTER_INSPECTOR_ID) {
48-
payload.rootNodes = router.options.routes.map(route => formatRouteNode(router, route, '', payload.filter)).filter(Boolean)
48+
if (router.options.routes) {
49+
payload.rootNodes = router.options.routes.map(route => formatRouteNode(router, route, '', payload.filter)).filter(Boolean)
50+
} else {
51+
console.warn(`[Vue Devtools] No routes found in router`, router.options)
52+
}
4953
}
5054
})
5155

@@ -392,7 +396,7 @@ function formatStoreForInspectorTree (module, moduleName: string, path: string):
392396
// nested/cart/ -> cart
393397
label: moduleName,
394398
tags: module.namespaced ? [TAG_NAMESPACED] : [],
395-
children: Object.keys(module._children).map((key) =>
399+
children: Object.keys(module._children ?? {}).map((key) =>
396400
formatStoreForInspectorTree(
397401
module._children[key],
398402
key,
@@ -421,7 +425,7 @@ function extractNameFromPath (path: string) {
421425

422426
function formatStoreForInspectorState (module, getters, path): CustomInspectorState {
423427
const storeState: CustomInspectorState = {
424-
state: Object.keys(module.context.state).map((key) => ({
428+
state: Object.keys(module.context.state ?? {}).map((key) => ({
425429
key,
426430
editable: true,
427431
value: module.context.state[key],

0 commit comments

Comments
 (0)