"Illegal recursion detected" error when loading SXA website on a mobile device


Description

SXA website pages might fail to load with a high CPU usage and an unhandled exception if the page is requested with a mobile device or in the mobile mode of a desktop browser. The root cause of the issue is an infinite recursion on page load when using a component variant field for a mobile device. The following message can be found in the log:

Exception: System.InvalidOperationException
Message: Illegal recursion detected: GetModel
Source: Sitecore.Mvc
at Sitecore.Mvc.Common.RecursionPreventer..ctor(String title, Flag flag)
at Sitecore.Mvc.Presentation.Rendering.GetModel()
at Sitecore.Mvc.Presentation.Rendering.get_Model()
at Sitecore.XA.Foundation.Mvc.Wrappers.Rendering.get_Item()
...

This issue affects SXA 1.6.0- 1.8.1 versions.

Solution

To resolve the issue, consider one of the following options: