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

Server Translation not working if client use Grafana Faro #1711

Closed
3 tasks done
bozzelliandrea opened this issue Feb 12, 2025 · 5 comments · Fixed by #1719
Closed
3 tasks done

Server Translation not working if client use Grafana Faro #1711

bozzelliandrea opened this issue Feb 12, 2025 · 5 comments · Fixed by #1719
Labels
bug Something isn't working needs-isolation unconfirmed Needs triage.

Comments

@bozzelliandrea
Copy link

Description

When using Grafana Faro, which is a client side observability tool for react application, next-intl stop working only for server side components
and print on server side console the following error
Error: MISSING_MESSAGE: No messages were configured on the provider.

if you remove the faro component from the reproduction URL example, it works.

Verifications

Mandatory reproduction URL

https://github.com/bozzelliandrea/next-faro-intl

Reproduction description

  • add faro configuration (if using example, you can skip the configuration and ignore connectin error client and server side)
  • create a next client side component with faro initialization (already in the example)
  • add faro component to layout.tsx (already in the example)
  • run install and run next application
  • switch locale from the default to another one (ex. switch from /en to /it)
  • check server side console log (translation not working but middleware find locale and json mapping)
  • removing FaroComponent and then the i18n works as expected with multiple locales

Expected behaviour

Localization working with Grafana Faro when switching locale.

@bozzelliandrea bozzelliandrea added bug Something isn't working unconfirmed Needs triage. labels Feb 12, 2025
@amannn
Copy link
Owner

amannn commented Feb 13, 2025

I had a brief look at your example and can confirm there's a really weird bug here. As this happens as soon as you add Faro, maybe you want to investigate with them? I'm not sure if they do anything funky like modifying Next.js internals or so, the behavior looks unlike anything I've seen before honestly.

Copy link

Thank you for your report!

From the currently available context in this issue, it's unclear wether the erroneous behavior is caused by Next.js, next-intl or a 3rd party library that you're using. Please isolate the issue further to be sure that the issue is caused by next-intl. When in doubt, please search on the Next.js issue tracker or related resources of 3rd party libraries you might be using.

If you're able to isolate the issue to next-intl, please provide a minimal reproduction that ideally doesn't involve any 3rd party libraries or alternatively demonstrates that next-intl is causing the issue.

Thank you for your understanding!

@SalmenBejaoui
Copy link
Contributor

After debugging the provided repo, it seems the issue is caused by OpenTelemetry that Faro uses internally. OpenTelemetry overrides the Promise object internally using Zone.js https://github.com/angular/zone.js/blob/master/lib/common/promise.ts#L490

After the first render and Faro initialisation, the promise retrieved by getConfig seems not to be a native promise, skipping resolving the promise and retrieving the messages object because result instanceof Promise = false

https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/server/react-server/getConfig.tsx#L75.

Image

@amannn
Copy link
Owner

amannn commented Feb 17, 2025

Oh wow, thanks for digging into this @SalmenBejaoui!

I found this in the Zone.js docs:

While still a supported part of Angular, the Angular team strongly discourages using Zone.js outside of Angular application contexts.

However, since it's used as part of OpenTelemetry, the Next.js docs recommend this package and it is very popular, maybe out of pragmatism next-intl could provide a workaround for Zone.js for the time being.

Let me have a look …

@amannn
Copy link
Owner

amannn commented Feb 17, 2025

I've added #1719 to address this (pre-release available as next-intl@0.0.0-canary-84fe6d0).

It seems like it fixes the error in your reproduction. Can you confirm that this version works for you?

amannn added a commit that referenced this issue Feb 18, 2025
Fixes #1711

Available as `next-intl@0.0.0-canary-84fe6d0`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-isolation unconfirmed Needs triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants