1
votes

we have our Spartacus project set up to fetch the context from the basesites request. A sample response can be seen here:

{
   "baseSites" : [ {
      "defaultLanguage" : {
         "isocode" : "sl"
      },
      "geoRecommended" : false,
      "showTeaser" : true,
      "stores" : [ {
         "currencies" : [ {
            "isocode" : "EUR"
         } ],
         "defaultCurrency" : {
            "isocode" : "EUR"
         },
         "defaultLanguage" : {
            "isocode" : "sl"
         },
         "languages" : [ {
            "isocode" : "sl"
         } ],
      } ],
      "uid" : "ung-site-si",
      "urlEncodingAttributes" : [ "languageCountry" ],
      "urlPatterns" : [ "(?i)^https?://localhost(:[\\d]+)?/rest/.*$", "(?i)^https?://[^/]+/(sl-SI)/?.*$" ]
   }, ...
]

We have two basesites set up at the moment. The urlPatterns are used to find the correct baseSite. Then the context(baseSite, language, currency) is set in our custom occ-loaded-config-converter. So we are not using any static context or fetching it from the URL, but getting the context from the response of the basesites request.

The site-context-interceptor then subscribes to e.g. this.languageService.getActive() and then sets the correct context (language, currency) for the backend requests:

/rest/v2/ung-site-rs/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=/shoppster-akcija&lang=sr&curr=RSD

Before the Spartacus Upgrade to 2.0 this worked fine. Right after the context was set from the basesites request, the subscription in the site-context-interceptor was triggered an the right context sent with the subsequent backend requests. Now after upgrading to 2.1, the context is not set on time anymore. So the first few backend requests are sent with the wrong context (default USD, en) and then at some point in time, the subscriptions are triggered an the correct context is set.

This may be related to this change: https://sap.github.io/spartacus-docs/technical-changes-version-2/#context-change-action-not-dispatched-on-the-initial-setting-of-the-value

Is it now not possible anymore to use the basesites request to set the context?

1
Could you specify exact patch version you're using, please? 2.1.4? - Krzysztof Platis
We are currently using 2.1.1 - Armin
Did you upgrade from pure 2.0.0 or from some patch 2.0.??. I'm asking just to narrow the period when the issue could have been introduced - then to search in the Spartacus repo. - Krzysztof Platis
You said "This may be related to this change: sap.github.io/spartacus-docs/technical-changes-version-2/…". I pretty much believe it's not the cause of the problem. This doc describes changes between 1.x and 2.0. But your starting point when upgrading was already 2.0, so the doc seems not relevant. - Krzysztof Platis
We upgraded from the 2.0.0-next.2 version. There the problem didn't occur yet - Armin

1 Answers

0
votes

As discussed in comments: bumping to the latest patch version 2.1.4 has fixed the issue.