1
0

fix: error "27" (#5122)

* fix: error 27

* fix: sentry only in prod

* fix: sentry env

* Revert "fix: error 27"

This reverts commit 66ee482a0567a5e53326e576b1bc6af0542a7fe3.

* feat: attempt to fix error 27
This commit is contained in:
Calum H.
2026-01-15 00:38:23 +00:00
committed by GitHub
parent 3ffa78aa07
commit 454c708fd6
6 changed files with 39 additions and 11 deletions

View File

@@ -1,8 +1,28 @@
import IntlMessageFormat from 'intl-messageformat'
import type { Ref } from 'vue'
import type { CompileError, MessageCompiler, MessageContext } from 'vue-i18n'
import type { CompileError, Composer, MessageCompiler, MessageContext } from 'vue-i18n'
import { useI18n } from 'vue-i18n'
/**
* Get i18n instance, preferring Nuxt's $i18n to avoid vue-i18n's
* getCurrentInstance() issues on edge runtimes with concurrent SSR requests.
*/
export function getSafeI18n(): Pick<Composer, 't' | 'locale'> {
// Try Nuxt's $i18n first (avoids Error 27 on Cloudflare Workers)
if (typeof useNuxtApp !== 'undefined') {
try {
const { $i18n } = useNuxtApp()
if ($i18n) {
return { t: $i18n.t, locale: $i18n.locale }
}
} catch {
// Not in Nuxt context, fall through
}
}
// Fallback to vue-i18n's useI18n
return useI18n()
}
export interface MessageDescriptor {
id: string
defaultMessage?: string
@@ -174,7 +194,7 @@ export interface VIntlFormatters {
* Uses vue-i18n's useI18n() under the hood.
*/
export function useVIntl(): VIntlFormatters & { locale: Ref<string> } {
const { t, locale } = useI18n()
const { t, locale } = getSafeI18n()
function formatMessage(descriptor: MessageDescriptor, values?: Record<string, unknown>): string {
const key = descriptor.id