Make the SXA image component load image in XPE - just a couple of hacks

Further Update:

I raised a Sitecore Support case and based on the response, I later created the following blog post so, you can skip to this post instead:

https://navansitecorenotes.blogspot.com/2023/08/why-is-image-not-displayed-in.html

If you want some context, you can continue reading this post!

_______________________________________________________________________

Actual Issue:

Recently while working on Sitecore 10.3 noticed that when I add the in-built SXA image component to Experience Editor, the image wasn't loading. I did all possible things like running around the computer 2.5 times, jumping-jacks for 19.75 times etc. but nothing worked. Only later I realised that SXA Image component has rendering problems right from good old days. 

References:

https://sitecore.stackexchange.com/questions/34871/images-not-loading-in-sxa-site

https://sitecore.stackexchange.com/questions/16012/sxa-image-not-show

Now, with that background, I noticed that i hadn't even set any theme for my site. So, I'm writing here the hack I followed to see the image component appear in my XPE as well as the web page. Now, we can't tell the end-users to do such hacks so take this note with a pinch of salt until you find something permanent to resolve the issue.


First, the problem:

1. Install a Sitecore SXA 10.3 instance

2. Do usual shenanigans of:

    - Create a tenant

    - Create a Site within it

3. Open the XPE for the site' page:


4. Select image control from toolbox and add to the main placeholder

5. Next, 

 - Choose an Image



- Upload Media -> Browse for Media Files -> Select file from file system -> provide alt text -> Change Destination to Site location in media library and confirm as follows:




Then, click Upload Media button. Now, the image will be grey as follows:


Close the Select Media window and click the toolbar Choose image button, now the image should be available so, select the same:


Now, we have reached the first problem of image not getting displayed in XPE as follows:



To hack our way out of this, inspect the image and open the image in a new window as follows:


Image in new tab:


Now, while the image is available in one tab, reload the XPE altogether in the other tab:


In the blank XPE, restart by adding the image control from the toolbox and when you choose the image this time, you should see it in XPE:


Now, save and publish the page. In the web page too do the same thing of opening the image in a new window and refresh the page and the image will be visible:


This worst of all hacks works in 10.2 too. Looks like the image is dependent on some kind of cache because if I hard reload the page, I had to re-do the same process of opening the image url in new tab and then reloading the page loaded the image. 

Hack no. 2: This also works but not the Sitecore approach:

Source field by default in Image field template points to query:$siteMedia


Change the Source to a path in themes image folder (as below) and then you should be able to add an image in XPE and the image will be reflected right-away:


Then, raised a Support Case with Sitecore - CS0396223

Comments

Popular Posts