Skip to content

Commit f6c5562

Browse files
committed
fix(directive): guard canCalendar visibility updates against runtime errors
1 parent fb96f08 commit f6c5562

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/directives/canCalendar.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ export default {
77
const userStore = useUserStore()
88

99
const updateVisibility = () => {
10-
const role = userStore.primaryRole
11-
const user = { role }
12-
const allowed = canAccessCalendar(user as any)
13-
el.style.display = allowed ? '' : 'none'
10+
try {
11+
const role = userStore.primaryRole
12+
const user = { role }
13+
const allowed = canAccessCalendar(user as any)
14+
el.style.display = allowed ? '' : 'none'
15+
} catch (err) {
16+
// hide on any error during evaluation
17+
el.style.display = 'none'
18+
}
1419
}
1520

1621
updateVisibility()
1722
// ensure reactivity has settled in test environments
1823
setTimeout(() => updateVisibility(), 0)
1924

2025
const stop = userStore.$subscribe(() => {
21-
updateVisibility()
26+
try {
27+
updateVisibility()
28+
} catch (e) {
29+
// swallow to avoid breaking host app/tests; ensure element hidden
30+
el.style.display = 'none'
31+
}
2232
})
2333

2434
;(el as any).__vCanCalendarStop = stop

0 commit comments

Comments
 (0)