Skip to content

Commit

Permalink
Fix possible TypeError when accessing route.value properties (#4523)
Browse files Browse the repository at this point in the history
  • Loading branch information
krysal authored Jun 26, 2024
1 parent 1c05ef0 commit da4c036
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export default defineComponent({
})
const route = useRoute()
const routeSearchTerm = computed(() => route.value.query.q)
const routeSearchTerm = computed(() => route.value?.query?.q)
watch(routeSearchTerm, (newSearchTerm) => {
const term = Array.isArray(newSearchTerm)
? newSearchTerm[0]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/VMediaInfo/VMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default defineComponent({
return
}
sendCustomEvent("VISIT_SOURCE_LINK", {
id: route.value.params.id,
id: route.value?.params?.id,
source,
})
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/VMediaInfo/VRelatedMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export default defineComponent({
)
const searchTerm = computed(() => {
const q = Array.isArray(route.value.query.q)
? route.value.query.q[0]
: route.value.query.q
const q = Array.isArray(route.value?.query?.q)
? route.value?.query?.q[0]
: route.value?.query?.q
return q ?? ""
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/composables/use-match-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useMatchRoute = (
return routes.includes(route.split("__")[0])
}

const matches = ref(routeNameMatches(route.value.name))
const matches = ref(routeNameMatches(route.value?.name))

router.beforeEach((to, _from, next) => {
matches.value = routeNameMatches(to.name)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/audio/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default defineComponent({
const audio = ref<AudioDetail | null>(
singleResultStore.audio?.id &&
singleResultStore.audio.id === route.value.params.id
singleResultStore.audio.id === route.value?.params?.id
? singleResultStore.audio
: null
)
Expand All @@ -105,7 +105,7 @@ export default defineComponent({
const { error: nuxtError } = useContext()
useFetch(async () => {
const audioId = route.value.params.id
const audioId = route.value?.params?.id
await singleResultStore.fetch(AUDIO, audioId)
const fetchedAudio = singleResultStore.audio
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/image/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default defineComponent({
const image = ref<ImageDetail | null>(
singleResultStore.image?.id &&
singleResultStore.image.id === route.value.params.id
singleResultStore.image.id === route.value?.params?.id
? singleResultStore.image
: null
)
Expand All @@ -158,7 +158,7 @@ export default defineComponent({
const { error: nuxtError } = useContext()
useFetch(async () => {
const imageId = route.value.params.id
const imageId = route.value?.params?.id
const fetchedImage = await singleResultStore.fetch(IMAGE, imageId)
if (!fetchedImage) {
if (fetchingError.value && !isRetriable(fetchingError.value)) {
Expand Down

0 comments on commit da4c036

Please sign in to comment.