fix: guard null access in composables (#951)

This commit is contained in:
Dominik Pschenitschni
2025-06-16 16:02:59 +02:00
committed by GitHub
parent 640645642b
commit 78fa5742c3
3 changed files with 14 additions and 7 deletions

View File

@@ -3,13 +3,16 @@ import ProjectService from '@/services/project'
import type {IProject} from '@/modelTypes/IProject'
import {getBlobFromBlurHash} from '@/helpers/getBlobFromBlurHash'
export function useProjectBackground(project: MaybeRefOrGetter<IProject>) {
export function useProjectBackground(project: MaybeRefOrGetter<IProject | null>) {
const background = ref<string | null>(null)
const backgroundLoading = ref(false)
const blurHashUrl = ref('')
watch(
() => [toValue(project).id, toValue(project)?.backgroundBlurHash] as [IProject['id'], IProject['backgroundBlurHash']],
() => [
toValue(project)?.id ?? null,
toValue(project)?.backgroundBlurHash ?? null,
] as [IProject['id'] | null, IProject['backgroundBlurHash'] | null],
async ([projectId, blurHash], oldValue) => {
const projectValue = toValue(project)
if (

View File

@@ -25,7 +25,7 @@ export function useRenewTokenOnFocus() {
}
const nowInSeconds = new Date().getTime() / MILLISECONDS_A_SECOND
const expiresIn = userInfo.value !== null
const expiresIn = userInfo.value
? userInfo.value.exp - nowInSeconds
: 0

View File

@@ -6,7 +6,7 @@ import {useProjectStore} from '@/stores/projects'
export function useRouteWithModal() {
const router = useRouter()
const route = useRoute()
const backdropView = computed(() => route.fullPath && window.history.state.backdropView)
const backdropView = computed(() => route.fullPath ? window.history.state.backdropView : undefined)
const baseStore = useBaseStore()
const projectStore = useProjectStore()
@@ -55,7 +55,7 @@ export function useRouteWithModal() {
currentModal.value = h(component, routeProps)
})
const historyState = computed(() => route.fullPath && window.history.state)
const historyState = computed(() => route.fullPath ? window.history.state : undefined)
function closeModal() {
@@ -63,7 +63,9 @@ export function useRouteWithModal() {
// we need to reflect that change in the route when they close the task modal.
// The last route is only available as resolved string, therefore we need to use a regex for matching here
const routeMatch = new RegExp('\\/projects\\/\\d+\\/(\\d+)', 'g')
const match = routeMatch.exec(historyState.value.back)
const match = historyState.value?.back
? routeMatch.exec(historyState.value.back)
: null
if (match !== null && baseStore.currentProject) {
let viewId: string | number = match[1]
@@ -86,7 +88,9 @@ export function useRouteWithModal() {
router.back()
} else {
const backdropRoute = historyState.value?.backdropView && router.resolve(historyState.value.backdropView)
router.push(backdropRoute)
if (backdropRoute) {
router.push(backdropRoute)
}
}
}