Enabling HTML caching on SXA sites (JSON layout) or on JSS sites can cause errors


Description

The article describes two scenarios when errors appear if using the JSON device while HTML caching is enabled on the SXA website or on the JSS site based on the SXA.

Scenario 1

If the SXA website page has a component with caching enabled. After reloading the website page on the front end using the JSON device the following error might occur:

Server Error in '/' Application.
Rendering data contained rendering reference ID e1354fcc-4fe0-4b4c-aa11-78b793895dfa but that rendering ID was not present in the rendered renderings context. This ought not to occur.
Description: An unhandled exception occurred.
Exception Details: System.InvalidOperationException: Rendering data contained rendering reference ID e1354fcc-4fe0-4b4c-aa11-78b793895dfa but that rendering ID was not present in the rendered renderings context. This ought not to occur.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Rendering data contained rendering reference ID e1354fcc-4fe0-4b4c-aa11-78b793895dfa but that rendering ID was not present in the rendered renderings context. This ought not to occur.]
Sitecore.LayoutService.ItemRendering.PlaceholderRenderingService.ConvertRenderedPlaceholderMarkup(RenderedPlaceholder placeholder, String contents, RenderedJsonRenderingContext renderedRenderingContext) +978
Sitecore.LayoutService.ItemRendering.PlaceholderRenderingService.RenderPlaceholder(PlaceholderDefinition placeholderDefinition, IRenderingConfiguration renderingConfiguration) +499
System.Linq.WhereSelectListIterator`2.MoveNext() +114 System.Linq.WhereEnumerableIterator`1.MoveNext() +236
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +436
System.Linq.Enumerable.ToList(IEnumerable`1 source) +70
Sitecore.LayoutService.ItemRendering.LayoutService.Render(Item item, IRenderingConfiguration renderingConfiguration, RenderOptions renderOptions) +838
Sitecore.XA.Feature.LayoutServices.Integration.Repositories.PageLayoutJsonRepository.GetJson(Item item) +280
Sitecore.XA.Feature.LayoutServices.Integration.Repositories.PageLayoutJsonRepository.GetModel() +93
Sitecore.XA.Foundation.Mvc.Controllers.StandardController.Index() +144 lambda_method(Closure , ControllerBase , Object[] ) +90
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +80
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +454
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +454
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +524

Scenario 2

If the JSS site created with SXA PowerShell scripts has a component with caching enabled. After reloading the website on the front end using the JSON device the following error might occur:

Rendering data contained rendering reference ID 12b32f25-1d0d-4201-be46-675dcee4fefb but that rendering ID was not present in the rendered renderings context. This ought not to occur.
[InvalidOperationException: Rendering data contained rendering reference ID 12b32f25-1d0d-4201-be46-675dcee4fefb but that rendering ID was not present in the rendered renderings context. This ought not to occur.]
Sitecore.LayoutService.ItemRendering.PlaceholderRenderingService.ConvertRenderedPlaceholderMarkup(RenderedPlaceholder placeholder, String contents, RenderedJsonRenderingContext renderedRenderingContext) +1016
Sitecore.LayoutService.ItemRendering.PlaceholderRenderingService.RenderPlaceholder(PlaceholderDefinition placeholderDefinition, IRenderingConfiguration renderingConfiguration) +499
System.Linq.WhereSelectListIterator`2.MoveNext() +117
System.Linq.WhereEnumerableIterator`1.MoveNext() +127
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +453
System.Linq.Enumerable.ToList(IEnumerable`1 source) +69
Sitecore.LayoutService.ItemRendering.LayoutService.Render(Item item, IRenderingConfiguration renderingConfiguration, RenderOptions renderOptions) +1089
Sitecore.JavaScriptServices.ViewEngine.Presentation.JsLayoutRenderer.ResolveFunctionArgs() +73
Sitecore.JavaScriptServices.ViewEngine.Presentation.JssRenderer.Render(TextWriter writer) +201
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +147
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +74
(Object , Object ) +14
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +490
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +236
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +195
Sitecore.Mvc.Presentation.RenderingView.Render(ViewContext viewContext, TextWriter writer) +297
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +91
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
System.Web.Mvc.Async.<>c__DisplayClass3_1.b__1(IAsyncResult asyncResult) +39

Solution

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