JSON translations don't work in SSR Spartacus 4.x
See original GitHub issueHello,
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:
- Created 2 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
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 function18nextInit()
customers need to dismantle deeply the modules tree up to theI18nModule
and then provide a custom factory functioni18nextInit()
Detailed results of investigation: In 4.0, when switching from the deprecated 3rd party dependency
i18next-xhr-backend
to its new counterparti18next-http-backend
we didn’t notice that there are slight differences between those packages:develop
branch by this PR https://github.com/SAP/spartacus/pull/14453/files#diff-b9c2f7d32db998292ce5b32da446437ad64755d84817c3261fdbc89f6438856aL99-R113setInterval()
which makes the SSR render to hang. This issue will be addressed by the PR todevelop
https://github.com/SAP/spartacus/pull/15297Since
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 torelease/4.3.x
and then release a new4.3.x
patch.This is a priority task now.
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!