Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(i18n): avoid useI18n() outside setup in async composables

Alexander Sysoev9ac088352463
diff --git a/app/composables/useImageLoader.ts b/app/composables/useImageLoader.ts
index c1ec1da9..33793b3b 100644
--- a/app/composables/useImageLoader.ts
+++ b/app/composables/useImageLoader.ts
@@ -15,7 +15,12 @@ export const useImageLoader = (
updateHighResImageRendered?: (isRendered: boolean) => void,
onImageLoaded?: () => void,
) => {
- const { t } = useI18n()
+ // useImageLoader() is invoked from loadImage(), which also runs inside watch
+ // callbacks (outside the synchronous setup context) — useI18n() would throw
+ // "Must be called at the top of a `setup` function". Use the Nuxt-global
+ // i18n instead, which is safe to access outside setup.
+ const { $i18n } = useNuxtApp()
+ const t = $i18n.t
if (highResLoaded || !isCurrentImage || error) return null
const loaderManager = new ImageLoaderManager()
diff --git a/app/composables/useUpload.ts b/app/composables/useUpload.ts
index 5b38be78..580e50c7 100644
--- a/app/composables/useUpload.ts
+++ b/app/composables/useUpload.ts
@@ -33,7 +33,12 @@ export interface UseUploadOptions {
}
export function useUpload(options: UseUploadOptions = {}) {
- const { t } = useI18n()
+ // useUpload() is invoked from within an async upload handler (outside the
+ // synchronous setup context), so useI18n() would throw "Must be called at
+ // the top of a `setup` function". Use the Nuxt-global i18n instead, which is
+ // safe to access outside setup (see useExifLocalization).
+ const { $i18n } = useNuxtApp()
+ const t = $i18n.t
const {
timeout = 0,
withCredentials = false,