Experience Editor & Sitecore JSS
As you probably know, Sitecore's experience editor does work on headless sites created with Sitecore SXA and JSS enabling editors to work in headless sites just as they would in the non-headless ones. We had such a headless site and bumped into a few issues in the experience editor though.
An important note here is that this headless site is not the only one on this Sitecore instance (10.2) - there are others, non-headless and non-sxa mvc sites.
Navigation bar
Our first issue was the navigation bar. The navigation bar allows you to navigate to a specific page through a menu structure, a bit like a breadcrumb. To enable the navigation bar, in the ribbon, on the View tab, select Navigation bar.
Our issue was that the urls in that navigation were wrong - they were using the wrong sc_site parameter in the querystring.
SiteResolving
First thing we had to check was the configuration of the sites. When adding sites with config patches they can be ordered. We had done this properly, but the headless site is a SXA site and that does not gets added through a config file. However, there also is a config section siteResolving in the ExperienceAccelerator section. This needs to include all your non-sxa sites so you need to patch them in.
<siteResolving patch:source="Sitecore.XA.SitesToResolveAfterSxa.config">
<site name="exm" resolve="after"/>
<site name="website" resolve="after"/>
<site name="unicorn" resolve="after"/>
<site name="x" resolve="after" patch:source="xxx.Sites.config"/>
<site name="y" resolve="after" patch:source="xxx.Sites.config"/>
<site name="z" resolve="after" patch:source="xxx.Sites.config"/>
</siteResolving>
This is a good and necessary step forward, but unfortunately it did not solve our problem yet.
TargetHostName
The final step to get it working was adding a target hostname to the site definition of our headless sxa-jss site. Not an ideal solution, but it does work.
Ok, issue number one solved - the navigation bar is working.
LinkFields
We also noticed we had a problem when using LinkFields.
When we have a RT field in the XP editor, the links inside are transformed into something like https://.../~/link.aspx?_id=5F7338F6FCFC404EB1EF67FAE1F71F7D&_z=z. In components using integrated GraphQL to fetch data however, we notice that the LinkFields are not transformed in the same way (on the same page). We fetch the jsonValue of the fields, use the Link component from the jss sdk in our Next.js code. This work perfectly in normal mode, but in the XP editor we get links like https://.../en/Test%3Fsc_site=X. If editors click on those links they get an error.
I asked this on Sitecore StackExchange but didn't get an answer there. So I opened a Sitecore support ticket and after a few rounds with questions and answers and logs, videos and data gathering we finally came to a solution.
But before we come to the solution, let's take a step back to see how we got there.
Step 1 - the ?
First thing we noticed was the %3F instead of a ? to start the querystring. Apparently there is a bug called "Internal link query string encoded in Next.js app" but we actually just fixed it in the Next app itself by replacing the character. Problem 1 solved.
Step 2 - sc_site
To get the correct site in the links I first wanted to check the data that came from the graphQL queries. To do this, I wanted to use the grapQL edge UI in edit mode and apparently that is possible. How to do that is documented on StackExchange - https://sitecore.stackexchange.com/a/39193/237 - so no need to repeat it all here. In short, if you want to fetch the data in edit mode:
- Fetch a token from the Identity Server using Postman (or similar tool) as explained here
- Add the authorization header in the http headers
- Add sc_mode=edit to your querystring
This way we learned that the url was definitely coming from Sitecore the wrong way. So back to Sitecore...
Maybe now is a good time to mention that although this headless site is rather new, the other mvc sites on the same platform are not. Instead, it's an old spaghetti platform that we inherited - I guess if you have been around in this business for a while you know what I mean.
And so, eventually we (to be honest, Sitecore support) found that someone patched a setting Languages.AlwaysStripLanguage to false.
The default value for this setting is true, and it specifies if the StripLanguage processor in the "preprocessRequest" pipeline will parse and remove languages from the url, even when the languageEmbedding attribute of the linkProvider is set to "never".
Changing this setting back to the original value (true) fixed our issue. And didn't cause any new ones...
Conclusion
Don't touch settings that you should not touch...
No comments:
Post a Comment