Skip to content
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

Translations not showing on Next Link click using 'en' locale (i18next loses instance) only on Vercel #49655

Open
1 task done
miguel-sg-dev opened this issue May 11, 2023 · 17 comments
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@miguel-sg-dev
Copy link

miguel-sg-dev commented May 11, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home
Binaries:
      Node: 18.8.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
Relevant packages:
      next: 13.4.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Internationalization (i18n), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/miguel-sg-dev/next-app

To Reproduce

Go to https://next-app-delta-azure.vercel.app/en and click on the FAQ link. The new page does not load the translations

Describe the Bug

When I'm on the en locale (https://next-app-delta-azure.vercel.app/en) and click on the FAQ link, it should load the faq page with the translated title but instead it shows the key "faq.title".

The only message I get in the console after I click on the link is this warning:
image

Couldn't try on canary version because it conflicts with the next-i18next dependency.

This issue just happens on Vercel. When I run the build and start the production server locally it works fine.

Expected Behavior

When clicking on the Link, the page should load with the translations, as it does when you click from https://next-app-delta-azure.vercel.app/ or https://next-app-delta-azure.vercel.app/es

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@miguel-sg-dev miguel-sg-dev added the bug Issue was opened via the bug report template. label May 11, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label May 11, 2023
@JesseKoldewijn
Copy link
Contributor

Hey man, I'm not sure where you got the "ns" key in the next config from (since I've never seen this specific setup before. But what I can see is that i18n is getting confused in your project probably because of the "default" locale. As far as I know all entries in locale are supposed to be existing locales. So in your case to achieve this setup you got you should go for the following.

Set either "en" or "es" as default language (enable language detection if you want). And remove "default" from locales and defaultLocale in your setup. This should work from what I remember from my last couple of projects using i18n.

If docs are needed you can check: https://nextjs.org/docs/pages/building-your-application/routing/internationalization

@miguel-sg-dev
Copy link
Author

Hey @JesseKoldewijn thank you for answering.

I'm using the default prefix locale, I can't do what you suggested because if I went to https://next-app-delta-azure.vercel.app/preguntas-frecuentes (without the "/es") it wouldn't modify the url and add the es locale as it does right now.

@JesseKoldewijn
Copy link
Contributor

Hey @JesseKoldewijn thank you for answering.

I'm using the default prefix locale, I can't do what you suggested because if I went to https://next-app-delta-azure.vercel.app/preguntas-frecuentes (without the "/es") it wouldn't modify the url and add the es locale as it does right now.

Ah gotcha, wouldn't the auto detection handle that rewrite?

@JesseKoldewijn
Copy link
Contributor

if not, the only other way I would see is creating a middleware that checks for static route paths and matches + rewites all the requests to the correct locale if the route is found.

@miguel-sg-dev
Copy link
Author

Hey @JesseKoldewijn thank you for answering.
I'm using the default prefix locale, I can't do what you suggested because if I went to https://next-app-delta-azure.vercel.app/preguntas-frecuentes (without the "/es") it wouldn't modify the url and add the es locale as it does right now.

Ah gotcha, wouldn't the auto detection handle that rewrite?

It doesn't :/

@miguel-sg-dev
Copy link
Author

miguel-sg-dev commented May 11, 2023

if not, the only other way I would see is creating a middleware that checks for static route paths and matches + rewites all the requests to the correct locale if the route is found.

Yeah but it's weird because it just happens on Vercel, when I do the build and start the server locally it works fine.

@JesseKoldewijn
Copy link
Contributor

if not, the only other way I would see is creating a middleware that checks for static route paths and matches + rewites all the requests to the correct locale if the route is found.

Yeah but it's weird because it just happens on Vercel, when I do the build and start the server it works fine.

funny enough when I visit "https://next-app-delta-azure.vercel.app/preguntas-frecuentes" I do get redirected to "https://next-app-delta-azure.vercel.app/es/preguntas-frecuentes"

@JesseKoldewijn
Copy link
Contributor

But that's probably because the default locale uses spanish for me while my system and browser locale is en-US

@JesseKoldewijn
Copy link
Contributor

and if I go to "https://next-app-delta-azure.vercel.app/en/faq" it does show the locale for me but not on initial route. it shows it after a refresh weirdly enough.

@JesseKoldewijn
Copy link
Contributor

I think if you replace your current middleware with the one shown in the docs it should work fine (and you can replace the fallback "en" to "es" if you want)

@JesseKoldewijn
Copy link
Contributor

Alright, from what I could muster it seems like it has something to do with the combination of your rewrites in the next config and your middleware next to it.

@JesseKoldewijn
Copy link
Contributor

it seems to lose the i18n client when going through a soft route. Maybe a good idea to specify this or something simular in the issue title? 👍

@miguel-sg-dev miguel-sg-dev changed the title Translations not showing on Next Link click using 'en' locale (i18next) only on Vercel Translations not showing on Next Link click using 'en' locale (i18next loses instance) only on Vercel May 12, 2023
@miguel-sg-dev
Copy link
Author

The issue still persists after removing redirects (thought maybe that could be conflicting) and updating the middleware as the documentation one.

@Linus-Boehm
Copy link

Linus-Boehm commented May 31, 2023

Any idea how to reproduce that locally?
We have the same issue and to investigate which part of our setup is causing there trouble, it would be helpful to be able to debug that locally. When I use yarn build and yarn start the issues seems not to be there. Can anybody help me understand why this is only broken, when the app gets deployed to vercel?

@JesseKoldewijn
Copy link
Contributor

As far as I've noticed when previously reproducing this it seemed like it happens both on local and deployed when having the combination of i18n and middleware. Haven't looked into this recently so not sure if this is still an issue on the latest canary release.

@Linus-Boehm
Copy link

TY @JesseKoldewijn I try to get a minimal reproduction up and running, to make sure this is actually the same issue

@aleehedl
Copy link

Any updates on this? The issue still persists with the latest version of Next.js and next-i18next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants