-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useTranslation
errors when used inside a Nitro request hook
#31
Comments
useTranslation
errors when used inside a [Nitro](https://nitro.unjs.io) request hookuseTranslation
errors when used inside a Nitro request hook
Push I have a similar issue in a Vercel environment. I'm using the i18n Nuxt module. (https://github.com/nuxt-modules/i18n) I have a webhook which makes an API call and sometimes the API is being called when the "server is cold" and then it fails. When it gets triggered again shortly afterwards, it works. Unfortunately I'm also not sure how I can provide a reproduction but I'm just leaving my Vercel logs here so maybe they help someone. There seems to be an issue in the Using Webhook --> calls API --> calls function (
My code async function handleLeadCreation(payload: WebhookPayload<'leadgen'>, event: H3Event<EventHandlerRequest>) {
try {
const supabase = serverSupabaseServiceRole<Database>(event)
const { sendMail } = useNodeMailer()
const t = await useTranslation(event)
// fails here
const subject = t('email.new_lead.subject', { campaign_name: supabaseLead?.fb_campaign_name })
function resolveLocale(locale) {
if (isString(locale)) {
return locale;
}
else {
if (isFunction(locale)) {
if (locale.resolvedOnce && _resolveLocale != null) {
return _resolveLocale;
}
else if (locale.constructor.name === 'Function') {
const resolve = locale();
if (isPromise(resolve)) {
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
}
return (_resolveLocale = resolve);
}
else {
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
}
}
else {
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
}
}
} |
We see the same error in a Nuxt application on Vercel, but only occassionaly. This is were it throws: Line 354 in 3246216
We are using an advanced localeDetector. The application is only using 1 locale for now. So I will simplify our localeDetector and monitor if the error this pops up. |
Some information from the logs. First line, "config created", show that a static singleton variable on the nitro side has been created. So I believe the process just booted up. The defineI18nMiddleware ran, because I patched it to log at the end. But useTranslation can't see the object on the context for some reason. Could we force the creation of the i18n object on the context? |
Describe the bug
When used inside a Nitro request hook, useTranslation (for server-side translation) errors:
Reproduction
nitroApp.hooks.hook("request", async (event) => { const t = await useTranslation(event) })
System Info
Used Package Manager
n/a
Additional context
The reproduction provided is extremely minimal as that's all that needs to be done in order to trigger the error. If necessary, I can provide a less minimal reproduction, please do let me know!
Validations
The text was updated successfully, but these errors were encountered: