question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON translations don't work in SSR Spartacus 4.x

See original GitHub issue

Hello,

I am opening a bug after creating a topic here.

I have implemented the Lazy Loading of the translations as in this guide. If I run the application in SSR mode it always falls back in CSR, even if I increase the timeout to over 1 minute. If I remove the backend configuration and restore the static files, the SSR works fine. This issue occurs on both version 4.1 and 4.2 of Spartacus.

Steps to reproduce:

ng new electronics-spa --style=scss --package-manager yarn
cd electronics-spa/
ng add @spartacus/schematics@latest --baseUrl https://spartacus-demo.eastus.cloudapp.azure.com:8443 --baseSite=electronics-spa --currency=USD --language=en --ssr --skip-confirmation
cp ./node_modules/@spartacus/assets/i18n-assets ./src/assets -r

(I am using of course mine SAP Cloud baseUrl)

Change the file src/app/spartacus/spartacus-configuration.module.ts in this way (as per the documentation):

providers: [
  provideConfig({
    i18n: {
      backend: {
        loadPath: 'assets/i18n-assets/{{lng}}/{{ns}}.json',
      },
      chunks: translationChunksConfig,
    },
  }),
];

Then finally run

yarn build:ssr
yarn serve:ssr

And when you open the application in the browser it will fall back in the CSR mode without any error on server side. If you revert the spartacus-configuration.module.ts and re-build and re-run the application, SSR works fine.

I have created a simple repo that reproduces the error: https://github.com/fgrecchi-aswatson/spartacus-ssr-issue

Thanks Filippo Grecchi

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Platonncommented, Mar 4, 2022

Hi @fgrecchi-aswatson. I confirm, the fix is to set reloadInterval: false in the backend options of i18next Unfortunately until https://github.com/SAP/spartacus/issues/11675 is implemented, it’s cumbersome for customers to apply quick fix themselves. Currently, to change any logic in the function 18nextInit() customers need to dismantle deeply the modules tree up to the I18nModule and then provide a custom factory function i18nextInit()

Detailed results of investigation: In 4.0, when switching from the deprecated 3rd party dependency i18next-xhr-backend to its new counterpart i18next-http-backend we didn’t notice that there are slight differences between those packages:

Since develop branch now is aimed to be released only as 5.0, we should backport both PRs https://github.com/SAP/spartacus/pull/14453/ and https://github.com/SAP/spartacus/pull/15297 to release/4.3.x and then release a new 4.3.x patch.

This is a priority task now.

1reaction
Platonncommented, Nov 19, 2021

No simple answer for this ticket from top of my head. I’ll need to dive and debug. Many thanks @fgrecchi-aswatson for providing a REPO for reproducing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spartacus not loading translations from local JSON files when ...
Deactivate Javascript in the browser to see what is rendered on the server; The translations are not loaded by the Node application: List...
Read more >
Spartacus Not Loading Translations From Local Json Files ...
Spartacus Not Loading Translations From Local Json Files When Using Ssr. If you are not using the latest version of SAP Commerce Cloud...
Read more >
Internationalization (i18n) - Spartacus Documentation - SAP
When new features are released in Spartacus, new JSON files are published with predefined translations, and any differences need to be taken into...
Read more >
SAP Spartacus: a small, but practical overview. - Medium
SAP Spartacus is an open-source framework provided by SAP for ... The custom language translations are normally stored in JSON files.
Read more >
Getting Started with SAP Commerce Cloud Project Spartacus
CX Works is designed for SAP Customer Experience solutions. It is a source of curated, field-tested and SAP-verified expertise, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found